-
Notifications
You must be signed in to change notification settings - Fork 688
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be moved to the clients service itself.. |
||
} |
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>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename id to clientId