Commit 9a91004f authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: float non-default flags to the top of the list

If no flags are toggled, flags are shown in the same order (the order
hardcoded in ProductionSupportedFlagList). If the user has already
toggled some flags (enabled/disabled), these flags float to the top of
the list when the user revisits the UI.

The flag order only moves when we recreate the flag UI. So flags will
stay in the same place as the user interacts with the UI, and only move
as a convenience if they return to the UI and need to go back to
default. This is mostly consistent with chrome://flags (the difference
is that we won't reset the order when the user clicks "reset all to
default," for simplicity and convenience if the user changes their mind
to re-enable some of those flags).

Fixed: 1059478
Test: Manual - verify flags float to the top when I revisit the flag UI
Change-Id: I01cac5e7c38b35be765c3e111f4b0d5ea4e3941f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124532Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754165}
parent 34d2626e
......@@ -86,13 +86,34 @@ public class FlagsFragment extends Fragment {
mOverriddenFlags = DeveloperModeUtils.getFlagOverrides(mContext.getPackageName());
}
mListAdapter = new FlagsListAdapter();
mListAdapter = new FlagsListAdapter(sortFlagList(ProductionSupportedFlagList.sFlagList));
flagsListView.setAdapter(mListAdapter);
Button resetFlagsButton = view.findViewById(R.id.reset_flags_button);
resetFlagsButton.setOnClickListener((View flagButton) -> { resetAllFlags(); });
}
/**
* Sorts the flag list so enabled/disabled flags are at the beginning and default flags are at
* the end.
*/
private Flag[] sortFlagList(Flag[] unsorted) {
Flag[] sortedFlags = new Flag[unsorted.length];
int i = 0;
for (Flag flag : unsorted) {
if (mOverriddenFlags.containsKey(flag.getName())) {
sortedFlags[i++] = flag;
}
}
for (Flag flag : unsorted) {
if (!mOverriddenFlags.containsKey(flag.getName())) {
sortedFlags[i++] = flag;
}
}
assert sortedFlags.length == unsorted.length : "arrays should be same length";
return sortedFlags;
}
private static int booleanToState(Boolean b) {
if (b == null) {
return /* STATE_DEFAULT */ 0;
......@@ -148,8 +169,8 @@ public class FlagsFragment extends Fragment {
* Adapter to create rows of toggleable Flags.
*/
private class FlagsListAdapter extends ArrayAdapter<Flag> {
public FlagsListAdapter() {
super(mContext, R.layout.toggleable_flag, ProductionSupportedFlagList.sFlagList);
public FlagsListAdapter(Flag[] sortedFlags) {
super(mContext, R.layout.toggleable_flag, sortedFlags);
}
@Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment