From 213cc07c804e52e48eb3e8791e7a3c12643109a5 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Sun, 5 Nov 2017 20:38:37 -0400 Subject: [PATCH] - Change intro to send the user to import seed when there isn't one - Now the equivalent value shows in the balance view --- .../activities/IntroActivity.java | 3 +- .../dao/CryptoCurrencyEquivalenceDao.java | 4 +++ ...ryptoCurrencyEquivalenceListViewModel.java | 34 +++++++++++++++++++ .../CryptoCurrencyEquivalenceViewModel.java | 33 ++++++++++++++++++ .../views/CryptoCoinBalanceListView.java | 2 +- .../views/CryptoCoinBalanceViewHolder.java | 26 ++++++++++++++ .../views/CryptoNetBalanceViewHolder.java | 2 ++ .../layout/crypto_coin_balance_list_item.xml | 13 ++++++- 8 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCurrencyEquivalenceListViewModel.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCurrencyEquivalenceViewModel.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java index e268e7a..a2b5fc5 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java @@ -47,7 +47,8 @@ public class IntroActivity extends AppCompatActivity { if (accountSeedListViewModel.accountSeedsCount() == 0){ //If the user doesn't have any seeds created, then //send the user to create/import an account - Intent intent = new Intent(this, AccountSeedsManagementActivity.class); + //Intent intent = new Intent(this, AccountSeedsManagementActivity.class); + Intent intent = new Intent(this, ImportSeedActivity.class); startActivity(intent); } else { Intent intent = new Intent(this, BoardActivity.class); diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyEquivalenceDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyEquivalenceDao.java index 7f5db5c..c1a24ec 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyEquivalenceDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyEquivalenceDao.java @@ -1,5 +1,6 @@ package cy.agorise.crystalwallet.dao; +import android.arch.lifecycle.LiveData; import android.arch.persistence.room.Dao; import android.arch.persistence.room.Insert; import android.arch.persistence.room.OnConflictStrategy; @@ -23,6 +24,9 @@ public interface CryptoCurrencyEquivalenceDao { @Query("SELECT * FROM crypto_currency_equivalence WHERE id = :id") CryptoCurrencyEquivalence getById(long id); + @Query("SELECT * FROM crypto_currency_equivalence WHERE from_crypto_currency_id = :fromCurrencyId AND to_crypto_currency_id = :toCurrencyId") + LiveData getByFromTo(long fromCurrencyId, long toCurrencyId); + @Insert(onConflict = OnConflictStrategy.REPLACE) public long[] insertCryptoCurrencyEquivalence(CryptoCurrencyEquivalence... currenciesEquivalences); diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCurrencyEquivalenceListViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCurrencyEquivalenceListViewModel.java new file mode 100644 index 0000000..81a7a96 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCurrencyEquivalenceListViewModel.java @@ -0,0 +1,34 @@ +package cy.agorise.crystalwallet.viewmodels; + +import android.app.Application; +import android.arch.lifecycle.AndroidViewModel; +import android.arch.lifecycle.LiveData; + +import java.util.List; + +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; +import cy.agorise.crystalwallet.models.CryptoNetBalance; + +/** + * Created by Henry Varona on 27/9/2017. + */ + +public class CryptoCurrencyEquivalenceListViewModel extends AndroidViewModel { + + private List cryptoCurrencyEquivalenceList; + private CrystalDatabase db; + + public CryptoCurrencyEquivalenceListViewModel(Application application) { + super(application); + this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext()); + } + + public void init(){ + this.cryptoCurrencyEquivalenceList = this.db.cryptoCurrencyEquivalenceDao().getAll(); + } + + public List getCryptoCurrencyEquivalenceList(){ + return this.cryptoCurrencyEquivalenceList; + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCurrencyEquivalenceViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCurrencyEquivalenceViewModel.java new file mode 100644 index 0000000..2261b0e --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCurrencyEquivalenceViewModel.java @@ -0,0 +1,33 @@ +package cy.agorise.crystalwallet.viewmodels; + +import android.app.Application; +import android.arch.lifecycle.AndroidViewModel; +import android.arch.lifecycle.LiveData; + +import java.util.List; + +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; + +/** + * Created by Henry Varona on 4/11/2017. + */ + +public class CryptoCurrencyEquivalenceViewModel extends AndroidViewModel { + + private LiveData cryptoCurrencyEquivalence; + private CrystalDatabase db; + + public CryptoCurrencyEquivalenceViewModel(Application application) { + super(application); + this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext()); + } + + public void init(long fromCurrency, long toCurrency){ + this.cryptoCurrencyEquivalence = this.db.cryptoCurrencyEquivalenceDao().getByFromTo(fromCurrency,toCurrency); + } + + public LiveData getCryptoCurrencyEquivalence(){ + return this.cryptoCurrencyEquivalence; + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListView.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListView.java index bd03126..a8aff6c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListView.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListView.java @@ -51,7 +51,7 @@ public class CryptoCoinBalanceListView extends RelativeLayout { public void init(){ rootView = mInflater.inflate(R.layout.crypto_coin_balance_list, this, true); - this.listView = (RecyclerView) rootView.findViewById(R.id.cryptoCoinBalanceListView); + this.listView = (RecyclerView) rootView.findViewById(R.id.cryptoCoinBalanceListView); final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext()); this.listView.setLayoutManager(linearLayoutManager); diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java index 7783260..1bd1e4f 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java @@ -1,6 +1,10 @@ package cy.agorise.crystalwallet.views; +import android.arch.lifecycle.LifecycleOwner; +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.Observer; import android.content.Context; +import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.TextView; @@ -10,6 +14,7 @@ import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCurrency; +import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; /** * Created by Henry Varona on 17/9/2017. @@ -18,12 +23,14 @@ import cy.agorise.crystalwallet.models.CryptoCurrency; public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder { private TextView cryptoCoinName; private TextView cryptoCoinBalance; + private TextView cryptoCoinBalanceEquivalence; private Context context; public CryptoCoinBalanceViewHolder(View itemView) { super(itemView); cryptoCoinName = (TextView) itemView.findViewById(R.id.tvCryptoCoinName); cryptoCoinBalance = (TextView) itemView.findViewById(R.id.tvCryptoCoinBalanceAmount); + cryptoCoinBalanceEquivalence = (TextView) itemView.findViewById(R.id.tvCryptoCoinBalanceEquivalence); this.context = itemView.getContext(); } @@ -31,17 +38,36 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder { public void clear(){ cryptoCoinName.setText("loading..."); cryptoCoinBalance.setText(""); + cryptoCoinBalanceEquivalence.setText(""); } public void bindTo(final CryptoCoinBalance balance/*, final OnTransactionClickListener listener*/) { if (balance == null){ cryptoCoinName.setText("loading..."); cryptoCoinBalance.setText(""); + cryptoCoinBalanceEquivalence.setText(""); } else { CryptoCurrency currency = CrystalDatabase.getAppDatabase(this.context).cryptoCurrencyDao().getById(balance.getCryptoCurrencyId()); + CryptoCurrency currencyBitEur = CrystalDatabase.getAppDatabase(this.context).cryptoCurrencyDao().getByName("EUR"); + + LiveData currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(this.context) + .cryptoCurrencyEquivalenceDao().getByFromTo( + currency.getId(), + currencyBitEur.getId() + ); cryptoCoinName.setText(currency.getName()); cryptoCoinBalance.setText(""+balance.getBalance()); + + currencyEquivalenceLiveData.observe((LifecycleOwner) this.context, new Observer() { + @Override + public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) { + if (cryptoCurrencyEquivalence != null){ + CryptoCurrency toCurrency = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(cryptoCurrencyEquivalence.getToCurrencyId()); + cryptoCoinBalanceEquivalence.setText(cryptoCurrencyEquivalence.getValue()+" "+toCurrency.getName()); + } + } + }); } } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java index 75444ee..13836a1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java @@ -24,6 +24,7 @@ import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.activities.SendTransactionActivity; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; +import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; import cy.agorise.crystalwallet.models.CryptoNetBalance; import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel; @@ -99,6 +100,7 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder { CryptoCoinBalanceListViewModel cryptoCoinBalanceListViewModel = ViewModelProviders.of(this.fragment).get(CryptoCoinBalanceListViewModel.class); cryptoCoinBalanceListViewModel.init(balance.getAccountId()); LiveData> cryptoCoinBalanceData = cryptoCoinBalanceListViewModel.getCryptoCoinBalanceList(); + cryptoCoinBalanceListView.setData(null); cryptoCoinBalanceData.observe((LifecycleOwner)this.itemView.getContext(), new Observer>() { diff --git a/app/src/main/res/layout/crypto_coin_balance_list_item.xml b/app/src/main/res/layout/crypto_coin_balance_list_item.xml index 5321d1d..7f8bccc 100644 --- a/app/src/main/res/layout/crypto_coin_balance_list_item.xml +++ b/app/src/main/res/layout/crypto_coin_balance_list_item.xml @@ -27,6 +27,17 @@ android:layout_height="wrap_content" android:layout_alignParentRight="true" android:ems="10" - android:text="0.00000000" /> + android:text="0.00000000" + android:textAlignment="textEnd" /> + + \ No newline at end of file