From 291e311b8a1ff52147cf0bec845d8fb9cf517621 Mon Sep 17 00:00:00 2001 From: m2049r Date: Mon, 1 Jun 2020 10:03:36 +0200 Subject: [PATCH] Enable rescan on wallet (from menu) (#663) * rescan --- app/build.gradle | 4 ++-- app/src/main/cpp/monerujo.cpp | 12 +++++++++- .../com/m2049r/xmrwallet/WalletActivity.java | 22 ++++++++++++++++++- .../com/m2049r/xmrwallet/WalletFragment.java | 8 +++++++ .../com/m2049r/xmrwallet/model/Wallet.java | 10 ++++++++- app/src/main/res/menu/wallet_menu.xml | 5 +++++ app/src/main/res/values-cat/strings.xml | 2 ++ app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values-el/strings.xml | 2 ++ app/src/main/res/values-eo/strings.xml | 2 ++ app/src/main/res/values-es/strings.xml | 2 ++ app/src/main/res/values-et/strings.xml | 2 ++ app/src/main/res/values-fr/strings.xml | 2 ++ app/src/main/res/values-hu/strings.xml | 2 ++ app/src/main/res/values-it/strings.xml | 2 ++ app/src/main/res/values-ja/strings.xml | 2 ++ app/src/main/res/values-nb/strings.xml | 2 ++ app/src/main/res/values-nl/strings.xml | 2 ++ app/src/main/res/values-pt-rBR/strings.xml | 2 ++ app/src/main/res/values-pt/strings.xml | 2 ++ app/src/main/res/values-ro/strings.xml | 2 ++ app/src/main/res/values-ru/strings.xml | 2 ++ app/src/main/res/values-sk/strings.xml | 2 ++ app/src/main/res/values-sr/strings.xml | 2 ++ app/src/main/res/values-sv/strings.xml | 2 ++ app/src/main/res/values-ua/strings.xml | 2 ++ app/src/main/res/values-zh-rCN/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 29 files changed, 102 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7078e6e..c4d7dac 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.m2049r.xmrwallet" minSdkVersion 21 targetSdkVersion 28 - versionCode 203 - versionName "1.12.13 'Caerbannog'" + versionCode 300 + versionName "1.13.0 'ReStart'" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { diff --git a/app/src/main/cpp/monerujo.cpp b/app/src/main/cpp/monerujo.cpp index c511be6..dc6ac8f 100644 --- a/app/src/main/cpp/monerujo.cpp +++ b/app/src/main/cpp/monerujo.cpp @@ -785,7 +785,7 @@ Java_com_m2049r_xmrwallet_model_Wallet_getDaemonBlockChainTargetHeight(JNIEnv *e } JNIEXPORT jboolean JNICALL -Java_com_m2049r_xmrwallet_model_Wallet_isSynchronized(JNIEnv *env, jobject instance) { +Java_com_m2049r_xmrwallet_model_Wallet_isSynchronizedJ(JNIEnv *env, jobject instance) { Bitmonero::Wallet *wallet = getHandle(env, instance); return static_cast(wallet->synchronized()); } @@ -909,6 +909,16 @@ Java_com_m2049r_xmrwallet_model_Wallet_refreshAsync(JNIEnv *env, jobject instanc wallet->refreshAsync(); } +//TODO virtual bool rescanBlockchain() = 0; + +//virtual void rescanBlockchainAsync() = 0; +JNIEXPORT void JNICALL +Java_com_m2049r_xmrwallet_model_Wallet_rescanBlockchainAsync(JNIEnv *env, jobject instance) { + Bitmonero::Wallet *wallet = getHandle(env, instance); + wallet->rescanBlockchainAsync(); +} + + //TODO virtual void setAutoRefreshInterval(int millis) = 0; //TODO virtual int autoRefreshInterval() const = 0; diff --git a/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java b/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java index b8e3429..0d8572c 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java @@ -217,6 +217,20 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste releaseWakeLock(); } + private void onWalletRescan() { + try { + final WalletFragment walletFragment = (WalletFragment) + getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName()); + getWallet().rescanBlockchainAsync(); + synced = false; + walletFragment.unsync(); + invalidateOptionsMenu(); + } catch (ClassCastException ex) { + Timber.d(ex.getLocalizedMessage()); + // keep calm and carry on + } + } + @Override protected void onStop() { Timber.d("onStop()"); @@ -243,7 +257,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste public boolean onPrepareOptionsMenu(Menu menu) { MenuItem renameItem = menu.findItem(R.id.action_rename); if (renameItem != null) - renameItem.setVisible(hasWallet() && getWallet().isSynchronized()); + renameItem.setEnabled(hasWallet() && getWallet().isSynchronized()); MenuItem streetmodeItem = menu.findItem(R.id.action_streetmode); if (streetmodeItem != null) if (isStreetMode()) { @@ -251,12 +265,18 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste } else { streetmodeItem.setIcon(R.drawable.gunther_24dp); } + final MenuItem rescanItem = menu.findItem(R.id.action_rescan); + if (rescanItem != null) + rescanItem.setEnabled(isSynced()); return super.onPrepareOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.action_rescan: + onWalletRescan(); + return true; case R.id.action_info: onWalletDetails(); return true; diff --git a/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java b/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java index 7e214d9..ea8e4ae 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java @@ -356,6 +356,14 @@ public class WalletFragment extends Fragment if (isVisible()) enableAccountsList(true); //otherwise it is enabled in onResume() } + public void unsync() { + if (!activityCallback.isWatchOnly()) { + bSend.setVisibility(View.INVISIBLE); + bSend.setEnabled(false); + } + if (isVisible()) enableAccountsList(false); //otherwise it is enabled in onResume() + } + boolean walletLoaded = false; public void onLoaded() { diff --git a/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java b/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java index ec9f80e..660744d 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java +++ b/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java @@ -248,7 +248,13 @@ public class Wallet { public native long getDaemonBlockChainTargetHeight(); - public native boolean isSynchronized(); + public native boolean isSynchronizedJ(); + + public boolean isSynchronized() { + final long daemonHeight = getDaemonBlockChainHeight(); + if (daemonHeight == 0) return false; + return isSynchronizedJ() && (getBlockChainHeight() == daemonHeight); + } public static native String getDisplayAmount(long amount); @@ -278,6 +284,8 @@ public class Wallet { public native void refreshAsync(); + public native void rescanBlockchainAsync(); + //TODO virtual void setAutoRefreshInterval(int millis) = 0; //TODO virtual int autoRefreshInterval() const = 0; diff --git a/app/src/main/res/menu/wallet_menu.xml b/app/src/main/res/menu/wallet_menu.xml index 691c770..97c4757 100644 --- a/app/src/main/res/menu/wallet_menu.xml +++ b/app/src/main/res/menu/wallet_menu.xml @@ -34,4 +34,9 @@ android:title="@string/menu_info" app:showAsAction="never" /> + \ 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 41818a3..67665ca 100644 --- a/app/src/main/res/values-cat/strings.xml +++ b/app/src/main/res/values-cat/strings.xml @@ -383,4 +383,6 @@ Restablir Alçada Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 45ebe8c..161677a 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -386,4 +386,6 @@ Wiederherstellungshöhe Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index bcd1db1..5598201 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -385,4 +385,6 @@ Ύψος ανάκτησης Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-eo/strings.xml b/app/src/main/res/values-eo/strings.xml index a1f3288..27c2221 100644 --- a/app/src/main/res/values-eo/strings.xml +++ b/app/src/main/res/values-eo/strings.xml @@ -385,4 +385,6 @@ Restaŭralteco Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index d593f15..9e361f5 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -375,4 +375,6 @@ Altura de Restauración Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-et/strings.xml b/app/src/main/res/values-et/strings.xml index 59cc42b..583bc5b 100644 --- a/app/src/main/res/values-et/strings.xml +++ b/app/src/main/res/values-et/strings.xml @@ -383,4 +383,6 @@ Taastamise plokinumber Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 2a33c31..5008abb 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -389,4 +389,6 @@ Hauteur de restauration Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index fb7b66d..6293da1 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -387,4 +387,6 @@ Visszaállítási lánchossz Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 0f4e421..1fde8ac 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -388,4 +388,6 @@ Altezza di ripristino Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index b5c786f..c1b7c55 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -394,4 +394,6 @@ Restore Height Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 2c1a872..4415955 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -385,4 +385,6 @@ Restore Height Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 1896026..b8b916c 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -385,4 +385,6 @@ Herstelpunt Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 08767a7..8b2f2bf 100755 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -377,4 +377,6 @@ Restaurar da altura Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 1b3ee7c..ae58d05 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -389,4 +389,6 @@ Restaurar de Altura Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index 8ddd026..b807a88 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -385,4 +385,6 @@ Restaurează Monobloc Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 6aace5f..e2d0a68 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -389,4 +389,6 @@ Восстановить высоту Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 0ed9d81..d58a705 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -386,4 +386,6 @@ Výška Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-sr/strings.xml b/app/src/main/res/values-sr/strings.xml index 84405a5..8e16614 100644 --- a/app/src/main/res/values-sr/strings.xml +++ b/app/src/main/res/values-sr/strings.xml @@ -385,4 +385,6 @@ Obnovi visinu Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index cdaa367..829bf46 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -370,4 +370,6 @@ Återställningshöjd Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-ua/strings.xml b/app/src/main/res/values-ua/strings.xml index 5995984..246b453 100644 --- a/app/src/main/res/values-ua/strings.xml +++ b/app/src/main/res/values-ua/strings.xml @@ -389,4 +389,6 @@ Відновити висоту Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index c5b5cbf..05a27e9 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -307,4 +307,6 @@ Restore Height Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 255fb8e..918e9da 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -384,4 +384,6 @@ Restore Height Start Monero App on %1$s + + Rescan! diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bb1ec18..a7f8ddb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -436,4 +436,6 @@ Restore Height Start Monero App on %1$s + + Rescan!