Adds import account link to create account view

pull/2/head
Marat Subkhankulov 7 years ago
parent a178ebe38f
commit 5ecc4ec360
  1. 17
      app/src/main/java/com/wallet/crypto/trust/controller/Controller.java
  2. 2
      app/src/main/java/com/wallet/crypto/trust/controller/OnTaskCompleted.java
  3. 23
      app/src/main/java/com/wallet/crypto/trust/controller/TaskResult.java
  4. 7
      app/src/main/java/com/wallet/crypto/trust/controller/TaskStatus.java
  5. 32
      app/src/main/java/com/wallet/crypto/trust/views/AccountListActivity.java
  6. 10
      app/src/main/java/com/wallet/crypto/trust/views/CreateAccountActivity.java
  7. 10
      app/src/main/java/com/wallet/crypto/trust/views/ImportAccountActivity.java
  8. 42
      app/src/main/java/com/wallet/crypto/trust/views/TransactionListActivity.java
  9. 16
      app/src/main/res/layout/activity_create_account.xml
  10. 19
      app/src/main/res/menu/navigation.xml
  11. 2
      app/src/main/res/values/strings.xml

@ -149,7 +149,7 @@ public class Controller {
// Get transactions
new GetTransactionsTask(mAccounts, new OnTaskCompleted() {
@Override
public void onTaskCompleted() {
public void onTaskCompleted(TaskResult result) {
Log.d(TAG, "Finished loading transactions");
// ... and then get balances
@ -182,6 +182,11 @@ public class Controller {
context.startActivity(intent);
}
public void navigateToAccountList() {
Intent intent = new Intent(mAppContext, AccountListActivity.class);
mAppContext.startActivity(intent);
}
public void navigateToAccountList(Context context) {
Intent intent = new Intent(context, AccountListActivity.class);
context.startActivity(intent);
@ -209,12 +214,13 @@ public class Controller {
public void clickCreateAccount(Activity activity, String name, String password) throws Exception {
Log.d(TAG, String.format("Create account '%s' with pwd '%s", name, password));
boolean firstAccount = mAccounts.size() == 0;
VMAccount account = createAccount(password);
mAccounts.add(account);
mTransactions.put(account.getAddress(), new ArrayList<ESTransaction>());
if (mEtherStore.getAccounts().size() == 0) {
if (firstAccount) {
setCurrentAddress(account.getAddress());
}
@ -368,7 +374,7 @@ public class Controller {
for (VMAccount a: mAccounts) {
getBalance(a);
}
mListener.onTaskCompleted();
mListener.onTaskCompleted(new TaskResult(TaskStatus.SUCCESS, ""));
return null;
}
}
@ -390,10 +396,11 @@ public class Controller {
Account account = mEtherStore.importKeyStore(keystoreJson, password);
loadAccounts();
Log.d("INFO", "Imported account: " + account.getAddress().getHex());
listener.onTaskCompleted(new TaskResult(TaskStatus.SUCCESS, "Imported wallet."));
} catch (Exception e) {
Log.d("ERROR", e.toString());
listener.onTaskCompleted(new TaskResult(TaskStatus.FAILURE, "Failed to import wallet: '%s'".format(e.getMessage())));
}
listener.onTaskCompleted();
return null;
}
}
@ -536,7 +543,7 @@ public class Controller {
for (VMAccount a : mAccounts) {
fetchTransactionsForAddress(a);
}
mListener.onTaskCompleted();
mListener.onTaskCompleted(new TaskResult(TaskStatus.SUCCESS, "Fetched transactions for all accounts."));
return null;
}
}

@ -5,6 +5,6 @@ package com.wallet.crypto.trust.controller;
*/
public interface OnTaskCompleted {
void onTaskCompleted();
void onTaskCompleted(TaskResult result);
}

@ -0,0 +1,23 @@
package com.wallet.crypto.trust.controller;
/**
* Created by marat on 10/15/17.
*/
public class TaskResult {
private TaskStatus status;
private String message;
public TaskResult(TaskStatus status, String message) {
this.status = status;
this.message = message;
}
public TaskStatus getStatus() {
return status;
}
public String getMessage() {
return message;
}
}

@ -0,0 +1,7 @@
package com.wallet.crypto.trust.controller;
/**
* Created by marat on 10/15/17.
*/
public enum TaskStatus { SUCCESS, FAILURE }

@ -2,6 +2,7 @@ package com.wallet.crypto.trust.views;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
@ -38,6 +39,24 @@ public class AccountListActivity extends AppCompatActivity implements DeleteAcco
*/
private boolean mTwoPane;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_import:
mController.navigateToImportAccount(AccountListActivity.this);
break;
case R.id.action_create:
mController.navigateToCreateAccount(AccountListActivity.this);
break;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -54,6 +73,9 @@ public class AccountListActivity extends AppCompatActivity implements DeleteAcco
mController = Controller.get();
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
mRecyclerView = findViewById(R.id.account_list);
assert mRecyclerView != null;
setupRecyclerView((RecyclerView) mRecyclerView);
@ -78,6 +100,10 @@ public class AccountListActivity extends AppCompatActivity implements DeleteAcco
Toast.makeText(AccountListActivity.this, "Delete dialog callback " + password, Toast.LENGTH_SHORT).show();
try {
mController.deleteAccount(address, password);
if (mController.getCurrentAccount() == null) {
finish(); // Don't show account list if there are no accounts,
// go to main view which will ask to create a new account
}
setupRecyclerView((RecyclerView) mRecyclerView);
} catch (Exception e) {
Log.e(TAG, e.toString());
@ -88,12 +114,6 @@ public class AccountListActivity extends AppCompatActivity implements DeleteAcco
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_import:
mController.navigateToImportAccount(this);
break;
case R.id.action_create:
mController.navigateToCreateAccount(this);
break;
case android.R.id.home:
finish();
break;

@ -3,6 +3,7 @@ package com.wallet.crypto.trust.views;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
@ -66,6 +67,7 @@ public class CreateAccountActivity extends AppCompatActivity implements LoaderCa
private EditText mConfirmPassword;
private View mProgressView;
private View mLoginFormView;
private Button mImportButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -113,6 +115,14 @@ public class CreateAccountActivity extends AppCompatActivity implements LoaderCa
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
mImportButton = findViewById(R.id.import_account_button);
mImportButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mController.navigateToImportAccount(CreateAccountActivity.this);
}
});
}
private void populateAutoComplete() {

@ -8,10 +8,13 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.wallet.crypto.trust.R;
import com.wallet.crypto.trust.controller.Controller;
import com.wallet.crypto.trust.controller.OnTaskCompleted;
import com.wallet.crypto.trust.controller.TaskResult;
import com.wallet.crypto.trust.controller.TaskStatus;
public class ImportAccountActivity extends AppCompatActivity {
@ -46,11 +49,16 @@ public class ImportAccountActivity extends AppCompatActivity {
mPassword.getText().toString(),
new OnTaskCompleted() {
@Override
public void onTaskCompleted() {
public void onTaskCompleted(final TaskResult result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (result.getStatus() == TaskStatus.SUCCESS) {
ImportAccountActivity.this.finish();
mController.navigateToAccountList();
} else {
Toast.makeText(ImportAccountActivity.this, result.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}

@ -7,6 +7,7 @@ import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
@ -24,6 +25,7 @@ import android.widget.TextView;
import com.wallet.crypto.trust.R;
import com.wallet.crypto.trust.controller.Controller;
import com.wallet.crypto.trust.controller.OnTaskCompleted;
import com.wallet.crypto.trust.controller.TaskResult;
import com.wallet.crypto.trust.model.ESTransaction;
import com.wallet.crypto.trust.model.VMAccount;
@ -37,7 +39,7 @@ import java.util.List;
* item details. On tablets, the activity presents the list of items and
* item details side-by-side using two vertical panes.
*/
public class TransactionListActivity extends AppCompatActivity implements OnTaskCompleted {
public class TransactionListActivity extends AppCompatActivity {
/**
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
@ -49,6 +51,24 @@ public class TransactionListActivity extends AppCompatActivity implements OnTask
private SwipeRefreshLayout mSwipeRefreshLayout;
private RecyclerView mRecyclerView;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_receive:
mController.navigateToReceive(TransactionListActivity.this);
break;
case R.id.navigation_send:
mController.navigateToSend(TransactionListActivity.this);
break;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -59,6 +79,9 @@ public class TransactionListActivity extends AppCompatActivity implements OnTask
mController = Controller.get();
mController.init(this);
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
mRecyclerView = (RecyclerView) findViewById(R.id.item_list);
assert mRecyclerView != null;
setupRecyclerView(mRecyclerView);
@ -81,7 +104,7 @@ public class TransactionListActivity extends AppCompatActivity implements OnTask
private void fetchModelsAndReinit() {
mController.loadViewModels(new OnTaskCompleted() {
@Override
public void onTaskCompleted() {
public void onTaskCompleted(TaskResult result) {
asyncInit();
}
});
@ -93,9 +116,6 @@ public class TransactionListActivity extends AppCompatActivity implements OnTask
mAddress = account.getAddress();
Log.d(TAG, "Address: %s, Balance: %s".format(mAddress, account.getBalance().toString()));
} else {
//Intent intent = new Intent(this, CreateAccountActivity.class);
//this.startActivity(intent);
mAddress ="0xDEADBEEF";
account = new VMAccount(mAddress, "0");
}
@ -136,7 +156,7 @@ public class TransactionListActivity extends AppCompatActivity implements OnTask
SharedPreferences.Editor e = getPrefs.edit();
// Edit preference to make it false because we don't want this to run again
e.putBoolean("firstStart", true);
e.putBoolean("firstStart", false);
// Apply changes
e.apply();
@ -165,7 +185,12 @@ public class TransactionListActivity extends AppCompatActivity implements OnTask
@Override
public void onResume() {
super.onResume();
init();
if (mController.getCurrentAccount() == null) {
mController.navigateToCreateAccount(this);
}
}
@Override
@ -202,11 +227,6 @@ public class TransactionListActivity extends AppCompatActivity implements OnTask
recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(txns));
}
@Override
public void onTaskCompleted() {
// Populate transactions
}
public class SimpleItemRecyclerViewAdapter
extends RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {

@ -75,6 +75,22 @@
android:text="@string/action_sign_in"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Already have a wallet?"
android:gravity="left"
/>
<Button
android:id="@+id/import_account_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/action_import"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_home" />
<item
android:id="@+id/navigation_dashboard"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_dashboard" />
<item
android:id="@+id/navigation_notifications"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/title_notifications" />
</menu>

@ -8,7 +8,7 @@
<string name="title_account">Accounts</string>
<string name="title_item_detail">Item Detail</string>
<string name="title_activity_main2">Main2Activity</string>
<string name="title_activity_create_account">Create Account</string>
<string name="title_activity_create_account">New Wallet</string>
<!-- Strings related to account creation -->
<string name="prompt_email">Account name</string>

Loading…
Cancel
Save