From c9ae39508f50136265296e5669737f0515ac08d7 Mon Sep 17 00:00:00 2001
From: m2049r <30435443+m2049r@users.noreply.github.com>
Date: Thu, 17 Aug 2017 22:35:25 +0200
Subject: [PATCH] details view works mostly (seed) need to prevent opening
wallet while preparing details new wallets sont store the cache ?! (except
watch only)
---
.../com/m2049r/xmrwallet/LoginActivity.java | 67 +++++++++++++++++--
.../com/m2049r/xmrwallet/LoginFragment.java | 40 +++++++++++
app/src/main/res/values/strings.xml | 1 +
3 files changed, 102 insertions(+), 6 deletions(-)
diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
index 1ddc8df8..57a06f82 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
@@ -79,16 +79,37 @@ public class LoginActivity extends AppCompatActivity
// now it's getting real, check if wallet exists
String walletPath = Helper.getWalletPath(this, walletName);
if (WalletManager.getInstance().walletExists(walletPath)) {
- promptPassword(walletName);
+ promptPassword(walletName, new PasswordAction() {
+ @Override
+ public void action(String walletName, String password) {
+ startWallet(walletName, password);
+ }
+ });
} else { // this cannot really happen as we prefilter choices
Toast.makeText(this, getString(R.string.bad_wallet), Toast.LENGTH_SHORT).show();
}
}
}
+ @Override
+ public void onWalletDetails(final String walletName) {
+ Log.d(TAG, "details for wallet ." + walletName + ".");
+ String walletPath = Helper.getWalletPath(this, walletName);
+ if (WalletManager.getInstance().walletExists(walletPath)) {
+ promptPassword(walletName, new PasswordAction() {
+ @Override
+ public void action(String walletName, String password) {
+ startDetails(walletName, password);
+ }
+ });
+ } else { // this cannot really happen as we prefilter choices
+ Toast.makeText(this, getString(R.string.bad_wallet), Toast.LENGTH_SHORT).show();
+ }
+ }
+
AlertDialog passwordDialog = null; // for preventing multiple clicks in wallet list
- void promptPassword(final String wallet) {
+ void promptPassword(final String wallet, final PasswordAction action) {
if (passwordDialog != null) return; // we are already asking for password
Context context = LoginActivity.this;
LayoutInflater li = LayoutInflater.from(context);
@@ -110,7 +131,7 @@ public class LoginActivity extends AppCompatActivity
public void onClick(DialogInterface dialog, int id) {
Helper.hideKeyboardAlways(LoginActivity.this);
String pass = etPassword.getText().toString();
- processPasswordEntry(wallet, pass);
+ processPasswordEntry(wallet, pass, action);
passwordDialog = null;
}
})
@@ -133,7 +154,7 @@ public class LoginActivity extends AppCompatActivity
Helper.hideKeyboardAlways(LoginActivity.this);
String pass = etPassword.getText().toString();
passwordDialog.cancel();
- processPasswordEntry(wallet, pass);
+ processPasswordEntry(wallet, pass, action);
passwordDialog = null;
return false;
}
@@ -151,9 +172,13 @@ public class LoginActivity extends AppCompatActivity
return WalletManager.getInstance().verifyWalletPassword(walletPath, password, true);
}
- private void processPasswordEntry(String walletName, String pass) {
+ interface PasswordAction {
+ void action(String walletName, String password);
+ }
+
+ private void processPasswordEntry(String walletName, String pass, PasswordAction action) {
if (checkWalletPassword(walletName, pass)) {
- startWallet(walletName, pass);
+ action.action(walletName, pass);
} else {
Toast.makeText(this, getString(R.string.bad_password), Toast.LENGTH_SHORT).show();
}
@@ -201,6 +226,34 @@ public class LoginActivity extends AppCompatActivity
startActivity(intent);
}
+ void startDetails(final String walletName, final String password) {
+ Log.d(TAG, "startDetails()");
+ new Thread(null,
+ new Runnable() {
+ @Override
+ public void run() {
+ String path = Helper.getWalletPath(getApplicationContext(), walletName);
+ Wallet wallet = WalletManager.getInstance().openWallet(path, password);
+ final String seed = wallet.getSeed();
+ final String address = wallet.getAddress();
+ final String view = wallet.getSecretViewKey();
+ final String spend = wallet.isWatchOnly() ? "" : "not available - use seed for recovery";
+ wallet.close();
+ Bundle b = new Bundle();
+ b.putString("name", walletName);
+ b.putString("password", password);
+ b.putString("seed", seed);
+ b.putString("address", address);
+ b.putString("viewkey", view);
+ b.putString("spendkey", spend);
+ b.putString("view", GenerateReviewFragment.VIEW_DETAILS);
+ startReviewFragment(b);
+ }
+ }
+ , "DetailsWallet", MoneroHandlerThread.THREAD_STACK_SIZE).start();
+ }
+
+
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
Log.d(TAG, "onRequestPermissionsResult()");
@@ -296,6 +349,7 @@ public class LoginActivity extends AppCompatActivity
final String spend = newWallet.isWatchOnly() ? "" : "not available - use seed for recovery";
newWallet.close();
Log.d(TAG, "Created " + address);
+ //TODO: is runOnUiThread needed?
runOnUiThread(new Runnable() {
public void run() {
Bundle b = new Bundle();
@@ -305,6 +359,7 @@ public class LoginActivity extends AppCompatActivity
b.putString("address", address);
b.putString("viewkey", view);
b.putString("spendkey", spend);
+ b.putString("view", GenerateReviewFragment.VIEW_ACCEPT);
startReviewFragment(b);
}
});
diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java
index 50e06272..20d5de2d 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java
@@ -79,6 +79,8 @@ public class LoginFragment extends Fragment {
void onWalletSelected(final String wallet);
+ void onWalletDetails(final String wallet);
+
void setTitle(String title);
}
@@ -190,6 +192,44 @@ public class LoginFragment extends Fragment {
}
});
+ listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
+ EditText tvDaemonAddress = (EditText) getView().findViewById(R.id.etDaemonAddress);
+ if (tvDaemonAddress.getText().toString().length() == 0) {
+ Toast.makeText(getActivity(), getString(R.string.prompt_daemon_missing), Toast.LENGTH_SHORT).show();
+ tvDaemonAddress.requestFocus();
+ Helper.showKeyboard(getActivity());
+ return true;
+ }
+
+ String itemValue = (String) listView.getItemAtPosition(position);
+
+ if (itemValue.length() <= (WALLETNAME_PREAMBLE_LENGTH)) {
+ Toast.makeText(getActivity(), getString(R.string.panic), Toast.LENGTH_LONG).show();
+ return true;
+ }
+
+ String x = isMainNet() ? "4-" : "9A-";
+ if (x.indexOf(itemValue.charAt(1)) < 0) {
+ Toast.makeText(getActivity(), getString(R.string.prompt_wrong_net), Toast.LENGTH_LONG).show();
+ return true;
+ }
+
+ if (!checkAndSetWalletDaemon(getDaemon(), !isMainNet())) {
+ Toast.makeText(getActivity(), getString(R.string.warn_daemon_unavailable), Toast.LENGTH_SHORT).show();
+ return true;
+ }
+
+ // looking good
+ savePrefs(false);
+
+ String wallet = itemValue.substring(WALLETNAME_PREAMBLE_LENGTH);
+ if (itemValue.charAt(1) == '-') wallet = ':' + wallet;
+ activityCallback.onWalletDetails(wallet);
+ return true;
+ }
+ });
activityCallback.setTitle(getString(R.string.app_name) + " " +
getString(isMainNet() ? R.string.connect_mainnet : R.string.connect_testnet));
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9ec235a0..8344105c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -18,6 +18,7 @@
Password for
Bad password!
Wallet does not exists!
+ This is not a wallet!
Daemon address must be set!
Wallet does not match selected net
Cannot connect to daemon! Try again.