From 93a60e6084f60e6d6cdb219f88bb576dc442e7cc Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 13 Sep 2017 21:06:51 -0400 Subject: [PATCH] - First version of Transaction History views --- .../agorise/crystalwallet/IntroActivity.java | 11 +++++++ .../models/CryptoCoinTransaction.java | 29 +++++++++++++++++ .../views/TransactionListAdapter.java | 32 +++++++++++++++++-- .../views/TransactionListView.java | 10 +++--- app/src/main/res/layout/activity_intro.xml | 2 ++ .../main/res/layout/transaction_list_item.xml | 6 ++-- 6 files changed, 79 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java b/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java index 053774b..79826ad 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java @@ -4,11 +4,22 @@ import android.arch.lifecycle.LifecycleActivity; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel; +import cy.agorise.crystalwallet.views.TransactionListView; + public class IntroActivity extends LifecycleActivity { + TransactionListViewModel transactionListViewModel; + TransactionListView transactionListView; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_intro); + + transactionListViewModel = new TransactionListViewModel(getApplicationContext()); + transactionListView = this.findViewById(R.id.transaction_list); + + transactionListView.init(transactionListViewModel); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java index 0f1ca61..15cd1b3 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java @@ -32,6 +32,35 @@ public class CryptoCoinTransaction { @ColumnInfo(name="is_confirmed") protected boolean isConfirmed; + public int getAmount() { + return amount; + } + + public void setAmount(int amount) { + this.amount = amount; + } + + @ColumnInfo(name="from") + protected String from; + @ColumnInfo(name="to") + protected String to; + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } + public int getAccountId() { return accountId; } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListAdapter.java index 84a12d9..a687097 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListAdapter.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListAdapter.java @@ -1,12 +1,20 @@ package cy.agorise.crystalwallet.views; +import android.arch.lifecycle.LiveData; import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListAdapter; +import android.widget.TextView; import java.util.List; +import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; /** @@ -15,9 +23,29 @@ import cy.agorise.crystalwallet.models.CryptoCoinTransaction; public class TransactionListAdapter extends ArrayAdapter { + //List items; + public TransactionListAdapter(Context context, LiveData> items) { + super(context, 0, items.getValue()); - public TransactionListAdapter(Context context, int resource, List items) { - super(context, resource, items); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + CryptoCoinTransaction transaction = getItem(position); + + if (convertView == null) { + convertView = LayoutInflater.from(getContext()).inflate(R.layout.transaction_list_item, parent, false); + } + + TextView tvFrom = (TextView) convertView.findViewById(R.id.fromText); + TextView tvTo = (TextView) convertView.findViewById(R.id.toText); + TextView tvAmount = (TextView) convertView.findViewById(R.id.amountText); + + tvFrom.setText(transaction.getFrom()); + tvTo.setText(transaction.getTo()); + tvAmount.setText(transaction.getAmount()); + + return convertView; } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java index dd74755..3d70086 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java @@ -23,19 +23,17 @@ public class TransactionListView extends RelativeLayout { ListView listView; ListAdapter listAdapter; - TransactionListViewModel transactionListViewModel; public TransactionListView(Context context, AttributeSet attrs) { super(context, attrs); rootView = inflate(context, R.layout.transaction_list, this); listView = rootView.findViewById(R.id.transactionListView); + } - - - transactionListViewModel = ViewModelProviders.of(this).get(TransactionListViewModel.class); - - listAdapter = new TransactionListAdapter(context, getResources(), transactionDao.getAll()); + public void init(TransactionListViewModel transactionListViewModel){ + this.transactionListViewModel = transactionListViewModel; + listAdapter = new TransactionListAdapter(this.getContext(), transactionListViewModel.getTransactionList()); listView.setAdapter(listAdapter); } diff --git a/app/src/main/res/layout/activity_intro.xml b/app/src/main/res/layout/activity_intro.xml index 2fe817b..e7dbdb0 100644 --- a/app/src/main/res/layout/activity_intro.xml +++ b/app/src/main/res/layout/activity_intro.xml @@ -14,7 +14,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> + diff --git a/app/src/main/res/layout/transaction_list_item.xml b/app/src/main/res/layout/transaction_list_item.xml index f4818c7..b80a6a2 100644 --- a/app/src/main/res/layout/transaction_list_item.xml +++ b/app/src/main/res/layout/transaction_list_item.xml @@ -13,7 +13,7 @@ android:layout_alignParentStart="true" android:layout_alignParentTop="true"> - - -