forked from upstream-mirrors/quik
Allow exclusion of prefers from automatically calling refresh in LiveViewManager
This commit is contained in:
@@ -6,6 +6,7 @@ import android.preference.PreferenceManager;
|
|||||||
import com.moez.QKSMS.common.preferences.QKPreference;
|
import com.moez.QKSMS.common.preferences.QKPreference;
|
||||||
import com.moez.QKSMS.interfaces.LiveView;
|
import com.moez.QKSMS.interfaces.LiveView;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -29,8 +30,18 @@ import java.util.WeakHashMap;
|
|||||||
public abstract class LiveViewManager {
|
public abstract class LiveViewManager {
|
||||||
private static final String TAG = "LiveViewManager";
|
private static final String TAG = "LiveViewManager";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps all of the LiveViews to their associated preference
|
||||||
|
*/
|
||||||
private static final HashMap<String, WeakHashMap<Object, Set<LiveView>>> sViews = new HashMap<>();
|
private static final HashMap<String, WeakHashMap<Object, Set<LiveView>>> sViews = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of preferences to be excluded from LiveView refreshing when the preference changes
|
||||||
|
*/
|
||||||
|
private static final HashSet<String> sExcludedPrefs = new HashSet<>(Arrays.asList(
|
||||||
|
QKPreference.THEME.getKey()
|
||||||
|
));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize preferences and register a listener for changes
|
* Initialize preferences and register a listener for changes
|
||||||
*
|
*
|
||||||
@@ -38,7 +49,11 @@ public abstract class LiveViewManager {
|
|||||||
*/
|
*/
|
||||||
public static void init(Context context) {
|
public static void init(Context context) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> refreshViews(key));
|
prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> {
|
||||||
|
if (!sExcludedPrefs.contains(key)) {
|
||||||
|
refreshViews(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -622,21 +622,17 @@ public class ThemeManager {
|
|||||||
mTextOnColorSecondary = mResources.getColor(isColorDarkEnough(mColor) ?
|
mTextOnColorSecondary = mResources.getColor(isColorDarkEnough(mColor) ?
|
||||||
R.color.theme_dark_text_secondary : R.color.theme_light_text_secondary);
|
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);
|
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colourFrom, color);
|
||||||
colorAnimation.setDuration(TRANSITION_LENGTH);
|
colorAnimation.setDuration(TRANSITION_LENGTH);
|
||||||
colorAnimation.setInterpolator(new DecelerateInterpolator());
|
colorAnimation.setInterpolator(new DecelerateInterpolator());
|
||||||
colorAnimation.addUpdateListener(animation -> {
|
colorAnimation.addUpdateListener(animation -> {
|
||||||
int color1 = (Integer) animation.getAnimatedValue();
|
mActiveColor = (Integer) animation.getAnimatedValue();
|
||||||
|
|
||||||
if (mStatusTintEnabled) {
|
if (mStatusTintEnabled) {
|
||||||
mWindow.setStatusBarColor(ColorUtils.darken(color1));
|
mWindow.setStatusBarColor(ColorUtils.darken(mActiveColor));
|
||||||
}
|
}
|
||||||
if (mNavigationTintEnabled) {
|
if (mNavigationTintEnabled) {
|
||||||
mWindow.setNavigationBarColor(ColorUtils.darken(color1));
|
mWindow.setNavigationBarColor(ColorUtils.darken(mActiveColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveViewManager.refreshViews(QKPreference.THEME);
|
LiveViewManager.refreshViews(QKPreference.THEME);
|
||||||
|
|||||||
Reference in New Issue
Block a user