]> git.ktnx.net Git - mobile-ledger.git/commitdiff
ProfileThemedActivity: fetch current profile synchronously
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 10 Nov 2019 09:15:47 +0000 (11:15 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 10 Nov 2019 09:15:47 +0000 (11:15 +0200)
the onCreate method must finish setting up the theme before
returning and giving way to creation of views

if the current profile data comes asynchronously, it may be too late and
some views may have already been created

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

index 3bce79d7da71b98f5b951d7f0dc8b769302aa522..8cfeea0fa0c39189be713682051b3ad4d8eaafde 100644 (file)
@@ -25,7 +25,6 @@ import androidx.annotation.Nullable;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.utils.Colors;
-import net.ktnx.mobileledger.utils.GetOptCallback;
 import net.ktnx.mobileledger.utils.MLDB;
 
 @SuppressLint("Registered")
@@ -43,6 +42,9 @@ public class ProfileThemedActivity extends CrashReportingActivity {
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         initProfile();
         super.onCreate(savedInstanceState);
+
+        setupProfileColors();
+
         Data.profile.observe(this, mobileLedgerProfile -> {
             mProfile = mobileLedgerProfile;
             setupProfileColors();
@@ -51,16 +53,13 @@ public class ProfileThemedActivity extends CrashReportingActivity {
     protected void initProfile() {
         mProfile = Data.profile.getValue();
         if (mProfile == null) {
-            MLDB.getOption(MLDB.OPT_PROFILE_UUID, null, new GetOptCallback() {
-                @Override
-                protected void onResult(String profileUUID) {
-                    MobileLedgerProfile startupProfile;
+            String profileUUID = MLDB.getOption(MLDB.OPT_PROFILE_UUID, null);
+            MobileLedgerProfile startupProfile;
 
 
-                    startupProfile = Data.getProfile(profileUUID);
-                    Data.setCurrentProfile(startupProfile);
-                }
-            });
+            startupProfile = Data.getProfile(profileUUID);
+            Data.setCurrentProfile(startupProfile);
+            mProfile = startupProfile;
         }
     }
 }