From aab4c009a95d371354f14685152b275812d60a15 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 19 Oct 2019 16:17:16 +0300 Subject: [PATCH] ProfileThemedActivity: load profile from options if none is loaded yet This may happen if the app is removed from memory while the new transaction activity is active; when the app is started later it goes straight to the new transaction activity and there is no profile loaded from the options db in the normal startup the main activity is first and it loads the profile. Another way to start the new transaction activity without passing via the main activity is through the app shortcuts --- .../ui/activity/ProfileThemedActivity.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileThemedActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileThemedActivity.java index 079e0df6..821d186d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileThemedActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileThemedActivity.java @@ -23,11 +23,14 @@ import android.os.Bundle; 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; import androidx.annotation.Nullable; @SuppressLint("Registered") public class ProfileThemedActivity extends CrashReportingActivity { + static final int waitSlice = 200; protected MobileLedgerProfile mProfile; protected void setupProfileColors() { Colors.setupTheme(this, mProfile); @@ -40,9 +43,24 @@ public class ProfileThemedActivity extends CrashReportingActivity { protected void onCreate(@Nullable Bundle savedInstanceState) { initProfile(); super.onCreate(savedInstanceState); - setupProfileColors(); + Data.profile.observe(this, mobileLedgerProfile -> { + mProfile = mobileLedgerProfile; + setupProfileColors(); + }); } 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; + + + startupProfile = Data.getProfile(profileUUID); + Data.setCurrentProfile(startupProfile); + } + }); + } } } -- 2.39.2