From 81da660a2ee53ebe8cd0e8c36544ab07288a6a24 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 13 Sep 2017 12:12:22 -0400 Subject: [PATCH] - Creating the view for Transaction History --- app/build.gradle | 4 +- .../agorise/crystalwallet/IntroActivity.java | 3 +- .../crystalwallet/dao/CrystalDatabase.java | 6 ++- .../crystalwallet/dao/TransactionDao.java | 19 +++++++++ .../crystalwallet/enums/CryptoCoin.java | 41 +++++++++++++++++++ .../crystalwallet/enums/CryptoNet.java | 21 ++++++++++ .../models/CryptoCoinTransaction.java | 8 ++++ .../viewmodels/TransactionListViewModel.java | 31 ++++++++++++++ .../views/TransactionListView.java | 20 +++++++-- app/src/main/res/layout/activity_intro.xml | 5 +++ 10 files changed, 150 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/dao/TransactionDao.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/enums/CryptoNet.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/TransactionListViewModel.java diff --git a/app/build.gradle b/app/build.gradle index ac8ee2f..0923225 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,7 +34,9 @@ dependencies { compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' + compile "android.arch.lifecycle:runtime:1.0.0-alpha9" + compile "android.arch.lifecycle:extensions:1.0.0-alpha9" + annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha9" compile 'android.arch.persistence.room:runtime:1.0.0-alpha9'; - apt "android.arch.persistence.room:compiler:1.0.0-alpha9"; } diff --git a/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java b/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java index 4c833bc..053774b 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java @@ -1,9 +1,10 @@ package cy.agorise.crystalwallet; +import android.arch.lifecycle.LifecycleActivity; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; -public class IntroActivity extends AppCompatActivity { +public class IntroActivity extends LifecycleActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java index 7cd993f..6165a48 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java @@ -6,19 +6,21 @@ import android.arch.persistence.room.migration.Migration; import android.content.Context; import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoNetAccount; /** * Created by Henry Varona on 4/9/2017. */ -@Database(entities = {AccountSeed.class/*, CryptoNetAccount.class*/}, version = 2) +@Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class}, version = 2) public abstract class CrystalDatabase extends RoomDatabase { private static CrystalDatabase instance; public abstract AccountSeedDao accountSeedDao(); public abstract CryptoNetAccountDao cryptoNetAccountDao(); + public abstract TransactionDao transactionDao(); public static CrystalDatabase getAppDatabase(Context context) { if (instance == null) { @@ -43,7 +45,7 @@ public abstract class CrystalDatabase extends RoomDatabase { + "FOREIGN_KEY(seed_id) REFERENCES seed(id))"); database.execSQL("CREATE TABLE 'crypto_coin_transaction' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, " + "'account_id' INTEGER, " - + "'date' INT, 'is_input' INT," + + "'date' INT, 'is_input' INT, amount INT, crypto_coin TEXT, is_confirmed INT, " + "FOREIGN_KEY(account_id) REFERENCES crypto_net_account(id))"); } }; diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/TransactionDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/TransactionDao.java new file mode 100644 index 0000000..33f4898 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/TransactionDao.java @@ -0,0 +1,19 @@ +package cy.agorise.crystalwallet.dao; + +import android.arch.lifecycle.LiveData; +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import java.util.List; + +import cy.agorise.crystalwallet.models.CryptoCoinTransaction; + +/** + * Created by Henry Varona on 12/9/2017. + */ +@Dao +public interface TransactionDao { + + @Query("SELECT * FROM crypto_coin_transaction") + LiveData> getAll(); +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java new file mode 100644 index 0000000..4343dc7 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java @@ -0,0 +1,41 @@ +package cy.agorise.crystalwallet.enums; + +import java.io.Serializable; + +/** + * Created by Henry Varona on 12/9/2017. + */ + +public enum CryptoCoin implements Serializable { + BITCOIN(CryptoNet.BITCOIN,"BTC",8,6), + BITCOIN_TEST(CryptoNet.BITCOIN_TEST,"BTC",8,6), + LITECOIN(CryptoNet.LITECOIN,"LTC",8,6), + DASH(CryptoNet.DASH,"DASH",8,6), + DOGECOIN(CryptoNet.DOGECOIN,"DOGE",8,6), + BITSHARES(CryptoNet.BITSHARES,"BTS",8,6); + + protected CryptoNet cryptoNet; + protected String label; + protected int precision; + protected int confirmationsNeeded; + + CryptoCoin(CryptoNet cryptoNet, String label, int precision, int confirmationsNeeded){ + this.cryptoNet = cryptoNet; + this.label = label; + this.precision = precision; + this.confirmationsNeeded = confirmationsNeeded; + } + + public CryptoNet getCryptoNet(){ + return this.cryptoNet; + } + public String getLabel(){ + return this.label; + } + public int getPrecision(){ + return this.precision; + } + public int getConfirmationsNeeded(){ + return this.confirmationsNeeded; + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoNet.java b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoNet.java new file mode 100644 index 0000000..9872dd6 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoNet.java @@ -0,0 +1,21 @@ +package cy.agorise.crystalwallet.enums; + +import java.io.Serializable; + +/** + * Created by Henry Varona on 12/9/2017. + */ + +public enum CryptoNet implements Serializable { + BITCOIN("BITCOIN"), BITCOIN_TEST("BITCOIN(TEST)"), LITECOIN("LITECOIN"), DASH("DASH"), DOGECOIN("DOGECOIN"), BITSHARES("BITSHARES"); + + protected String label; + + CryptoNet(String label){ + this.label = label; + } + + public String getLabel(){ + return this.label; + } +} 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 3e5ff0d..0f1ca61 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java @@ -6,6 +6,8 @@ import android.arch.persistence.room.PrimaryKey; import java.util.Date; +import cy.agorise.crystalwallet.enums.CryptoCoin; + /** * Created by Henry Varona on 11/9/2017. */ @@ -23,6 +25,12 @@ public class CryptoCoinTransaction { protected boolean isInput; @ColumnInfo(name="account_id") protected int accountId; + @ColumnInfo(name="amount") + protected int amount; + @ColumnInfo(name="crypto_coin") + protected CryptoCoin coin; + @ColumnInfo(name="is_confirmed") + protected boolean isConfirmed; public int getAccountId() { return accountId; diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/TransactionListViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/TransactionListViewModel.java new file mode 100644 index 0000000..3d2b7b7 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/TransactionListViewModel.java @@ -0,0 +1,31 @@ +package cy.agorise.crystalwallet.viewmodels; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.ViewModel; +import android.content.Context; + +import java.util.List; + +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.CryptoCoinTransaction; +import cy.agorise.crystalwallet.views.TransactionListView; + +/** + * Created by Henry Varona on 12/9/2017. + */ + +public class TransactionListViewModel extends ViewModel { + + private LiveData> transactionList; + private CrystalDatabase db; + + public TransactionListViewModel(Context context){ + this.db = CrystalDatabase.getAppDatabase(context); + transactionList = this.db.transactionDao().getAll(); + } + + public LiveData> getTransactionList(){ + return this.transactionList; + } + +} 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 8fc8b5d..dd74755 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java @@ -1,5 +1,6 @@ package cy.agorise.crystalwallet.views; +import android.arch.lifecycle.ViewModelProviders; import android.content.Context; import android.util.AttributeSet; import android.view.View; @@ -8,6 +9,9 @@ import android.widget.ListView; import android.widget.RelativeLayout; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.dao.TransactionDao; +import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel; /** * Created by Henry Varona on 10/9/2017. @@ -16,15 +20,23 @@ import cy.agorise.crystalwallet.R; public class TransactionListView extends RelativeLayout { View rootView; - ListView list; + ListView listView; ListAdapter listAdapter; + + TransactionListViewModel transactionListViewModel; + public TransactionListView(Context context, AttributeSet attrs) { super(context, attrs); rootView = inflate(context, R.layout.transaction_list, this); - list = rootView.findViewById(R.id.transactionListView); - listAdapter = new TransactionListAdapter(); - list.setAdapter(listAdapter); + listView = rootView.findViewById(R.id.transactionListView); + + + + transactionListViewModel = ViewModelProviders.of(this).get(TransactionListViewModel.class); + + listAdapter = new TransactionListAdapter(context, getResources(), transactionDao.getAll()); + listView.setAdapter(listAdapter); } diff --git a/app/src/main/res/layout/activity_intro.xml b/app/src/main/res/layout/activity_intro.xml index 887d99c..2fe817b 100644 --- a/app/src/main/res/layout/activity_intro.xml +++ b/app/src/main/res/layout/activity_intro.xml @@ -14,4 +14,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> + + +