From 7109442ad02586fd05bbcb81cdc56e856f84db9c Mon Sep 17 00:00:00 2001 From: pokkst Date: Thu, 8 Sep 2022 11:27:05 -0500 Subject: [PATCH] Add retry system if connection fails. --- .../com/m2049r/xmrwallet/MainActivity.java | 5 ++++ .../service/MoneroHandlerThread.java | 23 +++++++++++++++---- .../layout/password_bottom_sheet_dialog.xml | 1 + 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/m2049r/xmrwallet/MainActivity.java b/app/src/main/java/com/m2049r/xmrwallet/MainActivity.java index 57e004e..7e1c850 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/MainActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/MainActivity.java @@ -87,6 +87,11 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre this.blockchainService.refreshBlockchain(); } + @Override + public void onConnectionFail() { + System.out.println("CONNECT FAILED"); + } + @Override public void onPasswordSuccess(String password) { File walletFile = new File(getApplicationInfo().dataDir, Constants.WALLET_NAME); diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/MoneroHandlerThread.java b/app/src/main/java/com/m2049r/xmrwallet/service/MoneroHandlerThread.java index a70dbd9..3b97229 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/service/MoneroHandlerThread.java +++ b/app/src/main/java/com/m2049r/xmrwallet/service/MoneroHandlerThread.java @@ -55,9 +55,10 @@ public class MoneroHandlerThread extends Thread implements WalletListener { @Override public void run() { - WalletManager.getInstance().setDaemon(Node.fromString(DefaultNodes.XMRTW.getUri())); - wallet.init(0); + WalletManager.getInstance().setProxy("127.0.0.1:9050"); + WalletManager.getInstance().setDaemon(Node.fromString(DefaultNodes.MONERUJO_ONION.getUri())); wallet.setProxy("127.0.0.1:9050"); + wallet.init(0); wallet.setListener(this); wallet.startRefresh(); } @@ -85,10 +86,23 @@ public class MoneroHandlerThread extends Thread implements WalletListener { refresh(); } + int triesLeft = 5; + @Override public void refreshed() { - wallet.setSynchronized(); - refresh(); + Wallet.ConnectionStatus status = wallet.getFullStatus().getConnectionStatus(); + if(status == Wallet.ConnectionStatus.ConnectionStatus_Disconnected || status == null) { + if(triesLeft > 0) { + wallet.startRefresh(); + triesLeft--; + } else { + listener.onConnectionFail(); + } + } else { + BlockchainService.getInstance().setDaemonHeight(wallet.getDaemonBlockChainHeight()); + wallet.setSynchronized(); + refresh(); + } } private void refresh() { @@ -105,5 +119,6 @@ public class MoneroHandlerThread extends Thread implements WalletListener { public interface Listener { void onRefresh(); + void onConnectionFail(); } } diff --git a/app/src/main/res/layout/password_bottom_sheet_dialog.xml b/app/src/main/res/layout/password_bottom_sheet_dialog.xml index bfa442c..ed97097 100644 --- a/app/src/main/res/layout/password_bottom_sheet_dialog.xml +++ b/app/src/main/res/layout/password_bottom_sheet_dialog.xml @@ -21,6 +21,7 @@ android:layout_marginEnd="24dp" android:layout_marginBottom="32dp" android:hint="Password" + android:inputType="textPassword" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@id/unlock_wallet_button"/>