From c9a23341a0eeea37be2d397e1d394cf88a539e14 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 13 Sep 2017 22:09:58 -0400 Subject: [PATCH] - Fixing the views (in progress...) --- .../agorise/crystalwallet/IntroActivity.java | 4 +- .../crystalwallet/dao/CrystalDatabase.java | 3 + .../dao/converters/Converters.java | 68 +++++++++++++++++++ .../models/CryptoCoinTransaction.java | 17 +++++ 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/dao/converters/Converters.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java b/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java index 79826ad..5024117 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java @@ -1,6 +1,8 @@ package cy.agorise.crystalwallet; import android.arch.lifecycle.LifecycleActivity; +import android.arch.lifecycle.ViewModelProvider; +import android.arch.lifecycle.ViewModelProviders; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; @@ -17,7 +19,7 @@ public class IntroActivity extends LifecycleActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_intro); - transactionListViewModel = new TransactionListViewModel(getApplicationContext()); + transactionListViewModel = ViewModelProviders.of(this).get(TransactionListViewModel.class); transactionListView = this.findViewById(R.id.transaction_list); transactionListView.init(transactionListViewModel); 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 15803ea..f43c374 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java @@ -4,9 +4,11 @@ import android.arch.persistence.db.SupportSQLiteDatabase; import android.arch.persistence.room.Database; import android.arch.persistence.room.Room; import android.arch.persistence.room.RoomDatabase; +import android.arch.persistence.room.TypeConverters; import android.arch.persistence.room.migration.Migration; import android.content.Context; +import cy.agorise.crystalwallet.dao.converters.Converters; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoNetAccount; @@ -17,6 +19,7 @@ import cy.agorise.crystalwallet.models.CryptoNetAccount; */ @Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class}, version = 2) +@TypeConverters({Converters.class}) public abstract class CrystalDatabase extends RoomDatabase { private static CrystalDatabase instance; diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/converters/Converters.java b/app/src/main/java/cy/agorise/crystalwallet/dao/converters/Converters.java new file mode 100644 index 0000000..2234b47 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/converters/Converters.java @@ -0,0 +1,68 @@ +package cy.agorise.crystalwallet.dao.converters; + +import android.arch.persistence.room.TypeConverter; + +import java.util.Date; + +import cy.agorise.crystalwallet.enums.CryptoCoin; +import cy.agorise.crystalwallet.models.CryptoNetAccount; + +import static cy.agorise.crystalwallet.R.string.account; + +/** + * Created by Henry Varona on 13/9/2017. + */ + +public class Converters { + @TypeConverter + public Date fromTimestamp(Long value) { + return value == null ? null : new Date(value); + } + + @TypeConverter + public Long dateToTimestamp(Date date) { + if (date == null) { + return null; + } else { + return date.getTime(); + } + } + + @TypeConverter + public int cryptoNetAccountToId(CryptoNetAccount account) { + if (account == null) { + return -1; + } else { + return account.getId(); + } + } + + @TypeConverter + public CryptoNetAccount fromCryptoNetAccountId(int value) { + if (value == -1){ + return null; + } else { + CryptoNetAccount account = new CryptoNetAccount(); + account.setId(value); + return account; + } + } + + @TypeConverter + public String cryptoCoinToName(CryptoCoin coin) { + if (coin == null) { + return ""; + } else { + return coin.name(); + } + } + + @TypeConverter + public CryptoCoin nameToCryptoCoin(String value) { + if (value.equals("")){ + return null; + } else { + return CryptoCoin.valueOf(value); + } + } +} 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 58ae2dc..f71e894 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java @@ -47,6 +47,23 @@ public class CryptoCoinTransaction { */ @ColumnInfo(name="amount") protected int amount; + + public CryptoCoin getCoin() { + return coin; + } + + public void setCoin(CryptoCoin coin) { + this.coin = coin; + } + + public boolean isConfirmed() { + return isConfirmed; + } + + public void setConfirmed(boolean confirmed) { + isConfirmed = confirmed; + } + /** * The crypto Coin associated with this transaction */