From 051b0109797480b27c4d40b6ee744cdb57497abe Mon Sep 17 00:00:00 2001 From: m2049r Date: Tue, 23 Mar 2021 18:09:58 +0100 Subject: [PATCH] show new incoming tx in subaddress details --- 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 4aa65ad00f..0ee925bbb2 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 0000000000..242bea0f54 --- /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 897dcd0cf1..0a784f318c 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 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 void onRefreshed(final Wallet wallet) { 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 93552e7576..a35ced4462 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 boolean isSynced() { 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 @@ private void enableStreetMode(boolean enable) { } 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 @@ private void stopWalletService() { 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 void fail(String walletName) { 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 boolean onRefreshed(final Wallet wallet, final boolean full) { 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 boolean onRefreshed(final Wallet wallet, final boolean full) { 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 boolean onRefreshed(final Wallet wallet, final boolean full) { 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 @@ else if (!walletStatus.isOk()) 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 @@ else if (!walletStatus.isOk()) @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 void onTransactionCreated(final String txTag, final PendingTransaction pe @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 void onSendTransactionFailed(final String error) { @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 void onTransactionSent(final String txId) { @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 void run() { 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 void fail(String walletName) { 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 void onBackPressed() { 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 d365cf8b73..005244820f 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 void onRefreshed(final Wallet wallet, final boolean full) { accountIndex = wallet.getAccountIndex(); txlist.scrollToPosition(0); } - } updateStatus(wallet); }