]> git.ktnx.net Git - mobile-ledger.git/commitdiff
better handling of theme change
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 28 Dec 2020 12:16:21 +0000 (14:16 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 28 Dec 2020 15:52:19 +0000 (15:52 +0000)
was broken if the theme is changed via the profile editor invoked by
the "configure profile" button in the new transaction activity

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

index 370c5e2b6e95ab905dd80804df7c3ae238a56b36..f2615937d7c9f922b9c31fc733a85d0a66128956 100644 (file)
@@ -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();
index 745e888a03f40b3fa5bdd319c1c160ed313793c0..64d84ef0178fde10e8d4c64e6edb923c3647e352 100644 (file)
@@ -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);