Commit 01f55f58 authored by Jordan Oroshiba's avatar Jordan Oroshiba Committed by Chromium LUCI CQ

Hide the trash icon if there is no storage to be deleted.

Bug: 1152891
Change-Id: I7286e35769fb66f3cc6792d9ae7dc0bfd460b35b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2537774Reviewed-by: default avatarNatalie Chouinard <chouinard@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarLijin Shen <lazzzis@google.com>
Reviewed-by: default avatarEhimare Okoyomon <eokoyomon@chromium.org>
Commit-Queue: Jordan Oroshiba <oroshiba@google.com>
Cr-Commit-Position: refs/heads/master@{#834238}
parent e5938202
...@@ -49,6 +49,8 @@ public class ChromeImageViewPreference extends Preference { ...@@ -49,6 +49,8 @@ public class ChromeImageViewPreference extends Preference {
private int mContentDescriptionRes; private int mContentDescriptionRes;
// Whether the ImageView should be enabled. // Whether the ImageView should be enabled.
private boolean mImageViewEnabled = true; private boolean mImageViewEnabled = true;
// The ImageView Button.
private ImageView mButton;
/** /**
* Constructor for use in Java. * Constructor for use in Java.
...@@ -80,23 +82,13 @@ public class ChromeImageViewPreference extends Preference { ...@@ -80,23 +82,13 @@ public class ChromeImageViewPreference extends Preference {
public void onBindViewHolder(PreferenceViewHolder holder) { public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder); super.onBindViewHolder(holder);
ImageView button = (ImageView) holder.findViewById(R.id.image_view_widget); mButton = (ImageView) holder.findViewById(R.id.image_view_widget);
View view = holder.itemView; mButton.setBackgroundColor(Color.TRANSPARENT);
mButton.setVisibility(View.VISIBLE);
if (mImageRes != 0) { configureImageView();
Drawable buttonImg = SettingsUtils.getTintedIcon(getContext(), mImageRes, mColorRes); ManagedPreferencesUtils.onBindViewToImageViewPreference(
button.setImageDrawable(buttonImg); mManagedPrefDelegate, this, holder.itemView);
button.setBackgroundColor(Color.TRANSPARENT);
button.setVisibility(View.VISIBLE);
button.setEnabled(mImageViewEnabled);
if (mImageViewEnabled) button.setOnClickListener(mListener);
if (mContentDescriptionRes != 0) {
button.setContentDescription(view.getResources().getString(mContentDescriptionRes));
}
}
ManagedPreferencesUtils.onBindViewToImageViewPreference(mManagedPrefDelegate, this, view);
} }
@Override @Override
...@@ -114,6 +106,7 @@ public class ChromeImageViewPreference extends Preference { ...@@ -114,6 +106,7 @@ public class ChromeImageViewPreference extends Preference {
mImageRes = imageRes; mImageRes = imageRes;
mContentDescriptionRes = contentDescriptionRes; mContentDescriptionRes = contentDescriptionRes;
mListener = listener; mListener = listener;
configureImageView();
notifyChanged(); notifyChanged();
} }
...@@ -122,14 +115,20 @@ public class ChromeImageViewPreference extends Preference { ...@@ -122,14 +115,20 @@ public class ChromeImageViewPreference extends Preference {
* @param colorRes * @param colorRes
*/ */
public void setImageColor(@ColorRes int colorRes) { public void setImageColor(@ColorRes int colorRes) {
if (mColorRes == colorRes) return;
mColorRes = colorRes; mColorRes = colorRes;
configureImageView();
} }
/** /**
* Enables/Disables the ImageView, allowing for clicks to pass through (when disabled). * Enables/Disables the ImageView, allowing for clicks to pass through (when disabled).
*/ */
public void setImageViewEnabled(boolean enabled) { public void setImageViewEnabled(boolean enabled) {
if (mImageViewEnabled == enabled) return;
mImageViewEnabled = enabled; mImageViewEnabled = enabled;
configureImageView();
} }
/** /**
...@@ -142,4 +141,18 @@ public class ChromeImageViewPreference extends Preference { ...@@ -142,4 +141,18 @@ public class ChromeImageViewPreference extends Preference {
return mManagedPrefDelegate.isPreferenceControlledByPolicy(this) return mManagedPrefDelegate.isPreferenceControlledByPolicy(this)
|| mManagedPrefDelegate.isPreferenceControlledByCustodian(this); || mManagedPrefDelegate.isPreferenceControlledByCustodian(this);
} }
private void configureImageView() {
if (mImageRes == 0 || mButton == null) return;
Drawable buttonImg = SettingsUtils.getTintedIcon(getContext(), mImageRes, mColorRes);
mButton.setImageDrawable(buttonImg);
mButton.setEnabled(mImageViewEnabled);
if (mImageViewEnabled) mButton.setOnClickListener(mListener);
if (mContentDescriptionRes != 0) {
mButton.setContentDescription(mButton.getResources().getString(mContentDescriptionRes));
}
}
} }
...@@ -32,6 +32,8 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat { ...@@ -32,6 +32,8 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
private ChromeImageViewPreference mCookieInUse; private ChromeImageViewPreference mCookieInUse;
private Runnable mOnClearCallback; private Runnable mOnClearCallback;
private Dialog mConfirmationDialog; private Dialog mConfirmationDialog;
private boolean mDeleteDisabled;
private boolean mDataUsed;
/** Parameters to configure the cookie controls view. */ /** Parameters to configure the cookie controls view. */
public static class PageInfoCookiesViewParams { public static class PageInfoCookiesViewParams {
...@@ -75,22 +77,23 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat { ...@@ -75,22 +77,23 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
mCookieInUse.setIcon( mCookieInUse.setIcon(
SettingsUtils.getTintedIcon(getContext(), R.drawable.permission_cookie)); SettingsUtils.getTintedIcon(getContext(), R.drawable.permission_cookie));
if (!params.disableCookieDeletion) { mCookieInUse.setImageView(
mCookieInUse.setImageView( R.drawable.ic_delete_white_24dp, R.string.page_info_cookies_clear, null);
R.drawable.ic_delete_white_24dp, R.string.page_info_cookies_clear, null); // Disabling enables passthrough of clicks to the main preference.
mCookieInUse.setImageColor(R.color.default_icon_color_blue); mCookieInUse.setImageViewEnabled(false);
// Disabling enables passthrough of clicks to the main preference. mDeleteDisabled = params.disableCookieDeletion;
mCookieInUse.setImageViewEnabled(false); mCookieInUse.setOnPreferenceClickListener(preference -> {
mCookieInUse.setOnPreferenceClickListener(preference -> { showClearCookiesConfirmation();
showClearCookiesConfirmation(); return true;
return true; });
}); updateCookieDeleteButton();
}
mOnClearCallback = params.onClearCallback; mOnClearCallback = params.onClearCallback;
} }
private void showClearCookiesConfirmation() { private void showClearCookiesConfirmation() {
if (mDeleteDisabled || !mDataUsed) return;
mConfirmationDialog = mConfirmationDialog =
new AlertDialog.Builder(getActivity(), R.style.Theme_Chromium_AlertDialog) new AlertDialog.Builder(getActivity(), R.style.Theme_Chromium_AlertDialog)
.setTitle(R.string.page_info_cookies_clear) .setTitle(R.string.page_info_cookies_clear)
...@@ -121,6 +124,9 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat { ...@@ -121,6 +124,9 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
: null); : null);
mCookieInUse.setTitle(getContext().getResources().getQuantityString( mCookieInUse.setTitle(getContext().getResources().getQuantityString(
R.plurals.page_info_cookies_in_use, allowedCookies, allowedCookies)); R.plurals.page_info_cookies_in_use, allowedCookies, allowedCookies));
mDataUsed |= allowedCookies != 0;
updateCookieDeleteButton();
} }
public void setStorageUsage(long storageUsage) { public void setStorageUsage(long storageUsage) {
...@@ -129,5 +135,14 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat { ...@@ -129,5 +135,14 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
getContext().getString(R.string.origin_settings_storage_usage_brief), getContext().getString(R.string.origin_settings_storage_usage_brief),
Formatter.formatShortFileSize(getContext(), storageUsage)) Formatter.formatShortFileSize(getContext(), storageUsage))
: null); : null);
mDataUsed |= storageUsage != 0;
updateCookieDeleteButton();
}
private void updateCookieDeleteButton() {
mCookieInUse.setImageColor(!mDeleteDisabled && mDataUsed
? R.color.default_icon_color_blue
: R.color.default_icon_color_disabled);
} }
} }
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
<color name="default_icon_color_blue">@color/default_icon_color_blue_light</color> <color name="default_icon_color_blue">@color/default_icon_color_blue_light</color>
<color name="default_icon_color_secondary">@color/default_icon_color_secondary_light</color> <color name="default_icon_color_secondary">@color/default_icon_color_secondary_light</color>
<color name="hairline_stroke_color">@color/hairline_stroke_color_dark</color> <color name="hairline_stroke_color">@color/hairline_stroke_color_dark</color>
<color name="default_icon_color_disabled">@color/default_icon_color_disabled_light</color>
<color name="default_icon_color_disabled_inverse">@color/default_icon_color_disabled_dark</color>
<!-- Common background and branding color. --> <!-- Common background and branding color. -->
<color name="default_bg_color">@color/default_bg_color_dark</color> <color name="default_bg_color">@color/default_bg_color_dark</color>
......
...@@ -33,7 +33,10 @@ ...@@ -33,7 +33,10 @@
<color name="hairline_stroke_color_light">@color/modern_grey_300</color> <color name="hairline_stroke_color_light">@color/modern_grey_300</color>
<color name="hairline_stroke_color_dark">@color/modern_grey_700</color> <color name="hairline_stroke_color_dark">@color/modern_grey_700</color>
<color name="hairline_stroke_color">@color/hairline_stroke_color_light</color> <color name="hairline_stroke_color">@color/hairline_stroke_color_light</color>
<color name="default_icon_color_disabled">@color/default_icon_color_disabled_dark</color>
<color name="default_icon_color_disabled_inverse" tools:ignore="UnusedResources">
@color/default_icon_color_disabled_light
</color>
<!-- Common background and branding color. --> <!-- Common background and branding color. -->
<color name="default_bg_color">@color/default_bg_color_light</color> <color name="default_bg_color">@color/default_bg_color_light</color>
<color name="default_bg_color_secondary" tools:ignore="UnusedResources">@color/default_bg_color_secondary_light</color> <color name="default_bg_color_secondary" tools:ignore="UnusedResources">@color/default_bg_color_secondary_light</color>
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
<color name="default_icon_color_secondary_light">@color/white_alpha_70</color> <color name="default_icon_color_secondary_light">@color/white_alpha_70</color>
<color name="default_icon_color_blue_light">@color/modern_blue_300</color> <color name="default_icon_color_blue_light">@color/modern_blue_300</color>
<color name="default_icon_color_blue_dark">@color/modern_blue_600</color> <color name="default_icon_color_blue_dark">@color/modern_blue_600</color>
<color name="default_icon_color_disabled_dark">@color/modern_grey_800_alpha_38</color>
<color name="default_icon_color_disabled_light">@color/white_alpha_38</color>
<!-- Common text colors --> <!-- Common text colors -->
<color name="default_text_color_dark">@color/modern_grey_900</color> <color name="default_text_color_dark">@color/modern_grey_900</color>
......
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