<repo_name>kaustubhtoraskar/CodeIT<file_sep>/app/src/main/java/svkt/wallet/activities/WalletStatement.java
package svkt.wallet.activities;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import svkt.wallet.R;
import svkt.wallet.models.Transaction;
import svkt.wallet.models.User;

public class WalletStatement extends AppCompatActivity {

    TextView totalAmount,name,cardno;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wallet_statement);
        totalAmount = findViewById(R.id.totalAmount);
        name = findViewById(R.id.name);
        cardno = findViewById(R.id.cardno);
        passParams();
    }

    public void passParams(){
        FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
        DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference().child("users").child(currentUser.getUid());
        dbRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                User current = dataSnapshot.getValue(User.class);
                totalAmount.setText(getString(R.string.Rs)+ current.balance);
                name.setText(current.name);
                cardno.setText(current.cardNo);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_passbook, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        switch (id)
        {
            case R.id.action_chat:
                startActivity(new Intent(WalletStatement.this,ChatActivity.class));
                break;

            case R.id.action_passbook :
                startActivity(new Intent(WalletStatement.this,PassbookActivity.class));
                break;

            case R.id.action_statement :
                startActivity(new Intent(WalletStatement.this,WalletStatement.class));
                break;

            case R.id.action_logout :
                signOutDialog();
                break;

            case R.id.action_transfer :
                startActivity(new Intent(WalletStatement.this,TransactionActivity.class));
                break;
        }

        return super.onOptionsItemSelected(item);
    }

    private void signOutDialog() {
        final AlertDialog.Builder builder=new AlertDialog.Builder(WalletStatement.this);
        builder.setMessage("Do you want to Sign Out").setTitle("Sign Out");

        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                try {
                    if(isInternetConnected()) {
                        FirebaseAuth.getInstance().signOut();
                        finish();
                        startActivity(new Intent(WalletStatement.this,LoginActivity.class));
                    }
                }
                catch (Exception e) {
                    Toast.makeText(WalletStatement.this,R.string.error,Toast.LENGTH_SHORT).show();
                }
            }
        });

        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
            }
        });

        AlertDialog dialog=builder.create();
        dialog.show();
    }

    private boolean isInternetConnected()
    {
        ConnectivityManager connectivityManager=(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo=connectivityManager.getActiveNetworkInfo();
        if(networkInfo==null || !networkInfo.isConnected() || !networkInfo.isAvailable()) {
            Toast.makeText(WalletStatement.this,"No Internet Connectivity",Toast.LENGTH_LONG).show();
            return false;
        }
        return true;
    }
}
<file_sep>/app/src/main/java/svkt/wallet/activities/LoginActivity.java
package svkt.wallet.activities;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import svkt.wallet.R;
import svkt.wallet.models.User;

public class LoginActivity extends AppCompatActivity {

    private static final String TAG = "LoginActivity";
    private TextInputEditText emailEdit,passwordEdit;
    private Button loginButton,registerButton;
    private String email,password;
    private FirebaseAuth firebaseAuth;
    private FirebaseAuth.AuthStateListener authStateListener;
    private FirebaseUser firebaseUser;
    private ProgressDialog progressDialog;
    private DatabaseReference databaseReference;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        emailEdit = findViewById(R.id.email);
        passwordEdit = findViewById(R.id.password);
        loginButton = findViewById(R.id.loginButton);
        registerButton = findViewById(R.id.registerBtn);

