- Added Backup Seed Activity to show the mnemonic for the recently created seed

This commit is contained in:
Javier Varona 2018-01-12 21:01:38 -04:00
parent 76b5a6885d
commit f65e330d9b
4 changed files with 129 additions and 2 deletions

View file

@ -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<AccountSeed> liveDataAccountSeed = accountSeedViewModel.getAccountSeed();
liveDataAccountSeed.observe(this, new Observer<AccountSeed>() {
@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();
}
}

View file

@ -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();
}
}
});

View file

@ -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);
}

View file

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/tvMnemonicTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="10dp"
android:text="@string/seed_words"
android:textStyle="bold" />
<TextView
android:id="@+id/tvMnemonic"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:background="@drawable/edittext_bg"
android:inputType="number"
android:maxLines="1"
android:textColor="@color/black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@color/pink"
android:text="@string/ok"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>