Loading src/com/android/launcher3/config/FeatureFlags.java +15 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.config; import android.content.Context; import android.content.SharedPreferences; import com.android.launcher3.BuildConfig; import com.android.launcher3.Utilities; Loading Loading @@ -343,7 +344,15 @@ public final class FeatureFlags { for (DebugFlag flag : sDebugFlags) { flag.initialize(context); } sDebugFlags.sort((f1, f2) -> f1.key.compareToIgnoreCase(f2.key)); sDebugFlags.sort((f1, f2) -> { // Sort first by any prefs that the user has changed, then alphabetically. int changeComparison = Boolean.compare(f2.mHasBeenChangedAtLeastOnce, f1.mHasBeenChangedAtLeastOnce); return changeComparison != 0 ? changeComparison : f1.key.compareToIgnoreCase(f2.key); }); } } Loading Loading @@ -399,6 +408,7 @@ public final class FeatureFlags { public static class DebugFlag extends BooleanFlag { public final String description; protected boolean mHasBeenChangedAtLeastOnce; protected boolean mCurrentValue; public DebugFlag(String key, boolean defaultValue, String description) { Loading @@ -416,8 +426,10 @@ public final class FeatureFlags { } public void initialize(Context context) { mCurrentValue = context.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE) .getBoolean(key, defaultValue); SharedPreferences prefs = context.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE); mHasBeenChangedAtLeastOnce = prefs.contains(key); mCurrentValue = prefs.getBoolean(key, defaultValue); } @Override Loading src/com/android/launcher3/config/FlagTogglerPrefUi.java +8 −3 Original line number Diff line number Diff line Loading @@ -52,12 +52,17 @@ public final class FlagTogglerPrefUi { public void putBoolean(String key, boolean value) { for (DebugFlag flag : FeatureFlags.getDebugFlags()) { if (flag.key.equals(key)) { SharedPreferences.Editor editor = mContext.getSharedPreferences( FLAGS_PREF_NAME, Context.MODE_PRIVATE).edit(); if (value == flag.defaultValue) { SharedPreferences prefs = mContext.getSharedPreferences( FLAGS_PREF_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); // We keep the key in the prefs even if it has the default value, because it's a // signal that it has been changed at one point. if (!prefs.contains(key) && value == flag.defaultValue) { editor.remove(key).apply(); flag.mHasBeenChangedAtLeastOnce = false; } else { editor.putBoolean(key, value).apply(); flag.mHasBeenChangedAtLeastOnce = true; } updateMenu(); } Loading Loading
src/com/android/launcher3/config/FeatureFlags.java +15 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.config; import android.content.Context; import android.content.SharedPreferences; import com.android.launcher3.BuildConfig; import com.android.launcher3.Utilities; Loading Loading @@ -343,7 +344,15 @@ public final class FeatureFlags { for (DebugFlag flag : sDebugFlags) { flag.initialize(context); } sDebugFlags.sort((f1, f2) -> f1.key.compareToIgnoreCase(f2.key)); sDebugFlags.sort((f1, f2) -> { // Sort first by any prefs that the user has changed, then alphabetically. int changeComparison = Boolean.compare(f2.mHasBeenChangedAtLeastOnce, f1.mHasBeenChangedAtLeastOnce); return changeComparison != 0 ? changeComparison : f1.key.compareToIgnoreCase(f2.key); }); } } Loading Loading @@ -399,6 +408,7 @@ public final class FeatureFlags { public static class DebugFlag extends BooleanFlag { public final String description; protected boolean mHasBeenChangedAtLeastOnce; protected boolean mCurrentValue; public DebugFlag(String key, boolean defaultValue, String description) { Loading @@ -416,8 +426,10 @@ public final class FeatureFlags { } public void initialize(Context context) { mCurrentValue = context.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE) .getBoolean(key, defaultValue); SharedPreferences prefs = context.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE); mHasBeenChangedAtLeastOnce = prefs.contains(key); mCurrentValue = prefs.getBoolean(key, defaultValue); } @Override Loading
src/com/android/launcher3/config/FlagTogglerPrefUi.java +8 −3 Original line number Diff line number Diff line Loading @@ -52,12 +52,17 @@ public final class FlagTogglerPrefUi { public void putBoolean(String key, boolean value) { for (DebugFlag flag : FeatureFlags.getDebugFlags()) { if (flag.key.equals(key)) { SharedPreferences.Editor editor = mContext.getSharedPreferences( FLAGS_PREF_NAME, Context.MODE_PRIVATE).edit(); if (value == flag.defaultValue) { SharedPreferences prefs = mContext.getSharedPreferences( FLAGS_PREF_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); // We keep the key in the prefs even if it has the default value, because it's a // signal that it has been changed at one point. if (!prefs.contains(key) && value == flag.defaultValue) { editor.remove(key).apply(); flag.mHasBeenChangedAtLeastOnce = false; } else { editor.putBoolean(key, value).apply(); flag.mHasBeenChangedAtLeastOnce = true; } updateMenu(); } Loading