Commit 69dbcdd3 authored by Bernhard Bauer's avatar Bernhard Bauer Committed by Commit Bot

Avoid ContentSettingsType roundtrip when creating SiteSettingsCategory from preference key

The USE_STORAGE category type can't be represented as a
ContentSettingsType, which would make the UI fall back to displaying
all categories.

Bug: 856110
Change-Id: I434742d9fd330e4ff78f4ce69655da67a050e310
Reviewed-on: https://chromium-review.googlesource.com/1162237Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Bernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580573}
parent 65ef9c45
...@@ -255,11 +255,8 @@ public class SingleCategoryPreferences extends PreferenceFragment ...@@ -255,11 +255,8 @@ public class SingleCategoryPreferences extends PreferenceFragment
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Read which category we should be showing. // Read which category we should be showing.
if (getArguments() != null) { if (getArguments() != null) {
int contentSettingsType = SiteSettingsCategory.contentSettingsType( mCategory = SiteSettingsCategory.createFromPreferenceKey(
getArguments().getString(EXTRA_CATEGORY, "")); getArguments().getString(EXTRA_CATEGORY, ""));
if (contentSettingsType != -1) {
mCategory = SiteSettingsCategory.createFromContentSettingsType(contentSettingsType);
}
} }
if (mCategory == null) { if (mCategory == null) {
mCategory = SiteSettingsCategory.createFromType(SiteSettingsCategory.Type.ALL_SITES); mCategory = SiteSettingsCategory.createFromType(SiteSettingsCategory.Type.ALL_SITES);
......
...@@ -158,7 +158,8 @@ public class SiteSettingsCategory { ...@@ -158,7 +158,8 @@ public class SiteSettingsCategory {
return new SiteSettingsCategory(type, permission); return new SiteSettingsCategory(type, permission);
} }
public static SiteSettingsCategory createFromContentSettingsType(int contentSettingsType) { public static SiteSettingsCategory createFromContentSettingsType(
@ContentSettingsType int contentSettingsType) {
assert contentSettingsType != -1; assert contentSettingsType != -1;
assert Type.ALL_SITES == 0; assert Type.ALL_SITES == 0;
for (@Type int i = Type.ALL_SITES; i < Type.NUM_ENTRIES; i++) { for (@Type int i = Type.ALL_SITES; i < Type.NUM_ENTRIES; i++) {
...@@ -167,16 +168,12 @@ public class SiteSettingsCategory { ...@@ -167,16 +168,12 @@ public class SiteSettingsCategory {
return null; return null;
} }
/** public static SiteSettingsCategory createFromPreferenceKey(String preferenceKey) {
* Convert preference String into ContentSettingsType or returns -1 assert Type.ALL_SITES == 0;
* when mapping cannot be done. for (@Type int i = Type.ALL_SITES; i < Type.NUM_ENTRIES; i++) {
*/ if (PREFERENCE_KEYS[i].equals(preferenceKey)) return createFromType(i);
public static int contentSettingsType(String preferenceKey) {
if (preferenceKey.isEmpty()) return -1;
for (int i = 0; i < PREFERENCE_KEYS.length; i++) {
if (PREFERENCE_KEYS[i].equals(preferenceKey)) return CONTENT_TYPES[i];
} }
return -1; return null;
} }
/** /**
...@@ -196,7 +193,7 @@ public class SiteSettingsCategory { ...@@ -196,7 +193,7 @@ public class SiteSettingsCategory {
/** /**
* Returns the {@link ContentSettingsType} for this category, or -1 if no such type exists. * Returns the {@link ContentSettingsType} for this category, or -1 if no such type exists.
*/ */
public int getContentSettingsType() { public @ContentSettingsType int getContentSettingsType() {
return CONTENT_TYPES[mCategory]; return CONTENT_TYPES[mCategory];
} }
......
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