From c2c809211c8e68d5d99f9393da4fa399400e9292 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Mon, 28 Dec 2020 14:16:21 +0200 Subject: [PATCH] better handling of theme change was broken if the theme is changed via the profile editor invoked by the "configure profile" button in the new transaction activity --- .../ui/activity/MainActivity.java | 6 ------ .../ui/activity/ProfileThemedActivity.java | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 370c5e2b..f2615937 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -129,12 +129,6 @@ public class MainActivity extends ProfileThemedActivity { super.onDestroy(); } @Override - protected void setupProfileColors() { - final int profileColor = Data.retrieveCurrentThemeIdFromDb(); - Colors.setupTheme(this, profileColor); - Colors.profileThemeId = profileColor; - } - @Override protected void onResume() { super.onResume(); fabShouldShow(); 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 745e888a..64d84ef0 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 @@ -29,9 +29,18 @@ import net.ktnx.mobileledger.utils.Colors; @SuppressLint("Registered") public class ProfileThemedActivity extends CrashReportingActivity { protected MobileLedgerProfile mProfile; + private boolean themeSetUp = false; + private boolean mIgnoreProfileChange; protected void setupProfileColors() { final int themeHue = (mProfile == null) ? -1 : mProfile.getThemeHue(); + Colors.setupTheme(this, themeHue); + + if (themeSetUp) + this.recreate(); + themeSetUp = true; + + Colors.profileThemeId = Data.retrieveCurrentThemeIdFromDb(); } @Override protected void onStart() { @@ -41,9 +50,15 @@ public class ProfileThemedActivity extends CrashReportingActivity { protected void onCreate(@Nullable Bundle savedInstanceState) { initProfile(); setupProfileColors(); + + mIgnoreProfileChange = true; Data.observeProfile(this, profile -> { - mProfile = profile; - setupProfileColors(); + if (!mIgnoreProfileChange) { + mProfile = profile; + setupProfileColors(); + } + + mIgnoreProfileChange = false; }); super.onCreate(savedInstanceState); -- 2.39.5