wallet rename + tweaks
This commit is contained in:
parent
4b2d52fbe6
commit
e662d5a9c0
|
@ -1,2 +1,2 @@
|
||||||
workspace.xml
|
workspace.xml
|
||||||
markdown-navigator*
|
markdown-*
|
||||||
|
|
|
@ -295,6 +295,10 @@ public class GenerateFragment extends Fragment {
|
||||||
private void generateWallet() {
|
private void generateWallet() {
|
||||||
String name = etWalletName.getText().toString();
|
String name = etWalletName.getText().toString();
|
||||||
if (name.length() == 0) return;
|
if (name.length() == 0) return;
|
||||||
|
if (name.charAt(0)=='.') {
|
||||||
|
Toast.makeText(getActivity(), getString(R.string.generate_wallet_dot), Toast.LENGTH_LONG).show();
|
||||||
|
etWalletName.requestFocus();
|
||||||
|
}
|
||||||
File walletFile = Helper.getWalletFile(getActivity(), name);
|
File walletFile = Helper.getWalletFile(getActivity(), name);
|
||||||
if (WalletManager.getInstance().walletExists(walletFile)) {
|
if (WalletManager.getInstance().walletExists(walletFile)) {
|
||||||
Toast.makeText(getActivity(), getString(R.string.generate_wallet_exists), Toast.LENGTH_LONG).show();
|
Toast.makeText(getActivity(), getString(R.string.generate_wallet_exists), Toast.LENGTH_LONG).show();
|
||||||
|
|
|
@ -161,11 +161,51 @@ public class LoginActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class AsyncRename extends AsyncTask<String, Void, Boolean> {
|
||||||
|
ProgressDialog progressDialog = new MyProgressDialog(LoginActivity.this, R.string.rename_progress);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWalletRename(String walletName) {
|
protected void onPreExecute() {
|
||||||
|
super.onPreExecute();
|
||||||
|
progressDialog.show();
|
||||||
|
LoginActivity.this.asyncWaitTask = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(String... params) {
|
||||||
|
if (params.length != 2) return false;
|
||||||
|
File walletFile = Helper.getWalletFile(LoginActivity.this, params[0]);
|
||||||
|
String newName = params[1];
|
||||||
|
return renameWallet(walletFile, newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Boolean result) {
|
||||||
|
super.onPostExecute(result);
|
||||||
|
progressDialog.dismiss();
|
||||||
|
if (result) {
|
||||||
|
reloadWalletList();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(LoginActivity.this, getString(R.string.rename_failed), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
LoginActivity.this.asyncWaitTask = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy + delete seems safer than rename bevause we call rollback easily
|
||||||
|
boolean renameWallet(File walletFile, String newName) {
|
||||||
|
if (copyWallet(walletFile, new File(walletFile.getParentFile(), newName), false)) {
|
||||||
|
deleteWallet(walletFile);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWalletRename(final String walletName) {
|
||||||
Log.d(TAG, "rename for wallet ." + walletName + ".");
|
Log.d(TAG, "rename for wallet ." + walletName + ".");
|
||||||
if (checkServiceRunning()) return;
|
if (checkServiceRunning()) return;
|
||||||
final File walletFile = Helper.getWalletFile(this, walletName);
|
|
||||||
LayoutInflater li = LayoutInflater.from(this);
|
LayoutInflater li = LayoutInflater.from(this);
|
||||||
View promptsView = li.inflate(R.layout.prompt_rename, null);
|
View promptsView = li.inflate(R.layout.prompt_rename, null);
|
||||||
|
|
||||||
|
@ -175,7 +215,7 @@ public class LoginActivity extends AppCompatActivity
|
||||||
final EditText etRename = (EditText) promptsView.findViewById(R.id.etRename);
|
final EditText etRename = (EditText) promptsView.findViewById(R.id.etRename);
|
||||||
final TextView tvRenameLabel = (TextView) promptsView.findViewById(R.id.tvRenameLabel);
|
final TextView tvRenameLabel = (TextView) promptsView.findViewById(R.id.tvRenameLabel);
|
||||||
|
|
||||||
tvRenameLabel.setText(getString(R.string.prompt_rename) + " " + walletFile.getName());
|
tvRenameLabel.setText(getString(R.string.prompt_rename) + " " + walletName);
|
||||||
|
|
||||||
// set dialog message
|
// set dialog message
|
||||||
alertDialogBuilder
|
alertDialogBuilder
|
||||||
|
@ -185,10 +225,7 @@ public class LoginActivity extends AppCompatActivity
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
Helper.hideKeyboardAlways(LoginActivity.this);
|
Helper.hideKeyboardAlways(LoginActivity.this);
|
||||||
String newName = etRename.getText().toString();
|
String newName = etRename.getText().toString();
|
||||||
if (!renameWallet(walletFile, newName)) {
|
new AsyncRename().execute(walletName, newName);
|
||||||
Toast.makeText(LoginActivity.this, getString(R.string.rename_failed), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
reloadWalletList();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton("Cancel",
|
.setNegativeButton("Cancel",
|
||||||
|
@ -209,10 +246,7 @@ public class LoginActivity extends AppCompatActivity
|
||||||
Helper.hideKeyboardAlways(LoginActivity.this);
|
Helper.hideKeyboardAlways(LoginActivity.this);
|
||||||
String newName = etRename.getText().toString();
|
String newName = etRename.getText().toString();
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
if (!renameWallet(walletFile, newName)) {
|
new AsyncRename().execute(walletName, newName);
|
||||||
Toast.makeText(LoginActivity.this, getString(R.string.rename_failed), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
reloadWalletList();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -261,6 +295,9 @@ public class LoginActivity extends AppCompatActivity
|
||||||
File walletFile = Helper.getWalletFile(LoginActivity.this, walletName);
|
File walletFile = Helper.getWalletFile(LoginActivity.this, walletName);
|
||||||
File backupFile = new File(backupFolder, walletName);
|
File backupFile = new File(backupFolder, walletName);
|
||||||
Log.d(TAG, "backup " + walletFile.getAbsolutePath() + " to " + backupFile.getAbsolutePath());
|
Log.d(TAG, "backup " + walletFile.getAbsolutePath() + " to " + backupFile.getAbsolutePath());
|
||||||
|
// TODO probably better to copy to a new file and then rename
|
||||||
|
// then if something fails we have the old backup at least
|
||||||
|
// or just create a new backup every time and keep n old backups
|
||||||
return copyWallet(walletFile, backupFile, true);
|
return copyWallet(walletFile, backupFile, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +335,7 @@ public class LoginActivity extends AppCompatActivity
|
||||||
if (result) {
|
if (result) {
|
||||||
reloadWalletList();
|
reloadWalletList();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(LoginActivity.this, getString(R.string.backup_failed), Toast.LENGTH_LONG).show();
|
Toast.makeText(LoginActivity.this, getString(R.string.archive_failed), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
LoginActivity.this.asyncWaitTask = null;
|
LoginActivity.this.asyncWaitTask = null;
|
||||||
}
|
}
|
||||||
|
@ -740,29 +777,24 @@ public class LoginActivity extends AppCompatActivity
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO use move
|
boolean walletExists(File walletFile, boolean any) {
|
||||||
boolean renameWallet(File walletFile, String newName) {
|
|
||||||
if (copyWallet(walletFile, new File(walletFile.getParentFile(), newName), false)) {
|
|
||||||
deleteWallet(walletFile);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean walletExists(File walletFile) {
|
|
||||||
File dir = walletFile.getParentFile();
|
File dir = walletFile.getParentFile();
|
||||||
String name = walletFile.getName();
|
String name = walletFile.getName();
|
||||||
boolean exists = new File(dir, name).exists();
|
if (any) {
|
||||||
exists = new File(dir, name + ".keys").exists() && exists;
|
return new File(dir, name).exists()
|
||||||
exists = new File(dir, name + ".address.txt").exists() && exists;
|
|| new File(dir, name + ".keys").exists()
|
||||||
return exists;
|
|| new File(dir, name + ".address.txt").exists();
|
||||||
|
} else {
|
||||||
|
return new File(dir, name).exists()
|
||||||
|
&& new File(dir, name + ".keys").exists()
|
||||||
|
&& new File(dir, name + ".address.txt").exists();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean copyWallet(File srcWallet, File dstWallet, boolean overwrite) {
|
boolean copyWallet(File srcWallet, File dstWallet, boolean overwrite) {
|
||||||
Log.d(TAG, "src=" + srcWallet.exists() + " dst=" + dstWallet.exists());
|
//Log.d(TAG, "src=" + srcWallet.exists() + " dst=" + dstWallet.exists());
|
||||||
if (walletExists(dstWallet) && !overwrite) return false;
|
if (walletExists(dstWallet, true) && !overwrite) return false;
|
||||||
if (!walletExists(srcWallet)) return false;
|
if (!walletExists(srcWallet, false)) return false;
|
||||||
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
File srcDir = srcWallet.getParentFile();
|
File srcDir = srcWallet.getParentFile();
|
||||||
|
|
|
@ -93,20 +93,21 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startWalletService() {
|
private void startWalletService() {
|
||||||
acquireWakeLock();
|
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
|
acquireWakeLock();
|
||||||
String walletId = extras.getString(REQUEST_ID);
|
String walletId = extras.getString(REQUEST_ID);
|
||||||
String walletPassword = extras.getString(REQUEST_PW);
|
String walletPassword = extras.getString(REQUEST_PW);
|
||||||
connectWalletService(walletId, walletPassword);
|
connectWalletService(walletId, walletPassword);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("No extras passed! Panic!");
|
finish();
|
||||||
|
//throw new IllegalStateException("No extras passed! Panic!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopWalletService() {
|
private void stopWalletService() {
|
||||||
releaseWakeLock();
|
|
||||||
disconnectWalletService();
|
disconnectWalletService();
|
||||||
|
releaseWakeLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,12 +11,14 @@
|
||||||
|
|
||||||
<string name="backup_progress">Backup in progress</string>
|
<string name="backup_progress">Backup in progress</string>
|
||||||
<string name="archive_progress">Archive in progress</string>
|
<string name="archive_progress">Archive in progress</string>
|
||||||
|
<string name="rename_progress">Rename in progress</string>
|
||||||
|
|
||||||
<string name="service_progress">Wrapping things up …</string>
|
<string name="service_progress">Wrapping things up …\nThis can take a while!</string>
|
||||||
|
|
||||||
<string name="backup_success">Backup successful</string>
|
<string name="backup_success">Backup successful</string>
|
||||||
<string name="backup_failed">Backup failed!</string>
|
<string name="backup_failed">Backup failed!</string>
|
||||||
<string name="archive_success">Archive successful</string>
|
<string name="archive_success">Archive successful</string>
|
||||||
|
<string name="archive_failed">Archive failed!</string>
|
||||||
<string name="delete_failed">Delete failed!</string>
|
<string name="delete_failed">Delete failed!</string>
|
||||||
<string name="rename_failed">Rename failed!</string>
|
<string name="rename_failed">Rename failed!</string>
|
||||||
|
|
||||||
|
@ -93,6 +95,7 @@
|
||||||
<string name="generate_wallet_watchonly"><Watch Only Wallet></string>
|
<string name="generate_wallet_watchonly"><Watch Only Wallet></string>
|
||||||
|
|
||||||
<string name="generate_wallet_exists">Wallet exists! Choose another name</string>
|
<string name="generate_wallet_exists">Wallet exists! Choose another name</string>
|
||||||
|
<string name="generate_wallet_dot">Wallet name may not begin with \'.\'</string>
|
||||||
<string name="generate_wallet_created">Wallet created</string>
|
<string name="generate_wallet_created">Wallet created</string>
|
||||||
<string name="generate_wallet_create_failed">Wallet create failed</string>
|
<string name="generate_wallet_create_failed">Wallet create failed</string>
|
||||||
<string name="generate_wallet_create_failed_1">Wallet create failed (1/2)</string>
|
<string name="generate_wallet_create_failed_1">Wallet create failed (1/2)</string>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module external.linked.project.id="xmrwallet" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" version="4">
|
<module external.linked.project.id="xmrwallet" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||||
<component name="FacetManager">
|
<component name="FacetManager">
|
||||||
<facet type="java-gradle" name="Java-Gradle">
|
<facet type="java-gradle" name="Java-Gradle">
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|
Loading…
Reference in New Issue