From 9181858ea12ed0cc312912d58cf5f1b3d9e763eb 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 b5d1de2..75db7c5 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 0db596e..34939c8 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 d743a0a..e424a1b 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 fda24ce..4e78794 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 b175cd9..beca823 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 135d0e0..ce871a7 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 cad6586..9a85e0a 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 a94caff..26f9298 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 2fc326e..309e8bb 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 f81d534..95bba30 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 1f9edc6..29eb342 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 c9318ec..1aa0967 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 b7319cf..d5f41a3 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 f561b6c..13e8b59 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 48e0d87..d30d7ab 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 434d361..8f9e9ec 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 0698828..f43eba7 100755 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -416,10 +416,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 2910dfb..8cb7a29 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 b63934c..c09cdd9 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 176a0b6..b81b74b 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 a843758..c5996a4 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 9a00bb6..0c7334c 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 1fb5477..ea7822d 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 a67fa4e..c16dca7 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 fe6be17..3d93af3 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 5876f49..8ba96f4 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 f4d297f..ec63778 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!