From 24fc27b09e3158d0e67ee145c1f8ab8f657d2746 Mon Sep 17 00:00:00 2001 From: m2049r Date: Tue, 23 Mar 2021 19:05:30 +0100 Subject: [PATCH] show new incoming tx in subaddress details (#734) --- app/build.gradle | 4 +- .../xmrwallet/OnBlockUpdateListener.java | 23 ++++++++ .../xmrwallet/SubaddressInfoFragment.java | 9 ++- .../com/m2049r/xmrwallet/WalletActivity.java | 55 +++++++++++-------- .../com/m2049r/xmrwallet/WalletFragment.java | 1 - 5 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/com/m2049r/xmrwallet/OnBlockUpdateListener.java diff --git a/app/build.gradle b/app/build.gradle index 4aa65ad..0ee925b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.m2049r.xmrwallet" minSdkVersion 21 targetSdkVersion 29 - versionCode 800 - versionName "1.18.0 'ChAdOx1'" + versionCode 801 + versionName "1.18.1 'ChAdOx1'" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { diff --git a/app/src/main/java/com/m2049r/xmrwallet/OnBlockUpdateListener.java b/app/src/main/java/com/m2049r/xmrwallet/OnBlockUpdateListener.java new file mode 100644 index 0000000..242bea0 --- /dev/null +++ b/app/src/main/java/com/m2049r/xmrwallet/OnBlockUpdateListener.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 m2049r + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.m2049r.xmrwallet; + +import com.m2049r.xmrwallet.model.Wallet; + +public interface OnBlockUpdateListener { + void onBlockUpdate(final Wallet wallet); +} diff --git a/app/src/main/java/com/m2049r/xmrwallet/SubaddressInfoFragment.java b/app/src/main/java/com/m2049r/xmrwallet/SubaddressInfoFragment.java index 897dcd0..0a784f3 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/SubaddressInfoFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/SubaddressInfoFragment.java @@ -45,8 +45,8 @@ import java.util.List; import timber.log.Timber; -// TODO: live update - i.e. use onRefreshed() somehow -public class SubaddressInfoFragment extends Fragment implements TransactionInfoAdapter.OnInteractionListener { +public class SubaddressInfoFragment extends Fragment + implements TransactionInfoAdapter.OnInteractionListener, OnBlockUpdateListener { private TransactionInfoAdapter adapter; private Subaddress subaddress; @@ -123,6 +123,11 @@ public class SubaddressInfoFragment extends Fragment implements TransactionInfoA tvTxLabel.setText(R.string.subaddress_tx_label); } + @Override + public void onBlockUpdate(Wallet wallet) { + onRefreshed(wallet); + } + // Callbacks from TransactionInfoAdapter @Override public void onInteraction(final View view, final TransactionInfo infoItem) { diff --git a/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java b/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java index 93552e7..a35ced4 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java @@ -141,6 +141,14 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste return synced; } + private WalletFragment getWalletFragment() { + return (WalletFragment) getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName()); + } + + private Fragment getCurrentFragment() { + return getSupportFragmentManager().findFragmentById(R.id.fragment_container); + } + @Override public boolean isStreetMode() { return streetMode > 0; @@ -152,8 +160,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste } else { streetMode = 0; } - final WalletFragment walletFragment = (WalletFragment) - getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName()); + final WalletFragment walletFragment = getWalletFragment(); if (walletFragment != null) walletFragment.resetDismissedTransactions(); forceUpdate(); runOnUiThread(() -> { @@ -220,8 +227,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste private void onWalletRescan() { try { - final WalletFragment walletFragment = (WalletFragment) - getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName()); + final WalletFragment walletFragment = getWalletFragment(); getWallet().rescanBlockchainAsync(); synced = false; walletFragment.unsync(); @@ -336,8 +342,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste public void onWalletChangePassword() { try { - GenerateReviewFragment detailsFragment = (GenerateReviewFragment) - getSupportFragmentManager().findFragmentById(R.id.fragment_container); + GenerateReviewFragment detailsFragment = (GenerateReviewFragment) getCurrentFragment(); AlertDialog dialog = detailsFragment.createChangePasswordDialog(); if (dialog != null) { Helper.showKeyboard(dialog); @@ -571,8 +576,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste runOnUiThread(this::updateAccountsList); } try { - final WalletFragment walletFragment = (WalletFragment) - getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName()); + final WalletFragment walletFragment = getWalletFragment(); if (wallet.isSynchronized()) { Timber.d("onRefreshed() synced"); releaseWakeLock(RELEASE_WAKE_LOCK_DELAY); // the idea is to stay awake until synced @@ -583,7 +587,10 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste runOnUiThread(walletFragment::onSynced); } } - runOnUiThread(() -> walletFragment.onRefreshed(wallet, full)); + runOnUiThread(() -> { + walletFragment.onRefreshed(wallet, full); + updateCurrentFragment(wallet); + }); return true; } catch (ClassCastException ex) { // not in wallet fragment (probably send monero) @@ -593,6 +600,13 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste return false; } + private void updateCurrentFragment(final Wallet wallet) { + final Fragment fragment = getCurrentFragment(); + if (fragment instanceof OnBlockUpdateListener) { + ((OnBlockUpdateListener) fragment).onBlockUpdate(wallet); + } + } + @Override public void onWalletStored(final boolean success) { runOnUiThread(() -> { @@ -635,8 +649,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste if (requestStreetMode) onEnableStreetMode(); - final WalletFragment walletFragment = (WalletFragment) - getSupportFragmentManager().findFragmentById(R.id.fragment_container); + final WalletFragment walletFragment = getWalletFragment(); runOnUiThread(() -> { updateAccountsHeader(); if (walletFragment != null) { @@ -649,8 +662,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste @Override public void onTransactionCreated(final String txTag, final PendingTransaction pendingTransaction) { try { - final SendFragment sendFragment = (SendFragment) - getSupportFragmentManager().findFragmentById(R.id.fragment_container); + final SendFragment sendFragment = (SendFragment) getCurrentFragment(); runOnUiThread(() -> { dismissProgressDialog(); PendingTransaction.Status status = pendingTransaction.getStatus(); @@ -673,8 +685,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste @Override public void onSendTransactionFailed(final String error) { try { - final SendFragment sendFragment = (SendFragment) - getSupportFragmentManager().findFragmentById(R.id.fragment_container); + final SendFragment sendFragment = (SendFragment) getCurrentFragment(); runOnUiThread(() -> sendFragment.onSendTransactionFailed(error)); } catch (ClassCastException ex) { // not in spend fragment @@ -685,8 +696,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste @Override public void onTransactionSent(final String txId) { try { - final SendFragment sendFragment = (SendFragment) - getSupportFragmentManager().findFragmentById(R.id.fragment_container); + final SendFragment sendFragment = (SendFragment) getCurrentFragment(); runOnUiThread(() -> sendFragment.onTransactionSent(txId)); } catch (ClassCastException ex) { // not in spend fragment @@ -697,8 +707,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste @Override public void onProgress(final String text) { try { - final WalletFragment walletFragment = (WalletFragment) - getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName()); + final WalletFragment walletFragment = getWalletFragment(); runOnUiThread(new Runnable() { public void run() { walletFragment.setProgress(text); @@ -715,8 +724,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste public void onProgress(final int n) { runOnUiThread(() -> { try { - WalletFragment walletFragment = (WalletFragment) - getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName()); + WalletFragment walletFragment = getWalletFragment(); if (walletFragment != null) walletFragment.setProgress(n); } catch (ClassCastException ex) { @@ -857,8 +865,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste void onShareTxInfo() { try { - TxFragment fragment = (TxFragment) - getSupportFragmentManager().findFragmentById(R.id.fragment_container); + TxFragment fragment = (TxFragment) getCurrentFragment(); fragment.shareTxInfo(); } catch (ClassCastException ex) { // not in wallet fragment @@ -968,7 +975,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste drawer.closeDrawer(GravityCompat.START); return; } - final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container); + final Fragment fragment = getCurrentFragment(); if (fragment instanceof OnBackPressedListener) { if (!((OnBackPressedListener) fragment).onBackPressed()) { super.onBackPressed(); diff --git a/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java b/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java index d365cf8..0052448 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java @@ -363,7 +363,6 @@ public class WalletFragment extends Fragment accountIndex = wallet.getAccountIndex(); txlist.scrollToPosition(0); } - } updateStatus(wallet); }