Commit 067d7df1 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Add the setting for download later prompt.

Adds the "ask when to download" setting in download setting page.

Bug: 1078454
Change-Id: I8974413fc720694ca1cb39cd3ba740d47c480e6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2265174
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782209}
parent 7f0839a9
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
android:positiveButtonText="@string/done" android:positiveButtonText="@string/done"
android:negativeButtonText="@null" /> android:negativeButtonText="@null" />
<org.chromium.components.browser_ui.settings.ChromeSwitchPreference
android:key="download_later_prompt_enabled"
android:title="@string/download_later_prompt_enabled_title"
android:summaryOn="@string/text_on"
android:summaryOff="@string/text_off" />
<org.chromium.components.browser_ui.settings.ChromeSwitchPreference <org.chromium.components.browser_ui.settings.ChromeSwitchPreference
android:key="location_prompt_enabled" android:key="location_prompt_enabled"
android:title="@string/download_location_prompt_enabled_title" android:title="@string/download_location_prompt_enabled_title"
......
...@@ -11,12 +11,18 @@ import androidx.preference.Preference; ...@@ -11,12 +11,18 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import org.chromium.chrome.browser.download.DownloadDialogBridge; import org.chromium.chrome.browser.download.DownloadDialogBridge;
import org.chromium.chrome.browser.download.DownloadLaterPromptStatus;
import org.chromium.chrome.browser.download.DownloadPromptStatus; import org.chromium.chrome.browser.download.DownloadPromptStatus;
import org.chromium.chrome.browser.download.R; import org.chromium.chrome.browser.download.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.offlinepages.prefetch.PrefetchConfiguration; import org.chromium.chrome.browser.offlinepages.prefetch.PrefetchConfiguration;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileKey; import org.chromium.chrome.browser.profiles.ProfileKey;
import org.chromium.components.browser_ui.settings.ChromeSwitchPreference; import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
import org.chromium.components.browser_ui.settings.SettingsUtils; import org.chromium.components.browser_ui.settings.SettingsUtils;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
/** /**
* Fragment containing Download settings. * Fragment containing Download settings.
...@@ -24,10 +30,14 @@ import org.chromium.components.browser_ui.settings.SettingsUtils; ...@@ -24,10 +30,14 @@ import org.chromium.components.browser_ui.settings.SettingsUtils;
public class DownloadSettings public class DownloadSettings
extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener { extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener {
public static final String PREF_LOCATION_CHANGE = "location_change"; public static final String PREF_LOCATION_CHANGE = "location_change";
private static final String PREF_DOWNLOAD_LATER_PROMPT_ENABLED =
"download_later_prompt_enabled";
private static final String PREF_LOCATION_PROMPT_ENABLED = "location_prompt_enabled"; private static final String PREF_LOCATION_PROMPT_ENABLED = "location_prompt_enabled";
private static final String PREF_PREFETCHING_ENABLED = "prefetching_enabled"; private static final String PREF_PREFETCHING_ENABLED = "prefetching_enabled";
private PrefService mPrefService;
private DownloadLocationPreference mLocationChangePref; private DownloadLocationPreference mLocationChangePref;
private ChromeSwitchPreference mDownloadLaterPromptEnabledPref;
private ChromeSwitchPreference mLocationPromptEnabledPref; private ChromeSwitchPreference mLocationPromptEnabledPref;
private ChromeSwitchPreference mPrefetchingEnabled; private ChromeSwitchPreference mPrefetchingEnabled;
...@@ -35,11 +45,20 @@ public class DownloadSettings ...@@ -35,11 +45,20 @@ public class DownloadSettings
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String s) { public void onCreatePreferences(@Nullable Bundle savedInstanceState, String s) {
getActivity().setTitle(R.string.menu_downloads); getActivity().setTitle(R.string.menu_downloads);
SettingsUtils.addPreferencesFromResource(this, R.xml.download_preferences); SettingsUtils.addPreferencesFromResource(this, R.xml.download_preferences);
mPrefService = UserPrefs.get(Profile.getLastUsedRegularProfile());
mDownloadLaterPromptEnabledPref =
(ChromeSwitchPreference) findPreference(PREF_DOWNLOAD_LATER_PROMPT_ENABLED);
mDownloadLaterPromptEnabledPref.setOnPreferenceChangeListener(this);
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOAD_LATER)) {
getPreferenceScreen().removePreference(
findPreference(PREF_DOWNLOAD_LATER_PROMPT_ENABLED));
}
mLocationPromptEnabledPref = mLocationPromptEnabledPref =
(ChromeSwitchPreference) findPreference(PREF_LOCATION_PROMPT_ENABLED); (ChromeSwitchPreference) findPreference(PREF_LOCATION_PROMPT_ENABLED);
mLocationPromptEnabledPref.setOnPreferenceChangeListener(this); mLocationPromptEnabledPref.setOnPreferenceChangeListener(this);
mLocationChangePref = (DownloadLocationPreference) findPreference(PREF_LOCATION_CHANGE); mLocationChangePref = (DownloadLocationPreference) findPreference(PREF_LOCATION_CHANGE);
if (PrefetchConfiguration.isPrefetchingFlagEnabled()) { if (PrefetchConfiguration.isPrefetchingFlagEnabled()) {
...@@ -68,21 +87,25 @@ public class DownloadSettings ...@@ -68,21 +87,25 @@ public class DownloadSettings
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
updateData(); updateDownloadSettings();
} }
private void updateData() { private void updateDownloadSettings() {
if (mLocationChangePref != null) { mLocationChangePref.updateSummary();
mLocationChangePref.updateSummary();
}
if (mLocationPromptEnabledPref != null) { if (ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOAD_LATER)) {
// Location prompt is marked enabled if the prompt status is not DONT_SHOW. @DownloadLaterPromptStatus
boolean isLocationPromptEnabled = DownloadDialogBridge.getPromptForDownloadAndroid() int downloadLaterPromptStatus =
!= DownloadPromptStatus.DONT_SHOW; mPrefService.getInteger(Pref.DOWNLOAD_LATER_PROMPT_STATUS);
mLocationPromptEnabledPref.setChecked(isLocationPromptEnabled); mDownloadLaterPromptEnabledPref.setChecked(
!(downloadLaterPromptStatus == DownloadLaterPromptStatus.DONT_SHOW));
} }
// Location prompt is marked enabled if the prompt status is not DONT_SHOW.
boolean isLocationPromptEnabled = DownloadDialogBridge.getPromptForDownloadAndroid()
!= DownloadPromptStatus.DONT_SHOW;
mLocationPromptEnabledPref.setChecked(isLocationPromptEnabled);
if (mPrefetchingEnabled != null) { if (mPrefetchingEnabled != null) {
mPrefetchingEnabled.setChecked(PrefetchConfiguration.isPrefetchingEnabledInSettings( mPrefetchingEnabled.setChecked(PrefetchConfiguration.isPrefetchingEnabledInSettings(
ProfileKey.getLastUsedRegularProfileKey())); ProfileKey.getLastUsedRegularProfileKey()));
...@@ -112,9 +135,25 @@ public class DownloadSettings ...@@ -112,9 +135,25 @@ public class DownloadSettings
// Preference.OnPreferenceChangeListener implementation. // Preference.OnPreferenceChangeListener implementation.
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
if (PREF_LOCATION_PROMPT_ENABLED.equals(preference.getKey())) { if (PREF_DOWNLOAD_LATER_PROMPT_ENABLED.equals(preference.getKey())) {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOAD_LATER)) return false;
@DownloadLaterPromptStatus
int downloadLaterPromptStatus =
mPrefService.getInteger(Pref.DOWNLOAD_LATER_PROMPT_STATUS);
if (!(boolean) newValue) {
mPrefService.setInteger(
Pref.DOWNLOAD_LATER_PROMPT_STATUS, DownloadLaterPromptStatus.DONT_SHOW);
return true;
}
// Only update if the download later dialog has been shown before.
if (downloadLaterPromptStatus != DownloadLaterPromptStatus.SHOW_INITIAL) {
mPrefService.setInteger(Pref.DOWNLOAD_LATER_PROMPT_STATUS,
DownloadLaterPromptStatus.SHOW_PREFERENCE);
}
} else if (PREF_LOCATION_PROMPT_ENABLED.equals(preference.getKey())) {
if ((boolean) newValue) { if ((boolean) newValue) {
// Only update if the interstitial has been shown before. // Only update if the download location dialog has been shown before.
if (DownloadDialogBridge.getPromptForDownloadAndroid() if (DownloadDialogBridge.getPromptForDownloadAndroid()
!= DownloadPromptStatus.SHOW_INITIAL) { != DownloadPromptStatus.SHOW_INITIAL) {
DownloadDialogBridge.setPromptForDownloadAndroid( DownloadDialogBridge.setPromptForDownloadAndroid(
......
...@@ -1067,6 +1067,9 @@ Your Google account may have other forms of browsing history like searches and a ...@@ -1067,6 +1067,9 @@ Your Google account may have other forms of browsing history like searches and a
<message name="IDS_DOWNLOAD_LATER_PICK_TIME_TEXT" desc="The text for the radio button to select the download time in download later dialog."> <message name="IDS_DOWNLOAD_LATER_PICK_TIME_TEXT" desc="The text for the radio button to select the download time in download later dialog.">
Pick date &amp; time Pick date &amp; time
</message> </message>
<message name="IDS_DOWNLOAD_LATER_PROMPT_ENABLED_TITLE" desc="A setting text to ask whether to show a dialog about when to download.">
Ask when to save files
</message>
<!-- Downloads location --> <!-- Downloads location -->
<message name="IDS_DOWNLOADS_LOCATION_SELECTOR_TITLE" desc="Title of the preference that allows the user to select which of the folders they would like to make the default location to save their downloads."> <message name="IDS_DOWNLOADS_LOCATION_SELECTOR_TITLE" desc="Title of the preference that allows the user to select which of the folders they would like to make the default location to save their downloads.">
......
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