UI bugfixes (#120)

* better wallet load progress

new version

* dont start LoginFragment if is already started
This commit is contained in:
m2049r 2017-11-08 23:04:01 +01:00 committed by GitHub
parent f5ad07c2b0
commit 347123d961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 36 deletions

View File

@ -8,8 +8,8 @@ android {
applicationId "com.m2049r.xmrwallet"
minSdkVersion 21
targetSdkVersion 25
versionCode 42
versionName "1.2.2"
versionCode 44
versionName "1.2.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {

View File

@ -293,5 +293,6 @@ public class GenerateReviewFragment extends Fragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.wallet_details_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
}

View File

@ -132,7 +132,7 @@ public class LoginActivity extends AppCompatActivity
});
if (Helper.getWritePermission(this)) {
startLoginFragment();
if (savedInstanceState == null) startLoginFragment();
} else {
Log.i(TAG, "Waiting for permissions");
}

View File

@ -36,8 +36,8 @@ import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;
import com.m2049r.xmrwallet.dialog.HelpFragment;
import com.m2049r.xmrwallet.dialog.DonationFragment;
import com.m2049r.xmrwallet.dialog.HelpFragment;
import com.m2049r.xmrwallet.layout.Toolbar;
import com.m2049r.xmrwallet.model.PendingTransaction;
import com.m2049r.xmrwallet.model.TransactionInfo;
@ -223,7 +223,7 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
Fragment walletFragment = new WalletFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, walletFragment).commit();
.add(R.id.fragment_container, walletFragment, WalletFragment.TAG).commit();
Log.d(TAG, "fragment added");
startWalletService();
@ -389,12 +389,12 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
Log.d(TAG, "onRefreshed()");
try {
final WalletFragment walletFragment = (WalletFragment)
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
getSupportFragmentManager().findFragmentByTag(WalletFragment.TAG);
if (wallet.isSynchronized()) {
Log.d(TAG, "onRefreshed() synced");
releaseWakeLock(); // the idea is to stay awake until synced
if (!synced) {
onProgress(null);
if (!synced) { // first sync
onProgress(-1);
saveWallet(); // save on first sync
synced = true;
runOnUiThread(new Runnable() {
@ -523,10 +523,10 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
public void onProgress(final String text) {
try {
final WalletFragment walletFragment = (WalletFragment)
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
getSupportFragmentManager().findFragmentByTag(WalletFragment.TAG);
runOnUiThread(new Runnable() {
public void run() {
walletFragment.onProgress(text);
walletFragment.setProgress(text);
}
});
} catch (ClassCastException ex) {
@ -540,10 +540,10 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
public void onProgress(final int n) {
try {
final WalletFragment walletFragment = (WalletFragment)
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
getSupportFragmentManager().findFragmentByTag(WalletFragment.TAG);
runOnUiThread(new Runnable() {
public void run() {
walletFragment.onProgress(n);
walletFragment.setProgress(n);
}
});
} catch (ClassCastException ex) {

View File

@ -49,7 +49,7 @@ import java.util.List;
public class WalletFragment extends Fragment
implements TransactionInfoAdapter.OnInteractionListener,
AsyncExchangeRate.Listener {
private static final String TAG = "WalletFragment";
public static final String TAG = "WalletFragment";
private TransactionInfoAdapter adapter;
private NumberFormat formatter = NumberFormat.getInstance();
@ -258,27 +258,26 @@ public class WalletFragment extends Fragment
}
}
public void setProgressText(final String text) {
private String syncText = null;
public void setProgress(final String text) {
syncText = text;
tvProgress.setText(text);
}
public void onProgress(final String text) {
if (text != null) {
setProgressText(text);
pbProgress.setVisibility(View.VISIBLE);
} else {
pbProgress.setVisibility(View.INVISIBLE);
setProgressText(getString(R.string.status_working));
onProgress(-1);
}
}
private int syncProgress = -1;
public void onProgress(final int n) {
if (n >= 0) {
public void setProgress(final int n) {
syncProgress = n;
if (n > 100) {
pbProgress.setIndeterminate(true);
pbProgress.setVisibility(View.VISIBLE);
} else if (n >= 0) {
pbProgress.setIndeterminate(false);
pbProgress.setProgress(n);
} else {
pbProgress.setIndeterminate(true);
pbProgress.setVisibility(View.VISIBLE);
} else { // <0
pbProgress.setVisibility(View.INVISIBLE);
}
}
@ -301,7 +300,6 @@ public class WalletFragment extends Fragment
Log.d(TAG, "updateStatus()");
if (walletTitle == null) {
setActivityTitle(wallet);
onProgress(100); // of loading
}
long balance = wallet.getBalance();
unlockedBalance = wallet.getUnlockedBalance();
@ -309,8 +307,6 @@ public class WalletFragment extends Fragment
double amountXmr = Double.parseDouble(Helper.getDisplayAmount(balance - unlockedBalance)); // assume this cannot fail!
String unconfirmed = Helper.getFormattedAmount(amountXmr, true);
tvUnconfirmedAmount.setText(getResources().getString(R.string.xmr_unconfirmed_amount, unconfirmed));
//tvUnconfirmedAmount.setText(getResources().getString(R.string.xmr_unconfirmed_amount,
// Helper.getDisplayAmount(balance - unlockedBalance, Helper.DISPLAY_DIGITS_SHORT)));
String sync = "";
if (!activityCallback.hasBoundService())
throw new IllegalStateException("WalletService not bound.");
@ -324,16 +320,18 @@ public class WalletFragment extends Fragment
firstBlock = wallet.getBlockChainHeight();
}
int x = 100 - Math.round(100f * n / (1f * daemonHeight - firstBlock));
//onProgress(getString(R.string.status_syncing) + " " + sync);
if (x == 0) x = -1;
onProgress(x);
if (x == 0) x = 101; // indeterminate
setProgress(x);
ivSynced.setVisibility(View.GONE);
} else {
sync = getString(R.string.status_synced) + formatter.format(wallet.getBlockChainHeight());
ivSynced.setVisibility(View.VISIBLE);
}
} else {
sync = getString(R.string.status_wallet_connecting);
setProgress(101);
}
setProgressText(sync);
setProgress(sync);
// TODO show connected status somewhere
}
@ -387,6 +385,8 @@ public class WalletFragment extends Fragment
Log.d(TAG, "onResume()");
activityCallback.setTitle(walletTitle, walletSubtitle);
activityCallback.setToolbarButton(Toolbar.BUTTON_CLOSE);
setProgress(syncProgress);
setProgress(syncText);
showReceive();
}
}

View File

@ -481,7 +481,7 @@ public class WalletService extends Service {
showProgress(100);
}
showProgress(getString(R.string.status_wallet_connecting));
showProgress(-1);
showProgress(101);
// if we try to refresh the history here we get occasional segfaults!
// doesnt matter since we update as soon as we get a new block anyway
Log.d(TAG, "start() done");