mirror of
https://github.com/m2049r/xmrwallet
synced 2025-04-30 09:07:21 +02:00
UI & progress bar tweaks
service start/stop in activity onCreate/onDestroy update continues in background if screen turned off
This commit is contained in:
parent
282f00959d
commit
c19ee65dd1
app
app.iml
src/main
@ -89,6 +89,7 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/cmake" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/cmake" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||||
|
@ -58,6 +58,10 @@ public class WalletActivity extends AppCompatActivity
|
|||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
Log.d(TAG, "onStart()");
|
Log.d(TAG, "onStart()");
|
||||||
|
this.synced = false; // init syncing logic
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startWalletService() {
|
||||||
acquireWakeLock();
|
acquireWakeLock();
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
@ -67,6 +71,8 @@ public class WalletActivity extends AppCompatActivity
|
|||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("No extras passed! Panic!");
|
throw new IllegalStateException("No extras passed! Panic!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onProgress(getString(R.string.status_wallet_loading));
|
||||||
showProgress();
|
showProgress();
|
||||||
final Handler handler = new Handler();
|
final Handler handler = new Handler();
|
||||||
handler.postDelayed(new Runnable() {
|
handler.postDelayed(new Runnable() {
|
||||||
@ -75,7 +81,11 @@ public class WalletActivity extends AppCompatActivity
|
|||||||
onProgress(10); // look like we are working!
|
onProgress(10); // look like we are working!
|
||||||
}
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
//Log.d(TAG, "onStart() done.");
|
}
|
||||||
|
|
||||||
|
private void stopWalletService() {
|
||||||
|
releaseWakeLock();
|
||||||
|
disconnectWalletService();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String title = null;
|
private String title = null;
|
||||||
@ -95,15 +105,13 @@ public class WalletActivity extends AppCompatActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
Log.d(TAG, "onStop()");
|
Log.d(TAG, "onStop()");
|
||||||
releaseWakeLock();
|
|
||||||
disconnectWalletService();
|
|
||||||
this.synced = false;
|
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
Log.d(TAG, "onDestroy()");
|
Log.d(TAG, "onDestroy()");
|
||||||
|
stopWalletService();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +137,7 @@ public class WalletActivity extends AppCompatActivity
|
|||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
setTitle(getString(R.string.status_wallet_loading));
|
setTitle(getString(R.string.status_wallet_loading));
|
||||||
|
startWalletService();
|
||||||
//Log.d(TAG, "onCreate() done.");
|
//Log.d(TAG, "onCreate() done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,33 +145,34 @@ public class WalletActivity extends AppCompatActivity
|
|||||||
private boolean synced = false;
|
private boolean synced = false;
|
||||||
|
|
||||||
private void updateStatus(Wallet wallet) {
|
private void updateStatus(Wallet wallet) {
|
||||||
|
Log.d(TAG, "updateStatus()");
|
||||||
setActivityTitle(wallet);
|
setActivityTitle(wallet);
|
||||||
final TextView balanceView = (TextView) findViewById(R.id.tvBalance);
|
final TextView balanceView = (TextView) findViewById(R.id.tvBalance);
|
||||||
final TextView unlockedView = (TextView) findViewById(R.id.tvUnlockedBalance);
|
final TextView unlockedView = (TextView) findViewById(R.id.tvUnlockedBalance);
|
||||||
final TextView syncProgressView = (TextView) findViewById(R.id.tvBlockHeightProgress);
|
final TextView syncProgressView = (TextView) findViewById(R.id.tvBlockHeightProgress);
|
||||||
final TextView connectionStatusView = (TextView) findViewById(R.id.tvConnectionStatus);
|
final TextView connectionStatusView = (TextView) findViewById(R.id.tvConnectionStatus);
|
||||||
|
|
||||||
//Wallet wallet = getWallet();
|
|
||||||
balanceView.setText(Wallet.getDisplayAmount(wallet.getBalance()));
|
balanceView.setText(Wallet.getDisplayAmount(wallet.getBalance()));
|
||||||
unlockedView.setText(Wallet.getDisplayAmount(wallet.getUnlockedBalance()));
|
unlockedView.setText(Wallet.getDisplayAmount(wallet.getUnlockedBalance()));
|
||||||
String sync = "";
|
String sync = "";
|
||||||
// TODO: getConnectionStatus() blocks as it tries to connect - this is bad in the UI thread!
|
if (mBoundService == null) throw new IllegalStateException("WalletService not bound.");
|
||||||
if (wallet.getConnectionStatus() == Wallet.ConnectionStatus.ConnectionStatus_Connected) {
|
Wallet.ConnectionStatus daemonConnected = mBoundService.getConnectionStatus();
|
||||||
|
if (daemonConnected == Wallet.ConnectionStatus.ConnectionStatus_Connected) {
|
||||||
|
long daemonHeight = mBoundService.getDaemonHeight();
|
||||||
if (!wallet.isSynchronized()) {
|
if (!wallet.isSynchronized()) {
|
||||||
long n = wallet.getDaemonBlockChainHeight() - wallet.getBlockChainHeight();
|
long n = daemonHeight - wallet.getBlockChainHeight();
|
||||||
sync = n + " " + getString(R.string.status_remaining);
|
sync = n + " " + getString(R.string.status_remaining);
|
||||||
if (firstBlock == 0) {
|
if (firstBlock == 0) {
|
||||||
firstBlock = wallet.getBlockChainHeight();
|
firstBlock = wallet.getBlockChainHeight();
|
||||||
}
|
}
|
||||||
int x = 100 - Math.round(100f * n / (1f * wallet.getDaemonBlockChainHeight() - firstBlock));
|
int x = 100 - Math.round(100f * n / (1f * daemonHeight - firstBlock));
|
||||||
//Log.d(TAG, n + "/" + (wallet.getDaemonBlockChainHeight() - firstBlock));
|
|
||||||
onProgress(getString(R.string.status_syncing) + " " + sync);
|
onProgress(getString(R.string.status_syncing) + " " + sync);
|
||||||
|
if (x == 0) x = -1;
|
||||||
onProgress(x);
|
onProgress(x);
|
||||||
} else {
|
} else {
|
||||||
sync = getString(R.string.status_synced) + ": " + wallet.getBlockChainHeight();
|
sync = getString(R.string.status_synced) + ": " + wallet.getBlockChainHeight();
|
||||||
if (!synced) {
|
if (!synced) {
|
||||||
hideProgress();
|
hideProgress();
|
||||||
saveWallet(); // save ONLY on first sync
|
saveWallet(); // save on first sync
|
||||||
// the usual use case is:
|
// the usual use case is:
|
||||||
// open the wallet, wait for sync, check balance, close app
|
// open the wallet, wait for sync, check balance, close app
|
||||||
// even if we wait for new transactions, they will be synced and saved next time
|
// even if we wait for new transactions, they will be synced and saved next time
|
||||||
@ -174,7 +184,7 @@ public class WalletActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
String net = (wallet.isTestNet() ? getString(R.string.connect_testnet) : getString(R.string.connect_mainnet));
|
String net = (wallet.isTestNet() ? getString(R.string.connect_testnet) : getString(R.string.connect_mainnet));
|
||||||
syncProgressView.setText(sync);
|
syncProgressView.setText(sync);
|
||||||
connectionStatusView.setText(net + " " + wallet.getConnectionStatus().toString().substring(17));
|
connectionStatusView.setText(net + " " + daemonConnected.toString().substring(17));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -364,7 +374,12 @@ public class WalletActivity extends AppCompatActivity
|
|||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
ProgressBar progress = (ProgressBar) findViewById(R.id.pbProgress);
|
ProgressBar progress = (ProgressBar) findViewById(R.id.pbProgress);
|
||||||
progress.setProgress(n);
|
if (n >= 0) {
|
||||||
|
progress.setIndeterminate(false);
|
||||||
|
progress.setProgress(n);
|
||||||
|
} else {
|
||||||
|
progress.setIndeterminate(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import android.os.Looper;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.R;
|
import com.m2049r.xmrwallet.R;
|
||||||
import com.m2049r.xmrwallet.model.Wallet;
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
@ -97,15 +98,27 @@ public class WalletService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long lastBlockTime = 0;
|
long lastBlockTime = 0;
|
||||||
|
int lastTxCount = 0;
|
||||||
|
|
||||||
public void newBlock(long height) {
|
public void newBlock(long height) {
|
||||||
if (wallet == null) throw new IllegalStateException("No wallet!");
|
if (wallet == null) throw new IllegalStateException("No wallet!");
|
||||||
// don't flood with an update for every block ...
|
// don't flood with an update for every block ...
|
||||||
if (lastBlockTime < System.currentTimeMillis() - 2000) {
|
if (lastBlockTime < System.currentTimeMillis() - 2000) {
|
||||||
Log.d(TAG, "newBlock() @" + height + "with observer " + observer);
|
Log.d(TAG, "newBlock() @" + height + " with observer " + observer);
|
||||||
lastBlockTime = System.currentTimeMillis();
|
lastBlockTime = System.currentTimeMillis();
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
observer.onRefreshed(wallet, false);
|
boolean fullRefresh = false;
|
||||||
|
updateDaemonState(wallet, wallet.isSynchronized() ? height : 0);
|
||||||
|
if (!wallet.isSynchronized()) {
|
||||||
|
// we want to see our transactions as they come in
|
||||||
|
wallet.getHistory().refresh();
|
||||||
|
int txCount = wallet.getHistory().getCount();
|
||||||
|
if (txCount > lastTxCount) {
|
||||||
|
lastTxCount = txCount;
|
||||||
|
fullRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
observer.onRefreshed(wallet, fullRefresh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,9 +131,10 @@ public class WalletService extends Service {
|
|||||||
|
|
||||||
public void refreshed() {
|
public void refreshed() {
|
||||||
if (wallet == null) throw new IllegalStateException("No wallet!");
|
if (wallet == null) throw new IllegalStateException("No wallet!");
|
||||||
Log.d(TAG, "refreshed() " + wallet.getBalance() + " sync=" + wallet.isSynchronized() + "with observer " + observer);
|
Log.d(TAG, "refreshed() " + wallet.getBalance() + " sync=" + wallet.isSynchronized() + " with observer " + observer);
|
||||||
if (updated) {
|
if (updated) {
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
|
updateDaemonState(wallet, 0);
|
||||||
wallet.getHistory().refresh();
|
wallet.getHistory().refresh();
|
||||||
observer.onRefreshed(wallet, true);
|
observer.onRefreshed(wallet, true);
|
||||||
updated = false;
|
updated = false;
|
||||||
@ -129,6 +143,42 @@ public class WalletService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long lastDaemonStatusUpdate = 0;
|
||||||
|
private long daemonHeight = 0;
|
||||||
|
private Wallet.ConnectionStatus connectionStatus = Wallet.ConnectionStatus.ConnectionStatus_Disconnected;
|
||||||
|
private static final long STATUS_UPDATE_INTERVAL = 120000; // 120s (blocktime)
|
||||||
|
|
||||||
|
private void updateDaemonState(Wallet wallet, long height) {
|
||||||
|
long t = System.currentTimeMillis();
|
||||||
|
if (height > 0) { // if we get a height, we are connected
|
||||||
|
daemonHeight = height;
|
||||||
|
connectionStatus = Wallet.ConnectionStatus.ConnectionStatus_Connected;
|
||||||
|
lastDaemonStatusUpdate = t;
|
||||||
|
} else {
|
||||||
|
if (t - lastDaemonStatusUpdate > STATUS_UPDATE_INTERVAL) {
|
||||||
|
lastDaemonStatusUpdate = t;
|
||||||
|
// these calls really connect to the daemon - wasting time
|
||||||
|
daemonHeight = wallet.getDaemonBlockChainHeight();
|
||||||
|
if (daemonHeight > 0) {
|
||||||
|
// if we get a valid height, the obviously we are connected
|
||||||
|
connectionStatus = Wallet.ConnectionStatus.ConnectionStatus_Connected;
|
||||||
|
} else {
|
||||||
|
// TODO: or connectionStatus = wallet.getConnectionStatus(); ?
|
||||||
|
connectionStatus = Wallet.ConnectionStatus.ConnectionStatus_Disconnected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Log.d(TAG, "updated daemon status: " + daemonHeight + "/" + connectionStatus.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDaemonHeight() {
|
||||||
|
return this.daemonHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Wallet.ConnectionStatus getConnectionStatus() {
|
||||||
|
return this.connectionStatus;
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
// communication back to client (activity) //
|
// communication back to client (activity) //
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
@ -296,12 +346,18 @@ public class WalletService extends Service {
|
|||||||
listener.start();
|
listener.start();
|
||||||
showProgress(95);
|
showProgress(95);
|
||||||
}
|
}
|
||||||
Log.d(TAG, "start() done");
|
Log.d(TAG, "start() notify obeserver first time");
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
Wallet myWallet = getWallet();
|
Wallet myWallet = getWallet();
|
||||||
|
showProgress(getString(R.string.status_wallet_connecting));
|
||||||
|
showProgress(-1);
|
||||||
|
updateDaemonState(myWallet, 0);
|
||||||
myWallet.getHistory().refresh();
|
myWallet.getHistory().refresh();
|
||||||
observer.onRefreshed(myWallet, true);
|
if (observer != null) { // TODO this could still happen - need to sync threads
|
||||||
|
observer.onRefreshed(myWallet, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Log.d(TAG, "start() done");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
@ -309,8 +365,13 @@ public class WalletService extends Service {
|
|||||||
setObserver(null); // in case it was not reset already
|
setObserver(null); // in case it was not reset already
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.stop();
|
listener.stop();
|
||||||
|
Wallet myWallet = getWallet();
|
||||||
|
// if (!myWallet.isSynchronized()) { // save only if NOT synced (to continue later)
|
||||||
|
// Log.d(TAG, "stop() saving");
|
||||||
|
// myWallet.store();
|
||||||
|
// }
|
||||||
Log.d(TAG, "stop() closing");
|
Log.d(TAG, "stop() closing");
|
||||||
listener.getWallet().close();
|
myWallet.close();
|
||||||
Log.d(TAG, "stop() closed");
|
Log.d(TAG, "stop() closed");
|
||||||
listener = null;
|
listener = null;
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
<string name="status_walletlist_loading">Loading Wallet List</string>
|
<string name="status_walletlist_loading">Loading Wallet List</string>
|
||||||
<string name="status_wallet_loading">Loading Wallet …</string>
|
<string name="status_wallet_loading">Loading Wallet …</string>
|
||||||
<string name="status_wallet_unloading">Saving Wallet</string>
|
<string name="status_wallet_unloading">Saving Wallet</string>
|
||||||
|
<string name="status_wallet_connecting">Connecting …</string>
|
||||||
<string name="prompt_password">Password for</string>
|
<string name="prompt_password">Password for</string>
|
||||||
<string name="bad_password">Bad password!</string>
|
<string name="bad_password">Bad password!</string>
|
||||||
<string name="prompt_daemon_missing">Daemon address must be set!</string>
|
<string name="prompt_daemon_missing">Daemon address must be set!</string>
|
||||||
<string name="prompt_wrong_net">Daemon type does not fit to wallet!</string>
|
<string name="prompt_wrong_net">Daemon type does not fit to wallet!</string>
|
||||||
<string name="warn_daemon_unavailable">Warning: cannot reach daemon!</string>
|
<string name="warn_daemon_unavailable">Cannot connect to daemon!</string>
|
||||||
<string name="panic">Something\'s wrong!</string>
|
<string name="panic">Something\'s wrong!</string>
|
||||||
|
|
||||||
<string name="title_amount">Amount</string>
|
<string name="title_amount">Amount</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user