]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix first run experience
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 12 Apr 2019 15:11:08 +0000 (18:11 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 12 Apr 2019 15:11:08 +0000 (18:11 +0300)
hide the no profiles screen and show the main screen when the
first profile is created

properly trigger a data retrieval operation
also when the data is stale

app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java

index 905998c20cf66e031a58838d5e41bcd8a9d85aa7..bc164a55333a9d28450a78d346c7720a66e63bee 100644 (file)
@@ -319,8 +319,11 @@ public class MainActivity extends ProfileThemedActivity {
         onProfileChanged(null);
 
         updateLastUpdateTextFromDB();
-        Date lastUpdate = Data.lastUpdateDate.get();
 
+        scheduleDataRetrievalIfStale();
+    }
+    private void scheduleDataRetrievalIfStale() {
+        Date lastUpdate = Data.lastUpdateDate.get();
         long now = new Date().getTime();
         if ((lastUpdate == null) || (now > (lastUpdate.getTime() + (24 * 3600 * 1000)))) {
             if (lastUpdate == null) Log.d("db::", "WEB data never fetched. scheduling a fetch");
@@ -367,6 +370,11 @@ public class MainActivity extends ProfileThemedActivity {
         MobileLedgerProfile profile = Data.profile.get();
         MainActivity.this.runOnUiThread(() -> {
 
+            boolean haveProfile = profile != null;
+            findViewById(R.id.no_profiles_layout).setVisibility(haveProfile ? View.GONE : View.VISIBLE);
+            findViewById(R.id.pager_layout)
+                    .setVisibility(haveProfile ? View.VISIBLE : View.VISIBLE);
+
             Data.transactions.clear();
             Log.d("transactions", "requesting list reload");
             TransactionListViewModel.scheduleTransactionListReload();
@@ -419,6 +427,10 @@ public class MainActivity extends ProfileThemedActivity {
                     fab.hide();
                 }
             }
+
+            updateLastUpdateTextFromDB();
+
+            scheduleDataRetrievalIfStale();
         });
     }
     private void updateLastUpdateDisplay() {