        firebaseAuth = FirebaseAuth.getInstance();
        authStateListener=new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                firebaseUser = firebaseAuth.getCurrentUser();
                if (firebaseUser != null)                // User is signed in
                {
                    Log.e(TAG, "User Sign in:" + firebaseUser.getUid());
                    databaseReference= FirebaseDatabase.getInstance().getReference().child("users").child(firebaseUser.getUid());
                    startActivity(new Intent(LoginActivity.this,ChatActivity.class));
                } else
                    Log.d(TAG, "No user");
            }
        };

        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                email = emailEdit.getText().toString();
                password = passwordEdit.getText().toString();
                if(isValid()){
                    showProgressDialog();
                    signInAccount();
                }
            }
        });

        registerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(LoginActivity.this,RegisterActivity.class));
            }
        });
    }

    private boolean isValid(){
        if(email.isEmpty() || !isEmailValid(email)){
            emailEdit.setError(getString(R.string.email_error));
            emailEdit.setFocusable(true);
            return false;
        }
        else if(password.isEmpty() || password.length() < 8){
            passwordEdit.setError(getString(R.string.password_error));
            passwordEdit.setFocusable(true);
            return false;
        }
        return true;
    }

    private boolean isEmailValid(String email){
        return !TextUtils.isEmpty(email) && android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
    }

    public void signInAccount()
    {
        firebaseAuth.signInWithEmailAndPassword(email, password)
                .addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(task.isSuccessful()) {
                            Log.e(TAG, "Sign In complete:" + task.isSuccessful());
                            firebaseUser = firebaseAuth.getCurrentUser();
                            databaseReference= FirebaseDatabase.getInstance().getReference().child("users").child(firebaseUser.getUid());
                            retrieveData();
                            hideProgressDialog();
                        }
                        else {
                            Log.e(TAG, "signInWithEmail", task.getException());
                            hideProgressDialog();
                            Toast.makeText(LoginActivity.this, "Invalid User",Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }

    public void showProgressDialog()
    {
        progressDialog=new ProgressDialog(LoginActivity.this);
        progressDialog.setCancelable(false);
        progressDialog.setMessage("Loading Wallet...");
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.show();
    }

    public void hideProgressDialog()
    {
        progressDialog.dismiss();
    }

    public void retrieveData()
    {
        databaseReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot)
            {
                User user = dataSnapshot.getValue(User.class);
                Toast.makeText(LoginActivity.this,"Welcome " + user.name,Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();
        firebaseAuth.addAuthStateListener(authStateListener);
    }

    @Override
    public void onStop() {
        super.onStop();
        firebaseAuth.removeAuthStateListener(authStateListener);
    }
}
<file_sep>/app/src/main/java/svkt/wallet/activities/TransactionActivity.java
package svkt.wallet.activities;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;

import svkt.wallet.R;
import svkt.wallet.models.Transaction;
import svkt.wallet.models.User;

public class TransactionActivity extends AppCompatActivity {

    private static final String TAG = "TransactionActivity";
    private TextView totalBalanceText;
    private TextInputEditText contactNoEdit,amountEdit;
    private Button transferBtn;
    private String phoneNo, amount;
    private ProgressDialog progressDialog;
    private FirebaseUser firebaseUser;
    private DatabaseReference databaseReference;
    private User currentUser,destUser;
    private String hashKey;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transaction);
        getSupportActionBar().setTitle("Transfer Funds");

        totalBalanceText = findViewById(R.id.totalBalance);
        contactNoEdit = findViewById(R.id.contactNo);
        amountEdit = findViewById(R.id.amount);
        transferBtn = findViewById(R.id.transferBtn);

        Bundle bundle = getIntent().getExtras();
        if(bundle != null){
            String phoneNo = bundle.getString("PHONE_NO");
            String amount = bundle.getString("AMOUNT");
            contactNoEdit.setText(phoneNo.substring(1,phoneNo.length()-1));
            amountEdit.setText(amount.substring(1,amount.length()-1));
        }
        getSelfUser();

        transferBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                phoneNo = contactNoEdit.getText().toString();
                amount = amountEdit.getText().toString();
                if(isValid()){
                    showProgressDialog("Checking if user exists...");
                    userExists(phoneNo);
                }
            }
        });
    }

    private boolean isValid(){
        if(phoneNo.isEmpty()){
            contactNoEdit.setError("Enter existng phone No on Wallet");
            contactNoEdit.setFocusable(true);
            return false;
        }
        else if(amount.isEmpty()){
            amountEdit.setError("Please enter amount");
            amountEdit.setFocusable(true);
            return false;
        }
        else if(Float.parseFloat(amount) > currentUser.balance){
            Toast.makeText(TransactionActivity.this,"You have unsufficient balance in our account",Toast.LENGTH_SHORT).show();
            amountEdit.setFocusable(true);
            return false;
        }
        return true;
    }

    private void doTransaction(String hashKey,long destAmount,String toName){
        destAmount += Long.parseLong(amount);
        FirebaseUser fUser = FirebaseAuth.getInstance().getCurrentUser();
        currentUser.balance -= Long.parseLong(amount);

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calobj = Calendar.getInstance();
        String date = df.format(calobj.getTime());

        Transaction destTransaction = new Transaction(hashKey,fUser.getUid(),toName,currentUser.name,amount,date,"received");
        Transaction srcTransaction = new Transaction(hashKey,fUser.getUid(),toName,currentUser.name,amount,date,"paid");

        DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("users");
        reference.child(hashKey).child("balance").setValue(destAmount);
        reference.child(fUser.getUid()).child("balance").setValue(currentUser.balance);

        DatabaseReference transRefer = FirebaseDatabase.getInstance().getReference().child("transaction");
        transRefer.child(fUser.getUid()).push().setValue(srcTransaction);
        transRefer.child(hashKey).push().setValue(destTransaction);

        Toast.makeText(TransactionActivity.this,"Transaction completed",Toast.LENGTH_SHORT).show();
        finish();
    }

    private void getSelfUser(){
        firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
        databaseReference = FirebaseDatabase.getInstance().getReference().child("users").child(firebaseUser.getUid());
        databaseReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                currentUser = dataSnapshot.getValue(User.class);
                totalBalanceText.setText(getString(R.string.Rs) + currentUser.balance);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });
    }

    private void userExists(String phoneNo){
        Query query = FirebaseDatabase.getInstance().getReference().child("users")
                .orderByChild("contactNo").equalTo(phoneNo);
        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Log.e(TAG,"Value = " + dataSnapshot.getValue());

                if(dataSnapshot.getValue() == null){
                    hideProgressDialog();
                    Toast.makeText(TransactionActivity.this,R.string.no_user,Toast.LENGTH_SHORT).show();
                }
                else{
                    hideProgressDialog();
                    HashMap map = (HashMap) dataSnapshot.getValue();
                    for ( Object key : map.keySet() ) {
                        hashKey = (String) key;
                    }
                    Log.e(TAG,"key" + map.keySet());
                    HashMap map2 = (HashMap) map.get(hashKey);
                    String toName = (String) map2.get("name");
                    long destAmount = (long) map2.get("balance");
                    Log.e(TAG,"Dest user balance = " + destAmount);
                    doTransaction(hashKey,destAmount,toName);
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                Log.e(TAG,"Database error = " + databaseError);
            }
        });
    }

    public void showProgressDialog(String message) {
        progressDialog=new ProgressDialog(TransactionActivity.this);
        progressDialog.setCancelable(false);
        progressDialog.setMessage(message);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.show();
    }

    public void hideProgressDialog()
    {
        progressDialog.dismiss();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_passbook, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        switch (id)
        {
            case R.id.action_chat:
                startActivity(new Intent(TransactionActivity.this,ChatActivity.class));
                break;

            case R.id.action_passbook :
                startActivity(new Intent(TransactionActivity.this,PassbookActivity.class));
                break;

            case R.id.action_statement :
                startActivity(new Intent(TransactionActivity.this,WalletStatement.class));
                break;

            case R.id.action_logout :
                signOutDialog();
                break;

            case R.id.action_transfer :
                startActivity(new Intent(TransactionActivity.this,TransactionActivity.class));
                break;


        }

        return super.onOptionsItemSelected(item);
    }

    private void signOutDialog() {
        final AlertDialog.Builder builder=new AlertDialog.Builder(TransactionActivity.this);
        builder.setMessage("Do you want to Sign Out").setTitle("Sign Out");

        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                try {
                    if(isInternetConnected()) {
                        FirebaseAuth.getInstance().signOut();
                        finish();
                        startActivity(new Intent(TransactionActivity.this,LoginActivity.class));
                    }
                }
                catch (Exception e) {
                    Toast.makeText(TransactionActivity.this,R.string.error,Toast.LENGTH_SHORT).show();
                }
            }
        });

        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
            }
        });

        AlertDialog dialog=builder.create();
        dialog.show();
    }

    private boolean isInternetConnected()
    {
        ConnectivityManager connectivityManager=(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo=connectivityManager.getActiveNetworkInfo();
        if(networkInfo==null || !networkInfo.isConnected() || !networkInfo.isAvailable()) {
            Toast.makeText(TransactionActivity.this,"No Internet Connectivity",Toast.LENGTH_LONG).show();
            return false;
        }
        return true;
    }
}
<file_sep>/app/src/main/java/svkt/wallet/activities/PassbookActivity.java
package svkt.wallet.activities;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;

