From f65e330d9b0cc851872a244ce431b5a3dacc6a5f Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Fri, 12 Jan 2018 21:01:38 -0400 Subject: [PATCH] - Added Backup Seed Activity to show the mnemonic for the recently created seed --- .../activities/BackupSeedActivity.java | 67 +++++++++++++++++++ .../activities/CreateSeedActivity.java | 10 ++- .../viewmodels/AccountSeedViewModel.java | 2 +- app/src/main/res/layout/backup_seed.xml | 52 ++++++++++++++ 4 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java create mode 100644 app/src/main/res/layout/backup_seed.xml diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java new file mode 100644 index 0000000..b0fceb5 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java @@ -0,0 +1,67 @@ +package cy.agorise.crystalwallet.activities; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProviders; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.text.Editable; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.OnTextChanged; +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.cryptonetinforequests.ValidateCreateBitsharesAccountRequest; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel; +import cy.agorise.crystalwallet.viewmodels.validators.CreateSeedValidator; +import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; + +public class BackupSeedActivity extends AppCompatActivity { + + AccountSeedViewModel accountSeedViewModel; + + @BindView(R.id.tvMnemonic) + TextView tvMnemonic; + @BindView(R.id.btnOk) + Button btnOk; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.backup_seed); + ButterKnife.bind(this); + + long seedId = getIntent().getLongExtra("SEED_ID",-1); + + if (seedId > -1) { + accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class); + LiveData liveDataAccountSeed = accountSeedViewModel.getAccountSeed(); + liveDataAccountSeed.observe(this, new Observer() { + @Override + public void onChanged(@Nullable AccountSeed accountSeed) { + tvMnemonic.setText(accountSeed.getMasterSeed()); + } + }); + accountSeedViewModel.loadSeed(seedId); + + } else { + finish(); + } + } + + @OnClick(R.id.btnCancel) + public void cancel(){ + this.finish(); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java index 40953e3..3d31494 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java @@ -1,6 +1,7 @@ package cy.agorise.crystalwallet.activities; import android.arch.lifecycle.ViewModelProviders; +import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; @@ -21,6 +22,7 @@ import cy.agorise.crystalwallet.cryptonetinforequests.ValidateCreateBitsharesAcc import cy.agorise.crystalwallet.enums.SeedType; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.GrapheneAccount; import cy.agorise.crystalwallet.models.GrapheneAccountInfo; import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel; import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountViewModel; @@ -120,6 +122,7 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator CreateSeedActivity.this.runOnUiThread(new Runnable() { @Override public void run() { + processDialog.setCancelable(false); processDialog.show(); processDialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); } @@ -131,10 +134,15 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator processDialog.dismiss(); if (request.getAccount() != null){ - finish(); + GrapheneAccount accountSeed = request.getAccount(); + Intent intent = new Intent(getApplicationContext(), BackupSeedActivity.class); + intent.putExtra("SEED_ID",accountSeed.getId()); + startActivity(intent); } else { createSeedValidator.validate(); } + + } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/AccountSeedViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/AccountSeedViewModel.java index af9e253..ee71edf 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/AccountSeedViewModel.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/AccountSeedViewModel.java @@ -29,7 +29,7 @@ public class AccountSeedViewModel extends AndroidViewModel { this.app = application; } - public void loadSeed(int seedId){ + public void loadSeed(long seedId){ this.accountSeed = this.db.accountSeedDao().findByIdLiveData(seedId); } diff --git a/app/src/main/res/layout/backup_seed.xml b/app/src/main/res/layout/backup_seed.xml new file mode 100644 index 0000000..9166b1c --- /dev/null +++ b/app/src/main/res/layout/backup_seed.xml @@ -0,0 +1,52 @@ + + + + + + + + + +