Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recent transactions feature added #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.mifos.selfserviceapp.api.services.AuthenticationService;
import org.mifos.selfserviceapp.api.services.ClientService;
import org.mifos.selfserviceapp.api.services.LoanAccountsListService;
import org.mifos.selfserviceapp.api.services.RecentTransactionsService;
import org.mifos.selfserviceapp.api.services.SavingAccountsListService;

import okhttp3.OkHttpClient;
Expand All @@ -23,6 +24,7 @@ public class BaseApiManager {
private ClientService clientsApi;
private SavingAccountsListService savingAccountsListApi;
private LoanAccountsListService loanAccountsListApi;
private RecentTransactionsService recentTransactionsApi;
private String authToken = "";

public BaseApiManager() {
Expand All @@ -35,6 +37,7 @@ public BaseApiManager(String authToken) {
clientsApi = createApi(ClientService.class, BASE_URL);
savingAccountsListApi = createApi(SavingAccountsListService.class, BASE_URL);
loanAccountsListApi = createApi(LoanAccountsListService.class, BASE_URL);
recentTransactionsApi = createApi(RecentTransactionsService.class, BASE_URL);
}

public OkHttpClient getOkHttpClient() {
Expand Down Expand Up @@ -73,6 +76,10 @@ public LoanAccountsListService getLoanAccountsListApi() {
return loanAccountsListApi;
}

public RecentTransactionsService getRecentTransactionsApi() {
return recentTransactionsApi;
}

public String getAuthToken() {
return authToken;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mifos.selfserviceapp.api;

import org.mifos.selfserviceapp.data.Client;
import org.mifos.selfserviceapp.data.Transaction;
import org.mifos.selfserviceapp.data.User;
import org.mifos.selfserviceapp.data.accounts.LoanAccount;
import org.mifos.selfserviceapp.data.accounts.SavingAccount;
Expand Down Expand Up @@ -49,6 +50,10 @@ public Call<LoanAccount> getLoanAccounts(int id) {
return baseApiManager.getLoanAccountsListApi().getLoanAccountsList(id);
}

public Call<Transaction> getRecentTransactions(int id) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename id to clientId

return baseApiManager.getRecentTransactionsApi().getRecentTransactionsList(id);
}

public PrefManager getPrefManager() {
return prefManager;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.mifos.selfserviceapp.api.services;

import org.mifos.selfserviceapp.api.ApiEndPoints;
import org.mifos.selfserviceapp.data.Transaction;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;

/**
* @author Vishwajeet
* @since 10/08/2016
*/
public interface RecentTransactionsService {
@GET(ApiEndPoints.CLIENTS + "/{clientId}/transactions")
Call<Transaction> getRecentTransactionsList(@Path("clientId") int clientId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be moved to the clients service itself..

}
70 changes: 70 additions & 0 deletions app/src/main/java/org/mifos/selfserviceapp/data/Transaction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.mifos.selfserviceapp.data;

import java.util.ArrayList;
import java.util.List;

/**
* @author Vishwajeet
* @since 10/8/16.
*/
public class Transaction {
private int id;
private List<Transaction> pageItems = new ArrayList<Transaction>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same refactoring needed as accounts.. move this list to something like TransactionListResponse class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!I was waiting for your review of accounts refactoring, will do it now.

private List<Integer> submittedOnDate = new ArrayList<Integer>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is date stored as integer? If it's timestamps, it's generally "long" type.

private float amount;
private Type type;

public List<Transaction> getPageItems() {
return pageItems;
}

public void setPageItems(List<Transaction> pageItems) {
this.pageItems = pageItems;
}

public List<Integer> getSubmittedOnDate() {
return submittedOnDate;
}

public void setSubmittedOndate(List<Integer> submittedOnDate) {
this.submittedOnDate = submittedOnDate;
}

public double getAmount() {
return amount;
}

public void setAmount(float amount) {
this.amount = amount;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public Type getType() {
return type;
}

public void setType (Type type) {
this.type = type;
}

public class Type {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can make this a static class. The advantage is that you don't need an instance of the outer class to access this.

private int id;
private String code;
private String value;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.mifos.selfserviceapp.ui.activities.LoginActivity;
import org.mifos.selfserviceapp.ui.fragments.ClientAccountsFragment;
import org.mifos.selfserviceapp.ui.fragments.LoanAccountsListFragment;
import org.mifos.selfserviceapp.ui.fragments.RecentTransactionsFragment;
import org.mifos.selfserviceapp.ui.fragments.SavingAccountsListFragment;

import dagger.Component;
Expand All @@ -32,4 +33,6 @@ public interface ActivityComponent {

void inject(SavingAccountsListFragment savingAccountsListFragment);

void inject(RecentTransactionsFragment recentTransactionsFragment);

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LoanAccountsListPresenter extends BasePresenter<LoanAccountsListVie
private DataManager dataManager;

/**
* Initialises the ClientListPresenter by automatically injecting an instance of
* Initialises the LoanAccountsListPresenter by automatically injecting an instance of
* {@link DataManager} and {@link Context}.
*
* @param dataManager DataManager class that provides access to the data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.mifos.selfserviceapp.presenters;

import android.content.Context;

import org.mifos.selfserviceapp.R;
import org.mifos.selfserviceapp.api.DataManager;
import org.mifos.selfserviceapp.data.Transaction;
import org.mifos.selfserviceapp.data.accounts.LoanAccount;
import org.mifos.selfserviceapp.injection.ActivityContext;
import org.mifos.selfserviceapp.presenters.base.BasePresenter;
import org.mifos.selfserviceapp.ui.views.RecentTransactionsView;

import java.util.List;

import javax.inject.Inject;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
* @author Vishwajeet
* @since 10/08/16
*/
public class RecentTransactionsPresenter extends BasePresenter<RecentTransactionsView> {
private DataManager dataManager;

/**
* Initialises the RecentTransactionsPresenter by automatically injecting an instance of
* {@link DataManager} and {@link Context}.
*
* @param dataManager DataManager class that provides access to the data
* via the API.
* @param context Context of the view attached to the presenter. In this case
* it is that of an {@link android.support.v7.app.AppCompatActivity}
*/

@Inject
public RecentTransactionsPresenter(DataManager dataManager, @ActivityContext Context context) {
super(context);
this.dataManager = dataManager;
}

public void loadRecentTransactions(int clientId) {
Call<Transaction> call = dataManager.getRecentTransactions(clientId);
getMvpView().showProgress();

call.enqueue(new Callback<Transaction>() {
@Override
public void onResponse(Response<Transaction> response) {
getMvpView().hideProgress();

if (response.code() == 200) {
Transaction recentTransaction = response.body();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this variable being used?

List<Transaction> recentTransactionsList = response.body().getPageItems();
if (recentTransaction != null) {
getMvpView().showRecentTransactions(recentTransactionsList);
}

} else if (response.code() >= 400 && response.code() < 500) {
getMvpView().showErrorFetchingRecentTransactions(context.getString(R.string.error_recent_transactions_loading));
} else if (response.code() == 500) {
getMvpView().showErrorFetchingRecentTransactions(context.getString(R.string.error_internal_server));
}
}

@Override
public void onFailure(Throwable t) {
getMvpView().hideProgress();
getMvpView().showErrorFetchingRecentTransactions(context.getString(R.string.error_message_server));
}
});
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SavingAccountsListPresenter extends BasePresenter<SavingAccountsLis
private DataManager dataManager;

/**
* Initialises the ClientListPresenter by automatically injecting an instance of
* Initialises the SavingAccountsListPresenter by automatically injecting an instance of
* {@link DataManager} and {@link Context}.
*
* @param dataManager DataManager class that provides access to the data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.mifos.selfserviceapp.R;
import org.mifos.selfserviceapp.ui.fragments.ClientAccountsFragment;
import org.mifos.selfserviceapp.ui.fragments.RecentTransactionsFragment;
import org.mifos.selfserviceapp.utils.Constants;


Expand All @@ -25,7 +26,6 @@
* @author Vishwajeet
* @since 14/07/2016
*/

public class HomeActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {

private int clientId;
Expand Down Expand Up @@ -69,11 +69,14 @@ public boolean onNavigationItemSelected(MenuItem item) {
// select which item to open
switch (item.getItemId()) {
case R.id.item_accounts:
ClientAccountsFragment.newInstance(clientId);
replaceFragment(ClientAccountsFragment.newInstance(clientId), R.id.container);
break;
case R.id.item_funds_transfer:
break;
case R.id.item_recent_transactions:
RecentTransactionsFragment.newInstance(clientId);
replaceFragment(RecentTransactionsFragment.newInstance(clientId), R.id.container);
break;
case R.id.item_questionnaire:
break;
Expand All @@ -84,6 +87,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
// close the drawer
mDrawerLayout.closeDrawer(GravityCompat.START);
mNavigationView.setCheckedItem(R.id.item_accounts);
setTitle(item.getTitle());
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.mifos.selfserviceapp.ui.adapters;

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

import org.mifos.selfserviceapp.R;
import org.mifos.selfserviceapp.data.Transaction;
import org.mifos.selfserviceapp.utils.Constants;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
* @author Vishwajeet
* @since 10/08/16
*/
public class RecentTransactionListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final Context context;
private final LayoutInflater layoutInflater;
private List<Transaction> transactionsList = new ArrayList<>();

public RecentTransactionListAdapter(Context context, List<Transaction> transactionsList) {
this.context = context;
layoutInflater = LayoutInflater.from(context);
this.transactionsList = transactionsList;
}

public Transaction getItem(int position) {
return transactionsList.get(position);
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RecyclerView.ViewHolder vh;
View v = LayoutInflater.from(parent.getContext()).inflate(
R.layout.row_recent_transaction, parent, false);
vh = new RecentTransactionListAdapter.ViewHolder(v);
return vh;
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof RecyclerView.ViewHolder) {

Transaction transaction = getItem(position);
((ViewHolder) holder).tvAmount.setText(String.valueOf(transaction.getAmount()));
((ViewHolder) holder).tvTypeValue.setText(transaction.getType().getValue());
((ViewHolder) holder).tvTransactionsDate.setText(transaction.getSubmittedOnDate().get(2).toString() +
Constants.BACK_SLASH + transaction.getSubmittedOnDate().get(1).toString() +
Constants.BACK_SLASH + transaction.getSubmittedOnDate().get(0).toString());
}

}

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

public static class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.tv_transactionDate)
TextView tvTransactionsDate;
@BindView(R.id.tv_amount)
TextView tvAmount;
@BindView(R.id.tv_value)
TextView tvTypeValue;

public ViewHolder(View v) {
super(v);
ButterKnife.bind(this, v);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
import butterknife.BindView;
import butterknife.ButterKnife;

/**
* @author Vishwajeet
* @since 14/07/2016
*/
public class ClientAccountsFragment extends Fragment {
private int clientId;

Expand Down
Loading