X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FMainActivity.java;h=1674c029a45dfda2b525cad2402cca1c235903c3;hb=605837f87d9731e3529fa9be447bbcf7625cb2eb;hp=5efc2f84f386180a930fd24ea7164d8344efd180;hpb=5bba2c06a81c87327fdcf3f2a85c3206d932c2f9;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 5efc2f84..1674c029 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -29,6 +29,7 @@ import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.View; +import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.widget.LinearLayout; import android.widget.ProgressBar; @@ -335,15 +336,15 @@ public class MainActivity extends ProfileThemedActivity { mainModel.clearUpdateError(); }); } - private void scheduleDataRetrievalIfStale(Date lastUpdate) { + private void scheduleDataRetrievalIfStale(long lastUpdate) { long now = new Date().getTime(); - if ((lastUpdate == null) || (now > (lastUpdate.getTime() + (24 * 3600 * 1000)))) { - if (lastUpdate == null) + if ((lastUpdate == 0) || (now > (lastUpdate + (24 * 3600 * 1000)))) { + if (lastUpdate == 0) Logger.debug("db::", "WEB data never fetched. scheduling a fetch"); else Logger.debug("db", String.format(Locale.ENGLISH, "WEB data last fetched at %1.3f and now is %1.3f. re-fetching", - lastUpdate.getTime() / 1000f, now / 1000f)); + lastUpdate / 1000f, now / 1000f)); mainModel.scheduleTransactionListRetrieval(); } @@ -460,7 +461,7 @@ public class MainActivity extends ProfileThemedActivity { updateLastUpdateTextFromDB(); } private void updateLastUpdateDisplay(Date newValue) { - LinearLayout l = findViewById(R.id.transactions_last_update_layout); + ViewGroup l = findViewById(R.id.transactions_last_update_layout); TextView v = findViewById(R.id.transactions_last_update); if (newValue == null) { l.setVisibility(View.INVISIBLE); @@ -473,8 +474,6 @@ public class MainActivity extends ProfileThemedActivity { l.setVisibility(View.VISIBLE); Logger.debug("main", String.format("Date formatted: %s", text)); } - - scheduleDataRetrievalIfStale(newValue); } private void profileThemeChanged() { storeThemeIdInPrefs(profile.getThemeHue()); @@ -580,6 +579,8 @@ public class MainActivity extends ProfileThemedActivity { else { mainModel.lastUpdateDate.postValue(new Date(last_update)); } + scheduleDataRetrievalIfStale(last_update); + } public void onStopTransactionRefreshClick(View view) { Logger.debug("interactive", "Cancelling transactions refresh");