details view works mostly (seed)

need to prevent opening wallet while preparing details
new wallets sont store the cache ?! (except watch only)
This commit is contained in:
m2049r 2017-08-17 22:35:25 +02:00
parent 44836a24bb
commit c9ae39508f
3 changed files with 102 additions and 6 deletions

View File

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

View File

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

View File

@ -18,6 +18,7 @@
<string name="prompt_password">Password for</string>
<string name="bad_password">Bad password!</string>
<string name="bad_wallet">Wallet does not exists!</string>
<string name="error_not_wallet">This is not a wallet!</string>
<string name="prompt_daemon_missing">Daemon address must be set!</string>
<string name="prompt_wrong_net">Wallet does not match selected net</string>
<string name="warn_daemon_unavailable">Cannot connect to daemon! Try again.</string>