]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileThemedActivity.java
(unsuccessful) attempt to avoid black flicker when switching profiles
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / ProfileThemedActivity.java
index a1beb94be914565384fd5dfa33b8b003586412a6..b9726492844cfd959cb208ae6258a423fb1ebd52 100644 (file)
 package net.ktnx.mobileledger.ui.activity;
 
 import android.annotation.SuppressLint;
-import android.os.AsyncTask;
 import android.os.Bundle;
 
 import androidx.annotation.Nullable;
 
 import net.ktnx.mobileledger.App;
+import net.ktnx.mobileledger.dao.BaseDAO;
 import net.ktnx.mobileledger.dao.ProfileDAO;
 import net.ktnx.mobileledger.db.DB;
 import net.ktnx.mobileledger.db.Profile;
@@ -57,8 +57,11 @@ public class ProfileThemedActivity extends CrashReportingActivity {
         Colors.setupTheme(this, mThemeHue);
 
         if (themeSetUp) {
-            Logger.debug(TAG, "setupProfileColors(): theme already set up, recreating activity");
-            this.recreate();
+            Logger.debug(TAG,
+                    "setupProfileColors(): theme already set up, supposedly the activity will be " +
+                    "recreated");
+//            this.recreate();
+            return;
         }
         themeSetUp = true;
 
@@ -75,15 +78,17 @@ public class ProfileThemedActivity extends CrashReportingActivity {
         Data.observeProfile(this, profile -> {
             if (profile == null) {
                 Logger.debug(TAG, "No current profile, leaving");
-                finish();
                 return;
             }
 
             mProfile = profile;
+            storeProfilePref(profile);
             int hue = profile.getTheme();
 
             if (hue != mThemeHue) {
-                storeProfilePref(profile);
+                Logger.debug(TAG,
+                        String.format(Locale.US, "profile observer calling setupProfileColors(%d)",
+                                hue));
                 setupProfileColors(hue);
             }
         });
@@ -99,14 +104,17 @@ public class ProfileThemedActivity extends CrashReportingActivity {
         if (profileId == -1)
             mThemeHue = Colors.DEFAULT_HUE_DEG;
 
+        Logger.debug(TAG,
+                String.format(Locale.US, "initProfile() calling setupProfileColors(%d)", hue));
         setupProfileColors(hue);
 
         initProfile(profileId);
     }
     protected void initProfile(long profileId) {
-        AsyncTask.execute(() -> initProfileAsync(profileId));
+        BaseDAO.runAsync(() -> initProfileSync(profileId));
     }
-    private void initProfileAsync(long profileId) {
+    private void initProfileSync(long profileId) {
+        Logger.debug(TAG, String.format(Locale.US, "Loading profile %d", profileId));
         ProfileDAO dao = DB.get()
                            .getProfileDAO();
         Profile profile = dao.getByIdSync(profileId);
@@ -118,7 +126,10 @@ public class ProfileThemedActivity extends CrashReportingActivity {
             profile = dao.getAnySync();
         }
 
-        Logger.debug(TAG, String.format(Locale.ROOT, "Profile %d loaded. posting", profileId));
+        if (profile == null)
+            Logger.debug(TAG, "No profile could be loaded");
+        else
+            Logger.debug(TAG, String.format(Locale.ROOT, "Profile %d loaded. posting", profileId));
         Data.postCurrentProfile(profile);
     }
 }