import svkt.wallet.R;
import svkt.wallet.fragments.AllFragment;
import svkt.wallet.fragments.PaidFragment;
import svkt.wallet.fragments.ReceivedFragment;
import svkt.wallet.models.Transaction;

public class PassbookActivity extends AppCompatActivity {

    /**
     * The {@link android.support.v4.view.PagerAdapter} that will provide
     * fragments for each of the sections. We use a
     * {@link FragmentPagerAdapter} derivative, which will keep every
     * loaded fragment in memory. If this becomes too memory intensive, it
     * may be best to switch to a
     * {@link android.support.v4.app.FragmentStatePagerAdapter}.
     */
    private SectionsPagerAdapter mSectionsPagerAdapter;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
    private ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_passbook);

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = findViewById(R.id.container);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        TabLayout tabLayout = findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(mViewPager);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_passbook, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        switch (id)
        {
            case R.id.action_chat:
                startActivity(new Intent(PassbookActivity.this,ChatActivity.class));
                break;

            case R.id.action_passbook :
                startActivity(new Intent(PassbookActivity.this,PassbookActivity.class));
                break;

            case R.id.action_statement :
                startActivity(new Intent(PassbookActivity.this,WalletStatement.class));
                break;

            case R.id.action_logout :
                signOutDialog();
                break;

            case R.id.action_transfer :
                startActivity(new Intent(PassbookActivity.this,TransactionActivity.class));
                break;

        }

        return super.onOptionsItemSelected(item);
    }

    private void signOutDialog() {
        final AlertDialog.Builder builder=new AlertDialog.Builder(PassbookActivity.this);
        builder.setMessage("Do you want to Sign Out").setTitle("Sign Out");

        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                try {
                    if(isInternetConnected()) {
                        FirebaseAuth.getInstance().signOut();
                        finish();
                        startActivity(new Intent(PassbookActivity.this,LoginActivity.class));
                    }
                }
                catch (Exception e) {
                    Toast.makeText(PassbookActivity.this,R.string.error,Toast.LENGTH_SHORT).show();
                }
            }
        });

        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
            }
        });

        AlertDialog dialog=builder.create();
        dialog.show();
    }

    private boolean isInternetConnected()
    {
        ConnectivityManager connectivityManager=(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo=connectivityManager.getActiveNetworkInfo();
        if(networkInfo==null || !networkInfo.isConnected() || !networkInfo.isAvailable()) {
            Toast.makeText(PassbookActivity.this,"No Internet Connectivity",Toast.LENGTH_LONG).show();
            return false;
        }
        return true;
    }

    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch(position)
            {
                case 0 :
                    AllFragment allFragment = new AllFragment();
                    return allFragment;
                case 1 :
                    PaidFragment paidFragment = new PaidFragment();
                    return paidFragment;
                case 2 :
                    ReceivedFragment receivedFragment = new ReceivedFragment();
                    return receivedFragment;
            }
            return null;
        }

        @Override
        public int getCount() {
            // Show 3 total pages.
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "All";
                case 1:
                    return "Paid";
                case 2:
                    return "Received";
            }
            return null;
        }
    }
}
<file_sep>/app/src/main/java/svkt/wallet/adapter/TransactionListAdapter.java
package svkt.wallet.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import svkt.wallet.R;
import svkt.wallet.models.Transaction;

