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 7031f69f..ef115d4a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java @@ -39,7 +39,8 @@ public abstract class LiveViewManager { * 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() + QKPreference.THEME.getKey(), + QKPreference.BACKGROUND.getKey() )); /** 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 7474e3a8..788a29c4 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ThemeManager.java @@ -16,7 +16,6 @@ import android.os.Build; import android.preference.PreferenceManager; import android.util.Log; import android.view.Gravity; -import android.view.View; import android.view.animation.DecelerateInterpolator; import android.widget.LinearLayout; import com.moez.QKSMS.R; @@ -248,47 +247,27 @@ public class ThemeManager { } public static void setTheme(Theme theme) { - int startColor = mBackgroundColor; + final int startColor = mBackgroundColor; initializeTheme(theme); - int endColor = mBackgroundColor; + final int endColor = mBackgroundColor; - if (mContext instanceof MainActivity) { - final View background = ((MainActivity) mContext).findViewById(R.id.menu_frame).getRootView(); - final View menu = ((MainActivity) mContext).findViewById(R.id.menu_frame); - final View content = ((MainActivity) mContext).findViewById(R.id.content_frame); - final View fragment = ((MainActivity) mContext).getContent().getView(); - - if (startColor != endColor) { - ValueAnimator backgroundAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor); - backgroundAnimation.setDuration(TRANSITION_LENGTH); - backgroundAnimation.addUpdateListener(animation -> { - int color = (Integer) animation.getAnimatedValue(); - if (fragment != null) { - fragment.setBackgroundColor(color); - } - background.setBackgroundColor(color); - menu.setBackgroundColor(color); - content.setBackgroundColor(color); - }); - backgroundAnimation.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - // This updates the colors and fonts of all the views. - LiveViewManager.refreshViews(QKPreference.BACKGROUND); - WidgetProvider.notifyThemeChanged(mContext); - } - }); - backgroundAnimation.start(); - } else { - // This updates the colors and fonts of all the views. + if (startColor != endColor) { + ValueAnimator backgroundAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor); + backgroundAnimation.setDuration(TRANSITION_LENGTH); + backgroundAnimation.addUpdateListener(animation -> { + mBackgroundColor = (Integer) animation.getAnimatedValue(); LiveViewManager.refreshViews(QKPreference.BACKGROUND); - background.setBackgroundColor(endColor); - menu.setBackgroundColor(endColor); - content.setBackgroundColor(endColor); - WidgetProvider.notifyThemeChanged(mContext); - } + }); + backgroundAnimation.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mBackgroundColor = endColor; + LiveViewManager.refreshViews(QKPreference.BACKGROUND); + WidgetProvider.notifyThemeChanged(mContext); + } + }); + backgroundAnimation.start(); } else { - // This updates the colors and fonts of all the views. LiveViewManager.refreshViews(QKPreference.BACKGROUND); WidgetProvider.notifyThemeChanged(mContext); }