From: Damyan Ivanov Date: Sat, 19 Oct 2019 13:17:16 +0000 (+0300) Subject: ProfileThemedActivity: load profile from options if none is loaded yet X-Git-Tag: v0.11.0~98 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=aab4c009a95d371354f14685152b275812d60a15;p=mobile-ledger.git 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 --- 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); + } + }); + } } }