From c7bd7469a194183a57d2d03848a10a03d62a590f Mon Sep 17 00:00:00 2001 From: m2049r Date: Tue, 20 Apr 2021 13:06:14 +0200 Subject: [PATCH] reset wallet by deleting wallet cache file (#751) --- .../com/m2049r/xmrwallet/LoginActivity.java | 37 +++++++++++++++++++ .../com/m2049r/xmrwallet/LoginFragment.java | 4 ++ .../service/exchange/ecb/ExchangeApiImpl.java | 2 +- app/src/main/res/menu/list_context_menu.xml | 4 ++ app/src/main/res/values-cat/strings.xml | 5 ++- app/src/main/res/values-de/strings.xml | 3 ++ app/src/main/res/values-el/strings.xml | 5 ++- app/src/main/res/values-eo/strings.xml | 5 ++- app/src/main/res/values-es/strings.xml | 3 ++ app/src/main/res/values-et/strings.xml | 5 ++- app/src/main/res/values-fr/strings.xml | 3 ++ app/src/main/res/values-hu/strings.xml | 5 ++- app/src/main/res/values-it/strings.xml | 3 ++ app/src/main/res/values-ja/strings.xml | 5 ++- app/src/main/res/values-nb/strings.xml | 5 ++- app/src/main/res/values-nl/strings.xml | 3 ++ app/src/main/res/values-pt-rBR/strings.xml | 5 ++- app/src/main/res/values-pt/strings.xml | 5 ++- app/src/main/res/values-ro/strings.xml | 5 ++- app/src/main/res/values-ru/strings.xml | 3 ++ app/src/main/res/values-sk/strings.xml | 3 ++ app/src/main/res/values-sr/strings.xml | 3 ++ app/src/main/res/values-sv/strings.xml | 5 ++- app/src/main/res/values-uk/strings.xml | 3 ++ app/src/main/res/values-zh-rCN/strings.xml | 5 ++- app/src/main/res/values-zh-rTW/strings.xml | 5 ++- app/src/main/res/values/strings.xml | 5 ++- 27 files changed, 129 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java index b5d1de23..75db7c57 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java @@ -557,6 +557,31 @@ public class LoginActivity extends BaseActivity .show(); } + @Override + public void onWalletDeleteCache(final String walletName) { + Timber.d("delete cache for wallet ." + walletName + "."); + if (checkServiceRunning()) return; + DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: + if (!deleteWalletCache(Helper.getWalletFile(LoginActivity.this, walletName))) { + Toast.makeText(LoginActivity.this, getString(R.string.delete_failed), Toast.LENGTH_LONG).show(); + } + break; + case DialogInterface.BUTTON_NEGATIVE: + // do nothing + break; + } + }; + + AlertDialog.Builder builder = new MaterialAlertDialogBuilder(this); + builder.setMessage(getString(R.string.deletecache_alert_message, walletName)) + .setTitle(walletName) + .setPositiveButton(getString(R.string.delete_alert_yes), dialogClickListener) + .setNegativeButton(getString(R.string.delete_alert_no), dialogClickListener) + .show(); + } + void reloadWalletList() { Timber.d("reloadWalletList()"); try { @@ -1024,6 +1049,18 @@ public class LoginActivity extends BaseActivity return success; } + boolean deleteWalletCache(File walletFile) { + Timber.d("deleteWalletCache %s", walletFile.getAbsolutePath()); + File dir = walletFile.getParentFile(); + String name = walletFile.getName(); + boolean success = true; + File cacheFile = new File(dir, name); + if (cacheFile.exists()) { + success = cacheFile.delete(); + } + return success; + } + void copyFile(File src, File dst) throws IOException { try (FileChannel inChannel = new FileInputStream(src).getChannel(); FileChannel outChannel = new FileOutputStream(dst).getChannel()) { diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java index 0db596ea..34939c8f 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java @@ -88,6 +88,8 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter void onWalletDelete(String walletName); + void onWalletDeleteCache(String walletName); + void onAddWallet(String type); void onNodePrefs(); @@ -220,6 +222,8 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter activityCallback.onWalletBackup(listItem.getName()); } else if (id == R.id.action_archive) { activityCallback.onWalletDelete(listItem.getName()); + } else if (id == R.id.action_deletecache) { + activityCallback.onWalletDeleteCache(listItem.getName()); } else { return super.onContextItemSelected(item); } diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/exchange/ecb/ExchangeApiImpl.java b/app/src/main/java/com/m2049r/xmrwallet/service/exchange/ecb/ExchangeApiImpl.java index d743a0a8..e424a1bf 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/service/exchange/ecb/ExchangeApiImpl.java +++ b/app/src/main/java/com/m2049r/xmrwallet/service/exchange/ecb/ExchangeApiImpl.java @@ -167,7 +167,7 @@ public class ExchangeApiImpl implements ExchangeApi { private Calendar fetchDate = null; synchronized private ExchangeRate getRate(String currency) throws ExchangeException { - Timber.e("Getting %s", currency); + Timber.d("Getting %s", currency); final Double rate = fxEntries.get(currency); if (rate == null) throw new ExchangeException(404, "Currency not supported: " + currency); return new ExchangeRateImpl(currency, rate, fxDate.getTime()); diff --git a/app/src/main/res/menu/list_context_menu.xml b/app/src/main/res/menu/list_context_menu.xml index fda24cec..4e78794f 100644 --- a/app/src/main/res/menu/list_context_menu.xml +++ b/app/src/main/res/menu/list_context_menu.xml @@ -26,4 +26,8 @@ android:orderInCategory="500" android:title="@string/menu_info" /> + \ No newline at end of file diff --git a/app/src/main/res/values-cat/strings.xml b/app/src/main/res/values-cat/strings.xml index 6c517c6a..10aae1ca 100644 --- a/app/src/main/res/values-cat/strings.xml +++ b/app/src/main/res/values-cat/strings.xml @@ -417,10 +417,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 851b765b..f643e1ad 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -424,4 +424,7 @@ Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 34c692a7..529cfcab 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -419,10 +419,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-eo/strings.xml b/app/src/main/res/values-eo/strings.xml index 6237dcf0..bd85a3bc 100644 --- a/app/src/main/res/values-eo/strings.xml +++ b/app/src/main/res/values-eo/strings.xml @@ -419,10 +419,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 7023abe9..ebf1bc01 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -416,4 +416,7 @@ Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-et/strings.xml b/app/src/main/res/values-et/strings.xml index 7f265e5b..e058a836 100644 --- a/app/src/main/res/values-et/strings.xml +++ b/app/src/main/res/values-et/strings.xml @@ -417,10 +417,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 98d688b1..d8af4fa0 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -429,4 +429,7 @@ Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index bcdbb142..1a8d714c 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -421,10 +421,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 94b8b02f..2322408c 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -428,4 +428,7 @@ Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index d5721daf..d853b662 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -422,10 +422,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 1b2125fd..f1e2113b 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -419,10 +419,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index f99fa2a6..2f0f59a1 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -425,4 +425,7 @@ Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index e83fe230..576e4054 100755 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -411,10 +411,13 @@ Selecione um subendereço Toque e segure para mais detalhes - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index c9e70460..52591012 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -423,10 +423,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index 17d0de7e..45700668 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -419,10 +419,13 @@ Selectează o subadresă Atinge lung pentru detalii - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index a10317a0..63c99449 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -429,4 +429,7 @@ Импортировать кошелек Ошибка импорта! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index c1895c2e..5340de48 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -426,4 +426,7 @@ Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-sr/strings.xml b/app/src/main/res/values-sr/strings.xml index 7733d62a..0f5d2828 100644 --- a/app/src/main/res/values-sr/strings.xml +++ b/app/src/main/res/values-sr/strings.xml @@ -424,4 +424,7 @@ Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index ea059569..2ac2d446 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -411,10 +411,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index df166ffc..9cb77ae2 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -429,4 +429,7 @@ Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index db38944e..3838a3d5 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -343,10 +343,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 6f485452..4cbe3502 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -418,10 +418,13 @@ Select a subaddress Long-press for details - The wallet will be deleted! + This wallet will be deleted! Delete Delete failed! Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load! diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7da9eea7..32fb5855 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -278,7 +278,7 @@ Take me back! Details - The wallet will be deleted! + This wallet will be deleted! Yes, do that! No thanks! @@ -497,4 +497,7 @@ Import wallet Import failed! + + Reset wallet! + This wallet will be reset, losing all off-chain data (like notes, account & subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!