From dfc751c5f86861841c386532aba2e9d09105434e Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Mon, 22 Jan 2018 22:18:15 -0400 Subject: [PATCH] - Added list of accounts (seeds) in "My Accounts" - Fixed some errors in Backup Activity --- app/src/main/AndroidManifest.xml | 2 ++ .../activities/AccountsActivity.java | 22 +++++++++++++++++++ .../activities/BackupSeedActivity.java | 5 +++-- .../views/AccountSeedViewHolder.java | 15 +++++++++++++ app/src/main/res/layout/activity_accounts.xml | 21 +++++++++++++----- 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ad92f17..52adab6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,6 +34,8 @@ + + diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java index 10e001e..e74f75b 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java @@ -1,16 +1,24 @@ package cy.agorise.crystalwallet.activities; import android.app.Activity; +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProviders; import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; +import java.util.List; + import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.viewmodels.AccountSeedListViewModel; +import cy.agorise.crystalwallet.views.AccountSeedListView; /** * Created by xd on 1/9/18. @@ -25,11 +33,25 @@ public class AccountsActivity extends AppCompatActivity { @BindView(R.id.tvClose) TextView tvClose; + @BindView(R.id.vAccountSeedList) + AccountSeedListView vAccountSeedList; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_accounts); ButterKnife.bind(this); + + AccountSeedListViewModel accountSeedListViewModel = ViewModelProviders.of(this).get(AccountSeedListViewModel.class); + LiveData> accountSeedData = accountSeedListViewModel.getAccountSeedList(); + vAccountSeedList.setData(null); + + accountSeedData.observe(this, new Observer>() { + @Override + public void onChanged(List accountSeeds) { + vAccountSeedList.setData(accountSeeds); + } + }); } @OnClick(R.id.tvSettings) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java index b0fceb5..2de4db6 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java @@ -46,6 +46,7 @@ public class BackupSeedActivity extends AppCompatActivity { if (seedId > -1) { accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class); + accountSeedViewModel.loadSeed(seedId); LiveData liveDataAccountSeed = accountSeedViewModel.getAccountSeed(); liveDataAccountSeed.observe(this, new Observer() { @Override @@ -60,8 +61,8 @@ public class BackupSeedActivity extends AppCompatActivity { } } - @OnClick(R.id.btnCancel) - public void cancel(){ + @OnClick(R.id.btnOk) + public void btnOkClick(){ this.finish(); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/AccountSeedViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/AccountSeedViewHolder.java index 1b0389c..47e1325 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/AccountSeedViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/AccountSeedViewHolder.java @@ -1,10 +1,14 @@ package cy.agorise.crystalwallet.views; +import android.content.Context; +import android.content.Intent; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.TextView; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.activities.BackupSeedActivity; +import cy.agorise.crystalwallet.activities.SettingsActivity; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; @@ -14,10 +18,12 @@ import cy.agorise.crystalwallet.models.CryptoCoinTransaction; public class AccountSeedViewHolder extends RecyclerView.ViewHolder { private TextView tvAccountSeedName; + private Context context; public AccountSeedViewHolder(View itemView) { super(itemView); tvAccountSeedName = (TextView) itemView.findViewById(R.id.tvAccountSeedName); + context = itemView.getContext(); } public void clear(){ @@ -29,6 +35,15 @@ public class AccountSeedViewHolder extends RecyclerView.ViewHolder { tvAccountSeedName.setText("loading..."); } else { tvAccountSeedName.setText(accountSeed.getName()); + + tvAccountSeedName.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(context, BackupSeedActivity.class); + intent.putExtra("SEED_ID", accountSeed.getId()); + context.startActivity(intent); + } + }); } } } diff --git a/app/src/main/res/layout/activity_accounts.xml b/app/src/main/res/layout/activity_accounts.xml index f2dc015..568b3ef 100644 --- a/app/src/main/res/layout/activity_accounts.xml +++ b/app/src/main/res/layout/activity_accounts.xml @@ -89,7 +89,7 @@ app:layout_constraintTop_toTopOf="@id/secondView" app:srcCompat="@drawable/ic_add_24dp" /> - + --> + + app:layout_constraintBottom_toBottomOf="@id/vAccountSeedList" + app:layout_constraintEnd_toEndOf="@id/vAccountSeedList" + app:layout_constraintStart_toStartOf="@id/vAccountSeedList" + app:layout_constraintTop_toTopOf="@id/vAccountSeedList" /> + app:layout_constraintTop_toBottomOf="@id/vAccountSeedList" />