/**
 * Created by kaustubh on 04-11-2017.
 */

public class TransactionListAdapter extends RecyclerView.Adapter<TransactionListAdapter.ViewHolder>{

    Context context;
    ArrayList<Transaction> transactions;
    public TransactionListAdapter(Context context, ArrayList<Transaction> transactions){
        this.context = context;
        this.transactions = transactions;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.list_item_transaction,parent,false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Transaction transaction = transactions.get(position);
        Log.e("TransactionListAdapter",transaction.from);

        holder.amount.setText(context.getString(R.string.Rs) +transaction.amount);
        holder.transactionDate.setText(transaction.date);
        if(transaction.type.equals("paid")){
            holder.arrowView.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_arrow_upward_orange_24dp));
            holder.transactionName.setText(transaction.toName);
        }
        else if(transaction.type.equals("received")){
            holder.arrowView.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_arrow_downward_orange_24dp));
            holder.transactionName.setText(transaction.fromName);
        }
    }

    @Override
    public int getItemCount() {
        return transactions.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView transactionName , transactionDate ,amount ;
        ImageView arrowView;
        ViewHolder(View itemView) {
            super(itemView);
            transactionName = itemView.findViewById(R.id.transactionName);
            transactionDate = itemView.findViewById(R.id.transactionDate);
            amount = itemView.findViewById(R.id.amount);
            arrowView = itemView.findViewById(R.id.arrow);
        }
    }
}
