Commit b6b921e2 authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

[Android] Add warning to Clear Data dialog (and polish a bit).

Part 1 of 2:

This CL adds a custom layout to the ClearDataDialog and fleshes
out the part when deleting storage for a single origin.

The new custom layout includes a new warning for when deleting
app data, and changes the title and Clear button text slightly.

Bug: 1068710
Change-Id: Ia7f302fb138540b7ebd11aa1ee87bdd8447b2042
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153147
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Commit-Queue: Peter Conn <peconn@chromium.org>
Auto-Submit: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760081}
parent e23af245
......@@ -942,6 +942,7 @@ chrome_java_resources = [
"java/res/drawable/ic_offline_pin_blue_white.xml",
"java/res/drawable/ic_offline_pin_white.xml",
"java/res/drawable/ic_pause_circle_outline_white_24dp.xml",
"java/res/drawable/ic_person_24dp.xml",
"java/res/drawable/ic_person_add_24dp.xml",
"java/res/drawable/ic_photo_camera_black.xml",
"java/res/drawable/ic_photo_camera_grey.xml",
......@@ -1069,6 +1070,7 @@ chrome_java_resources = [
"java/res/layout/checkbox_layout.xml",
"java/res/layout/clear_browsing_data_tabs.xml",
"java/res/layout/clear_browsing_important_dialog_listview.xml",
"java/res/layout/clear_data_dialog.xml",
"java/res/layout/clear_storage.xml",
"java/res/layout/compositor_view_holder.xml",
"java/res/layout/confirm_import_sync_data.xml",
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/default_icon_color_secondary_dark"
android:pathData="M12 2c-4.97 0-9 4.03-9 9 0 4.17 2.84 7.67 6.69 8.69L12 22l2.31-2.31C18.16 18.67 21 15.17 21 11c0-4.97-4.03-9-9-9zm0 2c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.3c-2.5 0-4.71-1.28-6-3.22 0.03 -1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z" />
<path
android:pathData="M0 0h24v24H0z" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:paddingStart="24dp"
android:paddingEnd="24dp">
<TextView
android:id="@android:id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />
<RelativeLayout
android:id="@+id/signed_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/message"
android:layout_marginTop="16dp">
<ImageView
android:id="@+id/signed_out_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_person_24dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/signed_out_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/message"
android:layout_toEndOf="@id/signed_out_icon"
android:layout_centerInParent="true"
android:layout_marginStart="12dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/signed_out"
android:layout_marginTop="12dp">
<ImageView
android:id="@+id/offline_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_offline_pin_24dp_on_light_bg"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/offline_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/offline_icon"
android:layout_centerInParent="true"
android:layout_marginStart="12dp" />
</RelativeLayout>
</RelativeLayout>
......@@ -33,7 +33,6 @@
<org.chromium.chrome.browser.site_settings.ClearWebsiteStorage
android:key="clear_data"
android:title="@string/webstorage_clear_data_dialog_title"
android:dialogMessage="@string/webstorage_clear_data_dialog_message"
android:positiveButtonText="@string/webstorage_clear_data_dialog_ok_button"
android:negativeButtonText="@string/cancel"
android:widgetLayout="@layout/clear_storage" />
......
......@@ -8,16 +8,69 @@ import android.content.Context;
import android.util.AttributeSet;
import androidx.preference.DialogPreference;
import androidx.preference.PreferenceViewHolder;
import org.chromium.chrome.R;
/**
* Dialog that prompts the user to clear website storage on the device.
*/
public class ClearWebsiteStorage extends DialogPreference {
Context mContext;
// The host to show in the dialog.
String mHost;
// Whether to warn that apps will also be deleted.
boolean mClearingApps;
public ClearWebsiteStorage(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initialize(context);
}
public ClearWebsiteStorage(Context context, AttributeSet attrs) {
super(context, attrs);
initialize(context);
}
private void initialize(Context context) {
setDialogLayoutResource(R.layout.clear_data_dialog);
mContext = context;
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
assert mHost != null;
super.onBindViewHolder(holder);
int resourceId = mClearingApps
? R.string.webstorage_clear_data_dialog_message_single_with_app
: R.string.webstorage_clear_data_dialog_message_single;
setDialogMessage(mContext.getString(resourceId, mHost));
}
/**
* Set the data to show in the dialog.
* @param host The host to show in the dialog.
* @param clearingApps True if there is one or more apps involved, whose data will be deleted.
*/
public void setDataForDisplay(String host, boolean clearingApps) {
mHost = host;
mClearingApps = clearingApps;
}
/**
* Returns the string resource id to use to explain that the user will be signed out.
*/
public int getSignedOutText() {
return R.string.webstorage_clear_data_dialog_sign_out_message;
}
/**
* Returns the string resource id to use to explain what happens with offline files.
*/
public int getOfflineText() {
return R.string.webstorage_clear_data_dialog_offline_message;
}
}
......@@ -5,11 +5,14 @@
package org.chromium.chrome.browser.site_settings;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.preference.Preference;
import androidx.preference.PreferenceDialogFragmentCompat;
import org.chromium.base.Callback;
import org.chromium.chrome.R;
/**
* The fragment used to display the clear website storage confirmation dialog.
......@@ -29,6 +32,17 @@ public class ClearWebsiteStorageDialog extends PreferenceDialogFragmentCompat {
return fragment;
}
@Override
protected void onBindDialogView(View view) {
ClearWebsiteStorage preference = (ClearWebsiteStorage) getPreference();
TextView signedOutView = view.findViewById(R.id.signed_out_text);
TextView offlineTextView = view.findViewById(R.id.offline_text);
signedOutView.setText(preference.getSignedOutText());
offlineTextView.setText(preference.getOfflineText());
super.onBindDialogView(view);
}
@Override
public void onDialogClosed(boolean positiveResult) {
sCallback.onResult(positiveResult);
......
......@@ -28,6 +28,7 @@ import org.chromium.base.Callback;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.webapps.WebappRegistry;
import org.chromium.components.browser_ui.settings.ChromeImageViewPreference;
import org.chromium.components.browser_ui.settings.ManagedPreferencesUtils;
import org.chromium.components.browser_ui.settings.SettingsUtils;
......@@ -330,7 +331,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
if (PREF_SITE_TITLE.equals(preference.getKey())) {
preference.setTitle(mSite.getTitle());
} else if (PREF_CLEAR_DATA.equals(preference.getKey())) {
setUpClearDataPreference(preference);
setUpClearDataPreference((ClearWebsiteStorage) preference);
} else if (PREF_RESET_SITE.equals(preference.getKey())) {
preference.setOnPreferenceClickListener(this);
} else {
......@@ -367,13 +368,17 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
}
}
private void setUpClearDataPreference(Preference preference) {
private void setUpClearDataPreference(ClearWebsiteStorage preference) {
long usage = mSite.getTotalUsage();
if (usage > 0) {
WebappRegistry registry = WebappRegistry.getInstance();
Set<String> originsWithApps = registry.getOriginsWithInstalledApp();
boolean appFound = originsWithApps.contains(mSite.getAddress().getOrigin());
Context context = preference.getContext();
preference.setTitle(
String.format(context.getString(R.string.origin_settings_storage_usage_brief),
Formatter.formatShortFileSize(context, usage)));
preference.setDataForDisplay(mSite.getTitle(), appFound);
} else {
getPreferenceScreen().removePreference(preference);
}
......
......@@ -1131,13 +1131,22 @@ Your Google account may have other forms of browsing history like searches and a
Are you sure you want to reset all site permissions for <ph name="CHOSEN_OBJECT_NAME">%1$s<ex>Weblight</ex></ph>?
</message>
<message name="IDS_WEBSTORAGE_CLEAR_DATA_DIALOG_TITLE" desc="Title of the confirmation dialog when the user ask to clear all data for an origin">
Clear stored data
Clear site data?
</message>
<message name="IDS_WEBSTORAGE_CLEAR_DATA_DIALOG_MESSAGE" desc="Text of the confirmation dialog when the user ask to clear all data for an origin">
All local data stored by this website, including cookies, will be deleted.
<message name="IDS_WEBSTORAGE_CLEAR_DATA_DIALOG_MESSAGE_SINGLE" desc="Text of the confirmation dialog when the user asks to clear all data (and app) for a single origin">
This will clear all data and cookies stored by <ph name="ORIGIN">%1$s<ex>google.com</ex></ph>.
</message>
<message name="IDS_WEBSTORAGE_CLEAR_DATA_DIALOG_MESSAGE_SINGLE_WITH_APP" desc="Text of the confirmation dialog when the user asks to clear all data (and app) for a single origin">
This will clear all data and cookies stored by <ph name="ORIGIN">%1$s<ex>google.com</ex></ph> and its app on your Home screen.
</message>
<message name="IDS_WEBSTORAGE_CLEAR_DATA_DIALOG_SIGN_OUT_MESSAGE" desc="Text of the confirmation dialog, explaining that the user will be signed out of the site being cleared.">
You'll be signed out of this site.
</message>
<message name="IDS_WEBSTORAGE_CLEAR_DATA_DIALOG_OFFLINE_MESSAGE" desc="Text of the confirmation dialog, explaining that all offline data will be cleared (when clearing a site/sites).">
Any offline data will be cleared.
</message>
<message name="IDS_WEBSTORAGE_CLEAR_DATA_DIALOG_OK_BUTTON" desc="Button confirming site data cleanup [CHAR-LIMIT=20]">
Clear all
Clear
</message>
<message name="IDS_WEBSITE_NOTIFICATION_MANAGED_BY_APP" desc="String used to indicate that notifications are managed by an installed app">
Managed by <ph name="APP_NAME">%1$s<ex>Notification App Name</ex></ph>
......
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