Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit deaff5fb authored by Jon Miranda's avatar Jon Miranda
Browse files

Move feature flags that have been changed to the top of the list.

Bug: 259270717
Test: change flag, check that its at the top of the sorted list
Change-Id: Ib10882e8de625471ef430a2f3162b85f9c6e1c1d
parent 168c204f
Loading
Loading
Loading
Loading
+15 −3
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.launcher3.config;
package com.android.launcher3.config;


import android.content.Context;
import android.content.Context;
import android.content.SharedPreferences;


import com.android.launcher3.BuildConfig;
import com.android.launcher3.BuildConfig;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
@@ -331,7 +332,15 @@ public final class FeatureFlags {
            for (DebugFlag flag : sDebugFlags) {
            for (DebugFlag flag : sDebugFlags) {
                flag.initialize(context);
                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);
            });
        }
        }
    }
    }


@@ -387,6 +396,7 @@ public final class FeatureFlags {
    public static class DebugFlag extends BooleanFlag {
    public static class DebugFlag extends BooleanFlag {


        public final String description;
        public final String description;
        protected boolean mHasBeenChangedAtLeastOnce;
        protected boolean mCurrentValue;
        protected boolean mCurrentValue;


        public DebugFlag(String key, boolean defaultValue, String description) {
        public DebugFlag(String key, boolean defaultValue, String description) {
@@ -404,8 +414,10 @@ public final class FeatureFlags {
        }
        }


        public void initialize(Context context) {
        public void initialize(Context context) {
            mCurrentValue = context.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE)
            SharedPreferences prefs =
                    .getBoolean(key, defaultValue);
                    context.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE);
            mHasBeenChangedAtLeastOnce = prefs.contains(key);
            mCurrentValue = prefs.getBoolean(key, defaultValue);
        }
        }


        @Override
        @Override
+8 −3
Original line number Original line Diff line number Diff line
@@ -52,12 +52,17 @@ public final class FlagTogglerPrefUi {
        public void putBoolean(String key, boolean value) {
        public void putBoolean(String key, boolean value) {
            for (DebugFlag flag : FeatureFlags.getDebugFlags()) {
            for (DebugFlag flag : FeatureFlags.getDebugFlags()) {
                if (flag.key.equals(key)) {
                if (flag.key.equals(key)) {
                    SharedPreferences.Editor editor = mContext.getSharedPreferences(
                    SharedPreferences prefs = mContext.getSharedPreferences(
                            FLAGS_PREF_NAME, Context.MODE_PRIVATE).edit();
                            FLAGS_PREF_NAME, Context.MODE_PRIVATE);
                    if (value == flag.defaultValue) {
                    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();
                        editor.remove(key).apply();
                        flag.mHasBeenChangedAtLeastOnce = false;
                    } else {
                    } else {
                        editor.putBoolean(key, value).apply();
                        editor.putBoolean(key, value).apply();
                        flag.mHasBeenChangedAtLeastOnce = true;
                    }
                    }
                    updateMenu();
                    updateMenu();
                }
                }