Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show new incoming tx in subaddress details #734

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/m2049r/xmrwallet/OnBlockUpdateListener.java
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
55 changes: 31 additions & 24 deletions app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(() -> {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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(() -> {
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ public void onRefreshed(final Wallet wallet, final boolean full) {
accountIndex = wallet.getAccountIndex();
txlist.scrollToPosition(0);
}

}
updateStatus(wallet);
}
Expand Down