diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java index 13a7d8d3..7031f69f 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java @@ -6,6 +6,7 @@ import android.preference.PreferenceManager; import com.moez.QKSMS.common.preferences.QKPreference; import com.moez.QKSMS.interfaces.LiveView; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -29,8 +30,18 @@ import java.util.WeakHashMap; public abstract class LiveViewManager { private static final String TAG = "LiveViewManager"; + /** + * Maps all of the LiveViews to their associated preference + */ private static final HashMap>> sViews = new HashMap<>(); + /** + * A list of preferences to be excluded from LiveView refreshing when the preference changes + */ + private static final HashSet sExcludedPrefs = new HashSet<>(Arrays.asList( + QKPreference.THEME.getKey() + )); + /** * Initialize preferences and register a listener for changes * @@ -38,7 +49,11 @@ public abstract class LiveViewManager { */ public static void init(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> refreshViews(key)); + prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> { + if (!sExcludedPrefs.contains(key)) { + refreshViews(key); + } + }); } /** diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java index b0424a16..8b3659f5 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -622,21 +622,17 @@ public class ThemeManager { mTextOnColorSecondary = mResources.getColor(isColorDarkEnough(mColor) ? R.color.theme_dark_text_secondary : R.color.theme_light_text_secondary); - // Some views are updated every frame of the animation; get these views here. We - // build this list once beforehand since it's a slightly expensive operation. - LiveViewManager.refreshViews(QKPreference.THEME); - ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colourFrom, color); colorAnimation.setDuration(TRANSITION_LENGTH); colorAnimation.setInterpolator(new DecelerateInterpolator()); colorAnimation.addUpdateListener(animation -> { - int color1 = (Integer) animation.getAnimatedValue(); + mActiveColor = (Integer) animation.getAnimatedValue(); if (mStatusTintEnabled) { - mWindow.setStatusBarColor(ColorUtils.darken(color1)); + mWindow.setStatusBarColor(ColorUtils.darken(mActiveColor)); } if (mNavigationTintEnabled) { - mWindow.setNavigationBarColor(ColorUtils.darken(color1)); + mWindow.setNavigationBarColor(ColorUtils.darken(mActiveColor)); } LiveViewManager.refreshViews(QKPreference.THEME);