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 {
private int mContentDescriptionRes;
// Whether the ImageView should be enabled.
private boolean mImageViewEnabled = true;
// The ImageView Button.
private ImageView mButton;
/**
* Constructor for use in Java.
......@@ -80,23 +82,13 @@ public class ChromeImageViewPreference extends Preference {
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
ImageView button = (ImageView) holder.findViewById(R.id.image_view_widget);
View view = holder.itemView;
mButton = (ImageView) holder.findViewById(R.id.image_view_widget);
mButton.setBackgroundColor(Color.TRANSPARENT);
mButton.setVisibility(View.VISIBLE);
if (mImageRes != 0) {
Drawable buttonImg = SettingsUtils.getTintedIcon(getContext(), mImageRes, mColorRes);
button.setImageDrawable(buttonImg);
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);
configureImageView();
ManagedPreferencesUtils.onBindViewToImageViewPreference(
mManagedPrefDelegate, this, holder.itemView);
}
@Override
......@@ -114,6 +106,7 @@ public class ChromeImageViewPreference extends Preference {
mImageRes = imageRes;
mContentDescriptionRes = contentDescriptionRes;
mListener = listener;
configureImageView();
notifyChanged();
}
......@@ -122,14 +115,20 @@ public class ChromeImageViewPreference extends Preference {
* @param colorRes
*/
public void setImageColor(@ColorRes int colorRes) {
if (mColorRes == colorRes) return;
mColorRes = colorRes;
configureImageView();
}
/**
* Enables/Disables the ImageView, allowing for clicks to pass through (when disabled).
*/
public void setImageViewEnabled(boolean enabled) {
if (mImageViewEnabled == enabled) return;
mImageViewEnabled = enabled;
configureImageView();
}
/**
......@@ -142,4 +141,18 @@ public class ChromeImageViewPreference extends Preference {
return mManagedPrefDelegate.isPreferenceControlledByPolicy(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 {
private ChromeImageViewPreference mCookieInUse;
private Runnable mOnClearCallback;
private Dialog mConfirmationDialog;
private boolean mDeleteDisabled;
private boolean mDataUsed;
/** Parameters to configure the cookie controls view. */
public static class PageInfoCookiesViewParams {
......@@ -75,22 +77,23 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
mCookieInUse.setIcon(
SettingsUtils.getTintedIcon(getContext(), R.drawable.permission_cookie));
if (!params.disableCookieDeletion) {
mCookieInUse.setImageView(
R.drawable.ic_delete_white_24dp, R.string.page_info_cookies_clear, null);
mCookieInUse.setImageColor(R.color.default_icon_color_blue);
// Disabling enables passthrough of clicks to the main preference.
mCookieInUse.setImageViewEnabled(false);
mCookieInUse.setOnPreferenceClickListener(preference -> {
showClearCookiesConfirmation();
return true;
});
}
mCookieInUse.setImageView(
R.drawable.ic_delete_white_24dp, R.string.page_info_cookies_clear, null);
// Disabling enables passthrough of clicks to the main preference.
mCookieInUse.setImageViewEnabled(false);
mDeleteDisabled = params.disableCookieDeletion;
mCookieInUse.setOnPreferenceClickListener(preference -> {
showClearCookiesConfirmation();
return true;
});
updateCookieDeleteButton();
mOnClearCallback = params.onClearCallback;
}
private void showClearCookiesConfirmation() {
if (mDeleteDisabled || !mDataUsed) return;
mConfirmationDialog =
new AlertDialog.Builder(getActivity(), R.style.Theme_Chromium_AlertDialog)
.setTitle(R.string.page_info_cookies_clear)
......@@ -121,6 +124,9 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
: null);
mCookieInUse.setTitle(getContext().getResources().getQuantityString(
R.plurals.page_info_cookies_in_use, allowedCookies, allowedCookies));
mDataUsed |= allowedCookies != 0;
updateCookieDeleteButton();
}
public void setStorageUsage(long storageUsage) {
......@@ -129,5 +135,14 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
getContext().getString(R.string.origin_settings_storage_usage_brief),
Formatter.formatShortFileSize(getContext(), storageUsage))
: 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 @@
<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="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. -->
<color name="default_bg_color">@color/default_bg_color_dark</color>
......
......@@ -33,7 +33,10 @@
<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">@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. -->
<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>
......
......@@ -13,6 +13,8 @@
<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_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 -->
<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