- Fixing Transaction list to work properly
- Improving UI transaction list info
This commit is contained in:
parent
8745b32446
commit
2b638acd89
7 changed files with 107 additions and 11 deletions
|
@ -20,13 +20,13 @@ public interface TransactionDao {
|
||||||
@Query("SELECT * FROM crypto_coin_transaction")
|
@Query("SELECT * FROM crypto_coin_transaction")
|
||||||
LiveData<List<CryptoCoinTransaction>> getAll();
|
LiveData<List<CryptoCoinTransaction>> getAll();
|
||||||
|
|
||||||
@Query("SELECT * FROM crypto_coin_transaction ORDER BY date ASC")
|
@Query("SELECT * FROM crypto_coin_transaction ORDER BY date DESC")
|
||||||
LivePagedListProvider<Integer, CryptoCoinTransaction> transactionsByDate();
|
LivePagedListProvider<Integer, CryptoCoinTransaction> transactionsByDate();
|
||||||
|
|
||||||
@Query("SELECT * FROM crypto_coin_transaction WHERE account_id = :idAccount ORDER BY date ASC")
|
@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);
|
||||||
|
|
||||||
@Query("SELECT * FROM crypto_coin_transaction WHERE account_id = :idAccount ORDER BY date ASC")
|
@Query("SELECT * FROM crypto_coin_transaction WHERE account_id = :idAccount ORDER BY date DESC")
|
||||||
List<CryptoCoinTransaction> getByIdAccount(long idAccount);
|
List<CryptoCoinTransaction> getByIdAccount(long idAccount);
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
|
|
@ -1,14 +1,30 @@
|
||||||
package cy.agorise.crystalwallet.fragments;
|
package cy.agorise.crystalwallet.fragments;
|
||||||
|
|
||||||
|
import android.arch.lifecycle.LiveData;
|
||||||
|
import android.arch.lifecycle.Observer;
|
||||||
|
import android.arch.lifecycle.ViewModelProviders;
|
||||||
|
import android.arch.paging.PagedList;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
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 java.util.List;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
import cy.agorise.crystalwallet.R;
|
import cy.agorise.crystalwallet.R;
|
||||||
|
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
||||||
|
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
|
||||||
|
import cy.agorise.crystalwallet.views.TransactionListView;
|
||||||
|
|
||||||
public class TransactionsFragment extends Fragment {
|
public class TransactionsFragment extends Fragment {
|
||||||
|
|
||||||
|
@BindView(R.id.vTransactionListView)
|
||||||
|
TransactionListView transactionListView;
|
||||||
|
|
||||||
public TransactionsFragment() {
|
public TransactionsFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
@ -29,6 +45,20 @@ public class TransactionsFragment extends Fragment {
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
return inflater.inflate(R.layout.fragment_transactions, container, false);
|
View v = inflater.inflate(R.layout.fragment_transactions, container, false);
|
||||||
|
ButterKnife.bind(this, v);
|
||||||
|
|
||||||
|
TransactionListViewModel transactionListViewModel = ViewModelProviders.of(this).get(TransactionListViewModel.class);
|
||||||
|
LiveData<PagedList<CryptoCoinTransaction>> transactionsLiveData = transactionListViewModel.getTransactionList();
|
||||||
|
|
||||||
|
final Fragment fragment = this;
|
||||||
|
transactionsLiveData.observe(this, new Observer<PagedList<CryptoCoinTransaction>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(@Nullable PagedList<CryptoCoinTransaction> cryptoCoinTransactions) {
|
||||||
|
transactionListView.setData(cryptoCoinTransactions, fragment);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package cy.agorise.crystalwallet.viewmodels;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.arch.lifecycle.AndroidViewModel;
|
||||||
|
import android.arch.lifecycle.LiveData;
|
||||||
|
|
||||||
|
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||||
|
import cy.agorise.crystalwallet.models.CryptoCurrency;
|
||||||
|
import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Henry Varona on 4/11/2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CryptoCurrencyViewModel extends AndroidViewModel {
|
||||||
|
|
||||||
|
private CrystalDatabase db;
|
||||||
|
|
||||||
|
public CryptoCurrencyViewModel(Application application) {
|
||||||
|
super(application);
|
||||||
|
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
public CryptoCurrency getCryptoCurrencyById(long id){
|
||||||
|
return this.db.cryptoCurrencyDao().getById(id);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import android.arch.paging.PagedListAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -30,8 +31,11 @@ import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
||||||
|
|
||||||
public class TransactionListAdapter extends PagedListAdapter<CryptoCoinTransaction, TransactionViewHolder> {
|
public class TransactionListAdapter extends PagedListAdapter<CryptoCoinTransaction, TransactionViewHolder> {
|
||||||
|
|
||||||
public TransactionListAdapter() {
|
Fragment fragment;
|
||||||
|
|
||||||
|
public TransactionListAdapter(Fragment fragment) {
|
||||||
super(CryptoCoinTransaction.DIFF_CALLBACK);
|
super(CryptoCoinTransaction.DIFF_CALLBACK);
|
||||||
|
this.fragment = fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,7 +43,7 @@ public class TransactionListAdapter extends PagedListAdapter<CryptoCoinTransacti
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.transaction_list_item,parent,false);
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.transaction_list_item,parent,false);
|
||||||
|
|
||||||
|
|
||||||
return new TransactionViewHolder(v);
|
return new TransactionViewHolder(v, this.fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cy.agorise.crystalwallet.views;
|
||||||
|
|
||||||
import android.arch.paging.PagedList;
|
import android.arch.paging.PagedList;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
@ -109,10 +110,10 @@ public class TransactionListView extends RelativeLayout {
|
||||||
*
|
*
|
||||||
* @param data the transactions that will be showed to the user
|
* @param data the transactions that will be showed to the user
|
||||||
*/
|
*/
|
||||||
public void setData(PagedList<CryptoCoinTransaction> data){
|
public void setData(PagedList<CryptoCoinTransaction> data, Fragment fragment){
|
||||||
//Initializes the adapter of the transaction list
|
//Initializes the adapter of the transaction list
|
||||||
if (this.listAdapter == null) {
|
if (this.listAdapter == null) {
|
||||||
this.listAdapter = new TransactionListAdapter();
|
this.listAdapter = new TransactionListAdapter(fragment);
|
||||||
this.listView.setAdapter(this.listAdapter);
|
this.listView.setAdapter(this.listAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package cy.agorise.crystalwallet.views;
|
package cy.agorise.crystalwallet.views;
|
||||||
|
|
||||||
|
import android.arch.lifecycle.LifecycleOwner;
|
||||||
|
import android.arch.lifecycle.ViewModelProviders;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import cy.agorise.crystalwallet.R;
|
import cy.agorise.crystalwallet.R;
|
||||||
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
||||||
|
import cy.agorise.crystalwallet.models.CryptoCurrency;
|
||||||
|
import cy.agorise.crystalwallet.viewmodels.CryptoCurrencyViewModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Henry Varona on 17/9/2017.
|
* Created by Henry Varona on 17/9/2017.
|
||||||
|
@ -27,14 +32,18 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
|
||||||
*/
|
*/
|
||||||
private TextView transactionAmount;
|
private TextView transactionAmount;
|
||||||
|
|
||||||
|
private TextView tvTransactionDate;
|
||||||
|
|
||||||
public TransactionViewHolder(View itemView) {
|
private Fragment fragment;
|
||||||
|
|
||||||
|
public TransactionViewHolder(View itemView, Fragment fragment) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
//TODO: use ButterKnife to load this
|
//TODO: use ButterKnife to load this
|
||||||
transactionFrom = (TextView) itemView.findViewById(R.id.fromText);
|
transactionFrom = (TextView) itemView.findViewById(R.id.fromText);
|
||||||
transactionTo = (TextView) itemView.findViewById(R.id.toText);
|
transactionTo = (TextView) itemView.findViewById(R.id.toText);
|
||||||
transactionAmount = (TextView) itemView.findViewById(R.id.amountText);
|
transactionAmount = (TextView) itemView.findViewById(R.id.amountText);
|
||||||
|
tvTransactionDate = (TextView) itemView.findViewById(R.id.tvTransactionDate);
|
||||||
|
this.fragment = fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -55,9 +64,23 @@ public class TransactionViewHolder extends RecyclerView.ViewHolder {
|
||||||
transactionTo.setText("");
|
transactionTo.setText("");
|
||||||
transactionAmount.setText("");
|
transactionAmount.setText("");
|
||||||
} else {
|
} else {
|
||||||
|
CryptoCurrencyViewModel cryptoCurrencyViewModel = ViewModelProviders.of(this.fragment).get(CryptoCurrencyViewModel.class);
|
||||||
|
CryptoCurrency cryptoCurrency = cryptoCurrencyViewModel.getCryptoCurrencyById(transaction.getIdCurrency());
|
||||||
|
String amountString = String.format("%.2f",transaction.getAmount()/Math.pow(10,cryptoCurrency.getPrecision()));
|
||||||
|
|
||||||
|
tvTransactionDate.setText(transaction.getDate().toString());
|
||||||
transactionFrom.setText(transaction.getFrom());
|
transactionFrom.setText(transaction.getFrom());
|
||||||
transactionTo.setText(transaction.getTo());
|
transactionTo.setText(transaction.getTo());
|
||||||
transactionAmount.setText("" + transaction.getAmount());
|
|
||||||
|
if (transaction.getInput()) {
|
||||||
|
transactionAmount.setTextColor(itemView.getContext().getResources().getColor(R.color.green));
|
||||||
|
} else {
|
||||||
|
transactionAmount.setTextColor(itemView.getContext().getResources().getColor(R.color.red));
|
||||||
|
}
|
||||||
|
transactionAmount.setText(
|
||||||
|
amountString
|
||||||
|
+ " "
|
||||||
|
+ cryptoCurrency.getName());
|
||||||
//This will load the transaction receipt when the user clicks this view
|
//This will load the transaction receipt when the user clicks this view
|
||||||
/*itemView.setOnClickListener(new View.OnClickListener() {
|
/*itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,10 +13,20 @@
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_alignParentTop="true">
|
android:layout_alignParentTop="true">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvTransactionDate"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:ems="10"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="date" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/fromText"
|
android:id="@+id/fromText"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/tvTransactionDate"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:text="from" />
|
android:text="from" />
|
||||||
|
@ -25,6 +35,7 @@
|
||||||
android:id="@+id/toText"
|
android:id="@+id/toText"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/tvTransactionDate"
|
||||||
android:layout_alignParentBottom="false"
|
android:layout_alignParentBottom="false"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
|
|
Loading…
Reference in a new issue