show new incoming tx in subaddress details (#734)

This commit is contained in:
m2049r 2021-03-23 19:05:30 +01:00 committed by GitHub
parent cf4ff856d5
commit 24fc27b09e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 29 deletions

View File

@ -7,8 +7,8 @@ android {
applicationId "com.m2049r.xmrwallet" applicationId "com.m2049r.xmrwallet"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 800 versionCode 801
versionName "1.18.0 'ChAdOx1'" versionName "1.18.1 'ChAdOx1'"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild { externalNativeBuild {
cmake { cmake {

View File

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

View File

@ -45,8 +45,8 @@ import java.util.List;
import timber.log.Timber; import timber.log.Timber;
// TODO: live update - i.e. use onRefreshed() somehow public class SubaddressInfoFragment extends Fragment
public class SubaddressInfoFragment extends Fragment implements TransactionInfoAdapter.OnInteractionListener { implements TransactionInfoAdapter.OnInteractionListener, OnBlockUpdateListener {
private TransactionInfoAdapter adapter; private TransactionInfoAdapter adapter;
private Subaddress subaddress; private Subaddress subaddress;
@ -123,6 +123,11 @@ public class SubaddressInfoFragment extends Fragment implements TransactionInfoA
tvTxLabel.setText(R.string.subaddress_tx_label); tvTxLabel.setText(R.string.subaddress_tx_label);
} }
@Override
public void onBlockUpdate(Wallet wallet) {
onRefreshed(wallet);
}
// Callbacks from TransactionInfoAdapter // Callbacks from TransactionInfoAdapter
@Override @Override
public void onInteraction(final View view, final TransactionInfo infoItem) { public void onInteraction(final View view, final TransactionInfo infoItem) {

View File

@ -141,6 +141,14 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
return synced; return synced;
} }
private WalletFragment getWalletFragment() {
return (WalletFragment) getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName());
}
private Fragment getCurrentFragment() {
return getSupportFragmentManager().findFragmentById(R.id.fragment_container);
}
@Override @Override
public boolean isStreetMode() { public boolean isStreetMode() {
return streetMode > 0; return streetMode > 0;
@ -152,8 +160,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
} else { } else {
streetMode = 0; streetMode = 0;
} }
final WalletFragment walletFragment = (WalletFragment) final WalletFragment walletFragment = getWalletFragment();
getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName());
if (walletFragment != null) walletFragment.resetDismissedTransactions(); if (walletFragment != null) walletFragment.resetDismissedTransactions();
forceUpdate(); forceUpdate();
runOnUiThread(() -> { runOnUiThread(() -> {
@ -220,8 +227,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
private void onWalletRescan() { private void onWalletRescan() {
try { try {
final WalletFragment walletFragment = (WalletFragment) final WalletFragment walletFragment = getWalletFragment();
getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName());
getWallet().rescanBlockchainAsync(); getWallet().rescanBlockchainAsync();
synced = false; synced = false;
walletFragment.unsync(); walletFragment.unsync();
@ -336,8 +342,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
public void onWalletChangePassword() { public void onWalletChangePassword() {
try { try {
GenerateReviewFragment detailsFragment = (GenerateReviewFragment) GenerateReviewFragment detailsFragment = (GenerateReviewFragment) getCurrentFragment();
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
AlertDialog dialog = detailsFragment.createChangePasswordDialog(); AlertDialog dialog = detailsFragment.createChangePasswordDialog();
if (dialog != null) { if (dialog != null) {
Helper.showKeyboard(dialog); Helper.showKeyboard(dialog);
@ -571,8 +576,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
runOnUiThread(this::updateAccountsList); runOnUiThread(this::updateAccountsList);
} }
try { try {
final WalletFragment walletFragment = (WalletFragment) final WalletFragment walletFragment = getWalletFragment();
getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName());
if (wallet.isSynchronized()) { if (wallet.isSynchronized()) {
Timber.d("onRefreshed() synced"); Timber.d("onRefreshed() synced");
releaseWakeLock(RELEASE_WAKE_LOCK_DELAY); // the idea is to stay awake until 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::onSynced);
} }
} }
runOnUiThread(() -> walletFragment.onRefreshed(wallet, full)); runOnUiThread(() -> {
walletFragment.onRefreshed(wallet, full);
updateCurrentFragment(wallet);
});
return true; return true;
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
// not in wallet fragment (probably send monero) // not in wallet fragment (probably send monero)
@ -593,6 +600,13 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
return false; return false;
} }
private void updateCurrentFragment(final Wallet wallet) {
final Fragment fragment = getCurrentFragment();
if (fragment instanceof OnBlockUpdateListener) {
((OnBlockUpdateListener) fragment).onBlockUpdate(wallet);
}
}
@Override @Override
public void onWalletStored(final boolean success) { public void onWalletStored(final boolean success) {
runOnUiThread(() -> { runOnUiThread(() -> {
@ -635,8 +649,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
if (requestStreetMode) onEnableStreetMode(); if (requestStreetMode) onEnableStreetMode();
final WalletFragment walletFragment = (WalletFragment) final WalletFragment walletFragment = getWalletFragment();
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
runOnUiThread(() -> { runOnUiThread(() -> {
updateAccountsHeader(); updateAccountsHeader();
if (walletFragment != null) { if (walletFragment != null) {
@ -649,8 +662,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
@Override @Override
public void onTransactionCreated(final String txTag, final PendingTransaction pendingTransaction) { public void onTransactionCreated(final String txTag, final PendingTransaction pendingTransaction) {
try { try {
final SendFragment sendFragment = (SendFragment) final SendFragment sendFragment = (SendFragment) getCurrentFragment();
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
runOnUiThread(() -> { runOnUiThread(() -> {
dismissProgressDialog(); dismissProgressDialog();
PendingTransaction.Status status = pendingTransaction.getStatus(); PendingTransaction.Status status = pendingTransaction.getStatus();
@ -673,8 +685,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
@Override @Override
public void onSendTransactionFailed(final String error) { public void onSendTransactionFailed(final String error) {
try { try {
final SendFragment sendFragment = (SendFragment) final SendFragment sendFragment = (SendFragment) getCurrentFragment();
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
runOnUiThread(() -> sendFragment.onSendTransactionFailed(error)); runOnUiThread(() -> sendFragment.onSendTransactionFailed(error));
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
// not in spend fragment // not in spend fragment
@ -685,8 +696,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
@Override @Override
public void onTransactionSent(final String txId) { public void onTransactionSent(final String txId) {
try { try {
final SendFragment sendFragment = (SendFragment) final SendFragment sendFragment = (SendFragment) getCurrentFragment();
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
runOnUiThread(() -> sendFragment.onTransactionSent(txId)); runOnUiThread(() -> sendFragment.onTransactionSent(txId));
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
// not in spend fragment // not in spend fragment
@ -697,8 +707,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
@Override @Override
public void onProgress(final String text) { public void onProgress(final String text) {
try { try {
final WalletFragment walletFragment = (WalletFragment) final WalletFragment walletFragment = getWalletFragment();
getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName());
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
walletFragment.setProgress(text); walletFragment.setProgress(text);
@ -715,8 +724,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
public void onProgress(final int n) { public void onProgress(final int n) {
runOnUiThread(() -> { runOnUiThread(() -> {
try { try {
WalletFragment walletFragment = (WalletFragment) WalletFragment walletFragment = getWalletFragment();
getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName());
if (walletFragment != null) if (walletFragment != null)
walletFragment.setProgress(n); walletFragment.setProgress(n);
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
@ -857,8 +865,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
void onShareTxInfo() { void onShareTxInfo() {
try { try {
TxFragment fragment = (TxFragment) TxFragment fragment = (TxFragment) getCurrentFragment();
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
fragment.shareTxInfo(); fragment.shareTxInfo();
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
// not in wallet fragment // not in wallet fragment
@ -968,7 +975,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
drawer.closeDrawer(GravityCompat.START); drawer.closeDrawer(GravityCompat.START);
return; return;
} }
final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container); final Fragment fragment = getCurrentFragment();
if (fragment instanceof OnBackPressedListener) { if (fragment instanceof OnBackPressedListener) {
if (!((OnBackPressedListener) fragment).onBackPressed()) { if (!((OnBackPressedListener) fragment).onBackPressed()) {
super.onBackPressed(); super.onBackPressed();

View File

@ -363,7 +363,6 @@ public class WalletFragment extends Fragment
accountIndex = wallet.getAccountIndex(); accountIndex = wallet.getAccountIndex();
txlist.scrollToPosition(0); txlist.scrollToPosition(0);
} }
} }
updateStatus(wallet); updateStatus(wallet);
} }