- Added option to reorder transactions list
- Fixed Toast when restoring backup
This commit is contained in:
parent
6eb43f93be
commit
78fc4fbf0b
7 changed files with 270 additions and 18 deletions
|
@ -24,6 +24,18 @@ public interface TransactionDao {
|
||||||
@Query("SELECT * FROM crypto_coin_transaction ORDER BY date DESC")
|
@Query("SELECT * FROM crypto_coin_transaction ORDER BY date DESC")
|
||||||
LivePagedListProvider<Integer, CryptoCoinTransaction> transactionsByDate();
|
LivePagedListProvider<Integer, CryptoCoinTransaction> transactionsByDate();
|
||||||
|
|
||||||
|
@Query("SELECT * FROM crypto_coin_transaction ORDER BY amount DESC")
|
||||||
|
LivePagedListProvider<Integer, CryptoCoinTransaction> transactionsByAmount();
|
||||||
|
|
||||||
|
@Query("SELECT * FROM crypto_coin_transaction ORDER BY is_input DESC")
|
||||||
|
LivePagedListProvider<Integer, CryptoCoinTransaction> transactionsByIsInput();
|
||||||
|
|
||||||
|
@Query("SELECT * FROM crypto_coin_transaction ORDER BY `from` DESC")
|
||||||
|
LivePagedListProvider<Integer, CryptoCoinTransaction> transactionsByFrom();
|
||||||
|
|
||||||
|
@Query("SELECT * FROM crypto_coin_transaction ORDER BY `to` DESC")
|
||||||
|
LivePagedListProvider<Integer, CryptoCoinTransaction> transactionsByTo();
|
||||||
|
|
||||||
@Query("SELECT * FROM crypto_coin_transaction WHERE account_id = :idAccount ORDER BY date DESC")
|
@Query("SELECT * FROM crypto_coin_transaction WHERE account_id = :idAccount ORDER BY date DESC")
|
||||||
LiveData<List<CryptoCoinTransaction>> getByIdAccountLiveData(long idAccount);
|
LiveData<List<CryptoCoinTransaction>> getByIdAccountLiveData(long idAccount);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import cy.agorise.crystalwallet.R;
|
import cy.agorise.crystalwallet.R;
|
||||||
|
import cy.agorise.crystalwallet.activities.IntroActivity;
|
||||||
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequestListener;
|
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequestListener;
|
||||||
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequests;
|
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequests;
|
||||||
import cy.agorise.crystalwallet.requestmanagers.ImportBackupRequest;
|
import cy.agorise.crystalwallet.requestmanagers.ImportBackupRequest;
|
||||||
|
@ -127,17 +128,26 @@ public class ImportAccountOptionsFragment extends DialogFragment {
|
||||||
importBackupRequest.setListener(new FileServiceRequestListener() {
|
importBackupRequest.setListener(new FileServiceRequestListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCarryOut() {
|
public void onCarryOut() {
|
||||||
if (importBackupRequest.getStatus() == ImportBackupRequest.StatusCode.SUCCEEDED){
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (importBackupRequest.getStatus() == ImportBackupRequest.StatusCode.SUCCEEDED) {
|
||||||
Toast toast = Toast.makeText(
|
Toast toast = Toast.makeText(
|
||||||
getContext(), "Backup restored!", Toast.LENGTH_LONG);
|
getContext(), "Backup restored!", Toast.LENGTH_LONG);
|
||||||
toast.show();
|
toast.show();
|
||||||
} else if (importBackupRequest.getStatus() == ImportBackupRequest.StatusCode.FAILED){
|
|
||||||
|
Intent intent = new Intent(getContext(), IntroActivity.class);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
} else if (importBackupRequest.getStatus() == ImportBackupRequest.StatusCode.FAILED) {
|
||||||
Toast toast = Toast.makeText(
|
Toast toast = Toast.makeText(
|
||||||
getContext(), "An error ocurred while restoring the backup!", Toast.LENGTH_LONG);
|
getContext(), "An error ocurred while restoring the backup!", Toast.LENGTH_LONG);
|
||||||
toast.show();
|
toast.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
FileServiceRequests.getInstance().addRequest(importBackupRequest);
|
FileServiceRequests.getInstance().addRequest(importBackupRequest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,10 @@ import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
|
@ -21,16 +24,23 @@ import cy.agorise.crystalwallet.R;
|
||||||
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
||||||
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
|
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
|
||||||
import cy.agorise.crystalwallet.views.TransactionListView;
|
import cy.agorise.crystalwallet.views.TransactionListView;
|
||||||
|
import cy.agorise.crystalwallet.views.TransactionOrderSpinnerAdapter;
|
||||||
|
|
||||||
public class TransactionsFragment extends Fragment {
|
public class TransactionsFragment extends Fragment {
|
||||||
|
|
||||||
@BindView(R.id.vTransactionListView)
|
@BindView(R.id.vTransactionListView)
|
||||||
TransactionListView transactionListView;
|
TransactionListView transactionListView;
|
||||||
|
|
||||||
|
@BindView(R.id.spTransactionsOrder)
|
||||||
|
Spinner spTransactionsOrder;
|
||||||
|
|
||||||
RecyclerView balanceRecyclerView;
|
RecyclerView balanceRecyclerView;
|
||||||
FloatingActionButton fabSend;
|
FloatingActionButton fabSend;
|
||||||
FloatingActionButton fabReceive;
|
FloatingActionButton fabReceive;
|
||||||
|
|
||||||
|
TransactionListViewModel transactionListViewModel;
|
||||||
|
LiveData<PagedList<CryptoCoinTransaction>> transactionsLiveData;
|
||||||
|
|
||||||
public TransactionsFragment() {
|
public TransactionsFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
@ -83,8 +93,23 @@ public class TransactionsFragment extends Fragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
TransactionListViewModel transactionListViewModel = ViewModelProviders.of(this).get(TransactionListViewModel.class);
|
transactionListViewModel = ViewModelProviders.of(this).get(TransactionListViewModel.class);
|
||||||
LiveData<PagedList<CryptoCoinTransaction>> transactionsLiveData = transactionListViewModel.getTransactionList();
|
|
||||||
|
|
||||||
|
initTransactionsOrderSpinner();
|
||||||
|
changeTransactionList();
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeTransactionList(){
|
||||||
|
TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem orderSelected =
|
||||||
|
(TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem)(spTransactionsOrder.getSelectedItem());
|
||||||
|
|
||||||
|
if (transactionsLiveData != null){
|
||||||
|
transactionsLiveData.removeObservers(this);
|
||||||
|
}
|
||||||
|
transactionListViewModel.initTransactionList(orderSelected.getField());
|
||||||
|
transactionsLiveData = transactionListViewModel.getTransactionList();
|
||||||
|
|
||||||
final Fragment fragment = this;
|
final Fragment fragment = this;
|
||||||
transactionsLiveData.observe(this, new Observer<PagedList<CryptoCoinTransaction>>() {
|
transactionsLiveData.observe(this, new Observer<PagedList<CryptoCoinTransaction>>() {
|
||||||
|
@ -93,7 +118,32 @@ public class TransactionsFragment extends Fragment {
|
||||||
transactionListView.setData(cryptoCoinTransactions, fragment);
|
transactionListView.setData(cryptoCoinTransactions, fragment);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return view;
|
public void initTransactionsOrderSpinner(){
|
||||||
|
List<TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem> spinnerValues = new ArrayList<TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem>();
|
||||||
|
spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("date","Date",0,false));
|
||||||
|
spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("amount","Amount",0,false));
|
||||||
|
spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("is_input","In/Out",0,false));
|
||||||
|
spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("from","From",0,false));
|
||||||
|
spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("to","To",0,false));
|
||||||
|
|
||||||
|
TransactionOrderSpinnerAdapter transactionOrderSpinnerAdapter =
|
||||||
|
new TransactionOrderSpinnerAdapter(
|
||||||
|
getContext(), android.R.layout.simple_spinner_item,spinnerValues
|
||||||
|
);
|
||||||
|
spTransactionsOrder.setAdapter(transactionOrderSpinnerAdapter);
|
||||||
|
|
||||||
|
spTransactionsOrder.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
|
||||||
|
changeTransactionList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNothingSelected(AdapterView<?> adapterView) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Application;
|
||||||
import android.arch.lifecycle.AndroidViewModel;
|
import android.arch.lifecycle.AndroidViewModel;
|
||||||
import android.arch.lifecycle.LiveData;
|
import android.arch.lifecycle.LiveData;
|
||||||
import android.arch.lifecycle.ViewModel;
|
import android.arch.lifecycle.ViewModel;
|
||||||
|
import android.arch.paging.LivePagedListProvider;
|
||||||
import android.arch.paging.PagedList;
|
import android.arch.paging.PagedList;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
@ -25,13 +26,46 @@ public class TransactionListViewModel extends AndroidViewModel {
|
||||||
public TransactionListViewModel(Application application) {
|
public TransactionListViewModel(Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
|
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
|
||||||
transactionList = this.db.transactionDao().transactionsByDate().create(0,
|
/*transactionList = this.db.transactionDao().transactionsByDate().create(0,
|
||||||
|
new PagedList.Config.Builder()
|
||||||
|
.setEnablePlaceholders(true)
|
||||||
|
.setPageSize(10)
|
||||||
|
.setPrefetchDistance(10)
|
||||||
|
.build()
|
||||||
|
);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initTransactionList(String orderField){
|
||||||
|
LivePagedListProvider<Integer, CryptoCoinTransaction> livePagedListProvider = null;
|
||||||
|
|
||||||
|
switch (orderField){
|
||||||
|
case "date":
|
||||||
|
livePagedListProvider = this.db.transactionDao().transactionsByDate();
|
||||||
|
break;
|
||||||
|
case "amount":
|
||||||
|
livePagedListProvider = this.db.transactionDao().transactionsByAmount();
|
||||||
|
break;
|
||||||
|
case "is_input":
|
||||||
|
livePagedListProvider = this.db.transactionDao().transactionsByIsInput();
|
||||||
|
break;
|
||||||
|
case "from":
|
||||||
|
livePagedListProvider = this.db.transactionDao().transactionsByFrom();
|
||||||
|
break;
|
||||||
|
case "to":
|
||||||
|
livePagedListProvider = this.db.transactionDao().transactionsByTo();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (livePagedListProvider != null) {
|
||||||
|
this.transactionList = livePagedListProvider.create(0,
|
||||||
new PagedList.Config.Builder()
|
new PagedList.Config.Builder()
|
||||||
.setEnablePlaceholders(true)
|
.setEnablePlaceholders(true)
|
||||||
.setPageSize(10)
|
.setPageSize(10)
|
||||||
.setPrefetchDistance(10)
|
.setPrefetchDistance(10)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
this.transactionList = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<PagedList<CryptoCoinTransaction>> getTransactionList(){
|
public LiveData<PagedList<CryptoCoinTransaction>> getTransactionList(){
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
package cy.agorise.crystalwallet.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import cy.agorise.crystalwallet.R;
|
||||||
|
import cy.agorise.crystalwallet.models.CryptoCurrency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Henry Varona on 09/04/2018.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class TransactionOrderSpinnerAdapter extends ArrayAdapter<TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem> {
|
||||||
|
public static class TransactionOrderSpinnerItem {
|
||||||
|
private String field;
|
||||||
|
private String label;
|
||||||
|
private boolean ascending;
|
||||||
|
private int order;
|
||||||
|
|
||||||
|
public TransactionOrderSpinnerItem(String field, String label, int order, boolean ascending){
|
||||||
|
this.field = field;
|
||||||
|
this.label = label;
|
||||||
|
this.ascending = ascending;
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAscending(boolean newValue){
|
||||||
|
this.ascending = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder(int newValue){
|
||||||
|
this.order = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getField(){
|
||||||
|
return this.field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel(){
|
||||||
|
return this.label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOrder(){
|
||||||
|
return this.order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getAscending(){
|
||||||
|
return this.ascending;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private List<TransactionOrderSpinnerItem> data;
|
||||||
|
|
||||||
|
public TransactionOrderSpinnerAdapter(Context context, int resource, List<TransactionOrderSpinnerItem> objects) {
|
||||||
|
super(context, resource, objects);
|
||||||
|
this.data = objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||||
|
return getView(position, convertView, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creates the view for every element of the spinner
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
View v = inflater.inflate(R.layout.transactions_order_adapter_item, parent, false);
|
||||||
|
TextView tvTransactionOrderLabel = v.findViewById(R.id.tvTransactionOrderLabel);
|
||||||
|
|
||||||
|
TransactionOrderSpinnerItem transactionOrderSpinnerItem = getItem(position);
|
||||||
|
tvTransactionOrderLabel.setText(transactionOrderSpinnerItem.getLabel());
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,9 +5,38 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/rlTransactionToolsHeader"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etTransactionSearch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnTransactionsFilterDisplay"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/spTransactionsOrder"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="order"
|
||||||
|
/>
|
||||||
|
</RelativeLayout>
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/transactionListView"
|
android:id="@+id/transactionListView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/rlTransactionToolsHeader"
|
||||||
/>
|
/>
|
||||||
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
31
app/src/main/res/layout/transactions_order_adapter_item.xml
Normal file
31
app/src/main/res/layout/transactions_order_adapter_item.xml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="10dp"
|
||||||
|
android:paddingTop="10dp">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/ivTransactionOrderAscending"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@android:drawable/arrow_up_float" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvTransactionOrderLabel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_toRightOf="@+id/ivTransactionOrderAscending"
|
||||||
|
android:ems="10"
|
||||||
|
android:text="Date" />
|
||||||
|
</RelativeLayout>
|
||||||
|
</LinearLayout>
|
Loading…
Reference in a new issue