Commit 5028dd66 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Glue later dialog to infobar.

This CL adds the download later dialog to the download infobar.

Bug: 1102706,1078454
Change-Id: I7cab1da9b862c6cfa03e81dabd16639d0947bc23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2284351Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786635}
parent 4a895017
...@@ -23,12 +23,14 @@ import org.chromium.chrome.R; ...@@ -23,12 +23,14 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeTabbedActivity; import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.DeviceConditions; import org.chromium.chrome.browser.DeviceConditions;
import org.chromium.chrome.browser.download.dialogs.DownloadLaterDialogHelper;
import org.chromium.chrome.browser.download.items.OfflineContentAggregatorFactory; import org.chromium.chrome.browser.download.items.OfflineContentAggregatorFactory;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.infobar.DownloadProgressInfoBar; import org.chromium.chrome.browser.infobar.DownloadProgressInfoBar;
import org.chromium.chrome.browser.infobar.IPHInfoBarSupport; import org.chromium.chrome.browser.infobar.IPHInfoBarSupport;
import org.chromium.chrome.browser.infobar.InfoBarContainer; import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.infobar.InfoBarIdentifier; import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.components.download.DownloadState; import org.chromium.components.download.DownloadState;
import org.chromium.components.feature_engagement.FeatureConstants; import org.chromium.components.feature_engagement.FeatureConstants;
...@@ -37,8 +39,11 @@ import org.chromium.components.offline_items_collection.ContentId; ...@@ -37,8 +39,11 @@ import org.chromium.components.offline_items_collection.ContentId;
import org.chromium.components.offline_items_collection.LegacyHelpers; import org.chromium.components.offline_items_collection.LegacyHelpers;
import org.chromium.components.offline_items_collection.OfflineContentProvider; import org.chromium.components.offline_items_collection.OfflineContentProvider;
import org.chromium.components.offline_items_collection.OfflineItem; import org.chromium.components.offline_items_collection.OfflineItem;
import org.chromium.components.offline_items_collection.OfflineItemSchedule;
import org.chromium.components.offline_items_collection.OfflineItemState; import org.chromium.components.offline_items_collection.OfflineItemState;
import org.chromium.components.offline_items_collection.UpdateDelta; import org.chromium.components.offline_items_collection.UpdateDelta;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
...@@ -288,6 +293,9 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -288,6 +293,9 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
// Represents the currently displayed InfoBar data. // Represents the currently displayed InfoBar data.
private DownloadProgressInfoBarData mCurrentInfo; private DownloadProgressInfoBarData mCurrentInfo;
// Used to show the download later dialog to change download schedule.
private DownloadLaterDialogHelper mDownloadLaterDialogHelper;
/** Constructor. */ /** Constructor. */
public DownloadInfoBarController(boolean isIncognito) { public DownloadInfoBarController(boolean isIncognito) {
mUseNewDownloadPath = mUseNewDownloadPath =
...@@ -678,6 +686,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -678,6 +686,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
} else if (singleDownloadScheduled) { } else if (singleDownloadScheduled) {
info.message = getMessageForDownloadScheduled(itemToShow); info.message = getMessageForDownloadScheduled(itemToShow);
info.link = getContext().getString(R.string.change_link); info.link = getContext().getString(R.string.change_link);
info.id = itemToShow.id;
} else { } else {
// TODO(shaktisahu): Incorporate various types of failure messages. // TODO(shaktisahu): Incorporate various types of failure messages.
// TODO(shaktisahu, xingliu): Consult UX to handle multiple schedule variations. // TODO(shaktisahu, xingliu): Consult UX to handle multiple schedule variations.
...@@ -1011,18 +1020,21 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -1011,18 +1020,21 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
private class DownloadProgressInfoBarClient implements DownloadProgressInfoBar.Client { private class DownloadProgressInfoBarClient implements DownloadProgressInfoBar.Client {
@Override @Override
public void onLinkClicked(ContentId itemId) { public void onLinkClicked(ContentId itemId) {
// TODO(shaktisahu, xingliu) : This assumes that the item is being opened. For scheduled final OfflineItem item = mTrackedItems.get(itemId);
// downloads, we need to open the dialog.
mTrackedItems.remove(itemId); mTrackedItems.remove(itemId);
removeNotification(itemId); removeNotification(itemId);
if (itemId != null) {
if (item != null && item.schedule != null) {
onChangeScheduleClicked(itemId, item.schedule);
} else if (itemId != null) {
DownloadUtils.openItem( DownloadUtils.openItem(
itemId, mIsIncognito, DownloadOpenSource.DOWNLOAD_PROGRESS_INFO_BAR); itemId, mIsIncognito, DownloadOpenSource.DOWNLOAD_PROGRESS_INFO_BAR);
recordLinkClicked(true /*openItem*/);
} else { } else {
DownloadManagerService.openDownloadsPage( DownloadManagerService.openDownloadsPage(
getContext(), DownloadOpenSource.DOWNLOAD_PROGRESS_INFO_BAR); getContext(), DownloadOpenSource.DOWNLOAD_PROGRESS_INFO_BAR);
recordLinkClicked(false /*openItem*/);
} }
recordLinkClicked(itemId != null);
closePreviousInfoBar(); closePreviousInfoBar();
} }
...@@ -1037,6 +1049,26 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -1037,6 +1049,26 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
} }
} }
private void onChangeScheduleClicked(
final ContentId id, final OfflineItemSchedule currentSchedule) {
if (mDownloadLaterDialogHelper != null) mDownloadLaterDialogHelper.destroy();
ChromeActivity activity = getActivity();
if (activity == null) return;
PrefService prefService = UserPrefs.get(Profile.getLastUsedRegularProfile());
// Show the download later dialog to let the user change download schedule.
mDownloadLaterDialogHelper = DownloadLaterDialogHelper.create(
activity, activity.getModalDialogManager(), prefService);
mDownloadLaterDialogHelper.showChangeScheduleDialog(currentSchedule, (newSchedule) -> {
if (mUseNewDownloadPath) {
OfflineContentAggregatorFactory.get().changeSchedule(id, newSchedule);
} else {
DownloadManagerService.getDownloadManagerService().changeSchedule(
id, newSchedule, mIsIncognito);
}
});
}
private void recordInfoBarState( private void recordInfoBarState(
@DownloadInfoBarState int state, DownloadProgressInfoBarData info) { @DownloadInfoBarState int state, DownloadProgressInfoBarData info) {
int shownState = -1; int shownState = -1;
...@@ -1098,7 +1130,6 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -1098,7 +1130,6 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
if (openItem) { if (openItem) {
RecordUserAction.record("Android.Download.InfoBar.LinkClicked.OpenDownload"); RecordUserAction.record("Android.Download.InfoBar.LinkClicked.OpenDownload");
} else { } else {
// TODO(shaktisahu, xingliu): This could be scheduled download as well.
RecordUserAction.record("Android.Download.InfoBar.LinkClicked.OpenDownloadHome"); RecordUserAction.record("Android.Download.InfoBar.LinkClicked.OpenDownloadHome");
} }
} }
......
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