Enable rescan on wallet (from menu) (#663)

* rescan
This commit is contained in:
m2049r 2020-06-01 10:03:36 +02:00 committed by GitHub
parent 41290f51fd
commit 291e311b8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 102 additions and 5 deletions

View File

@ -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 {

View File

@ -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<Bitmonero::Wallet>(env, instance);
return static_cast<jboolean>(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<Bitmonero::Wallet>(env, instance);
wallet->rescanBlockchainAsync();
}
//TODO virtual void setAutoRefreshInterval(int millis) = 0;
//TODO virtual int autoRefreshInterval() const = 0;

View File

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

View File

@ -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() {

View File

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

View File

@ -34,4 +34,9 @@
android:title="@string/menu_info"
app:showAsAction="never" />
<item
android:id="@+id/action_rescan"
android:orderInCategory="600"
android:title="@string/menu_rescan"
app:showAsAction="never" />
</menu>

View File

@ -383,4 +383,6 @@
<string name="label_restoreheight">Restablir Alçada</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -386,4 +386,6 @@
<string name="label_restoreheight">Wiederherstellungshöhe</string>
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -385,4 +385,6 @@
<string name="label_restoreheight">Ύψος ανάκτησης</string> <!-- "Restore Height" -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -385,4 +385,6 @@
<string name="label_restoreheight">Restaŭralteco</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -375,4 +375,6 @@
<string name="label_restoreheight">Altura de Restauración</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -383,4 +383,6 @@
<string name="label_restoreheight">Taastamise plokinumber</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -389,4 +389,6 @@
<string name="label_restoreheight">Hauteur de restauration</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -387,4 +387,6 @@
<string name="label_restoreheight">Visszaállítási lánchossz</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -388,4 +388,6 @@
<string name="label_restoreheight">Altezza di ripristino</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -394,4 +394,6 @@
<string name="label_restoreheight">Restore Height</string>
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -385,4 +385,6 @@
<string name="label_restoreheight">Restore Height</string>
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -385,4 +385,6 @@
<string name="label_restoreheight">Herstelpunt</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -377,4 +377,6 @@
<string name="label_restoreheight">Restaurar da altura</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -389,4 +389,6 @@
<string name="label_restoreheight">Restaurar de Altura</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -385,4 +385,6 @@
<string name="label_restoreheight">Restaurează Monobloc</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -389,4 +389,6 @@
<string name="label_restoreheight">Восстановить высоту</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -386,4 +386,6 @@
<string name="label_restoreheight">Výška</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -385,4 +385,6 @@
<string name="label_restoreheight">Obnovi visinu</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -370,4 +370,6 @@
<string name="label_restoreheight">Återställningshöjd</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -389,4 +389,6 @@
<string name="label_restoreheight">Відновити висоту</string> <!-- Restore Height -->
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -307,4 +307,6 @@
<string name="label_restoreheight">Restore Height</string>
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -384,4 +384,6 @@
<string name="label_restoreheight">Restore Height</string>
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>

View File

@ -436,4 +436,6 @@
<string name="label_restoreheight">Restore Height</string>
<string name="toast_ledger_start_app">Start Monero App on %1$s</string>
<string name="menu_rescan">Rescan!</string>
</resources>