Commit df880618 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Read previously scheduled time for the change button.

Now we expose the initial time shown in the date time picker and read
the previous scheduled start time and show them in the date time
picker when the user press the change button in download home or
info bar.

Bug: 1110541
Change-Id: I7c562c6b3f3bcee0cb295d3b28b5830f82271b14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2325075Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794645}
parent 45444940
...@@ -90,7 +90,7 @@ public class DownloadLaterDialogTest { ...@@ -90,7 +90,7 @@ public class DownloadLaterDialogTest {
mDialogCoordinator = new DownloadLaterDialogCoordinator(mDateTimePicker); mDialogCoordinator = new DownloadLaterDialogCoordinator(mDateTimePicker);
mModel = new PropertyModel.Builder(DownloadLaterDialogProperties.ALL_KEYS) mModel = new PropertyModel.Builder(DownloadLaterDialogProperties.ALL_KEYS)
.with(DownloadLaterDialogProperties.CONTROLLER, mDialogCoordinator) .with(DownloadLaterDialogProperties.CONTROLLER, mDialogCoordinator)
.with(DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION, .with(DownloadLaterDialogProperties.INITIAL_CHOICE,
DownloadLaterDialogChoice.ON_WIFI) DownloadLaterDialogChoice.ON_WIFI)
.with(DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION, .with(DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION,
DownloadLaterPromptStatus.SHOW_INITIAL) DownloadLaterPromptStatus.SHOW_INITIAL)
......
...@@ -27,6 +27,7 @@ android_library("java") { ...@@ -27,6 +27,7 @@ android_library("java") {
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadDateTimePickerDialogImpl.java", "java/src/org/chromium/chrome/browser/download/dialogs/DownloadDateTimePickerDialogImpl.java",
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadDateTimePickerDialogProperties.java", "java/src/org/chromium/chrome/browser/download/dialogs/DownloadDateTimePickerDialogProperties.java",
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadDateTimePickerView.java", "java/src/org/chromium/chrome/browser/download/dialogs/DownloadDateTimePickerView.java",
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadDialogUtils.java",
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogChoice.java", "java/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogChoice.java",
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogController.java", "java/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogController.java",
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogCoordinator.java", "java/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogCoordinator.java",
......
...@@ -201,8 +201,7 @@ public class DownloadDialogBridge ...@@ -201,8 +201,7 @@ public class DownloadDialogBridge
PropertyModel.Builder builder = PropertyModel.Builder builder =
new PropertyModel.Builder(DownloadLaterDialogProperties.ALL_KEYS) new PropertyModel.Builder(DownloadLaterDialogProperties.ALL_KEYS)
.with(DownloadLaterDialogProperties.CONTROLLER, mDownloadLaterDialog) .with(DownloadLaterDialogProperties.CONTROLLER, mDownloadLaterDialog)
.with(DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION, .with(DownloadLaterDialogProperties.INITIAL_CHOICE, mDownloadLaterChoice)
mDownloadLaterChoice)
.with(DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION, .with(DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION,
promptStatus); promptStatus);
if (mShowEditLocation) { if (mShowEditLocation) {
......
...@@ -15,7 +15,6 @@ import org.chromium.base.Log; ...@@ -15,7 +15,6 @@ import org.chromium.base.Log;
import org.chromium.chrome.browser.download.R; import org.chromium.chrome.browser.download.R;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModel.ReadableObjectPropertyKey;
import java.util.Calendar; import java.util.Calendar;
...@@ -42,8 +41,8 @@ public class DownloadDateTimePickerDialogImpl ...@@ -42,8 +41,8 @@ public class DownloadDateTimePickerDialogImpl
public void showDialog( public void showDialog(
Context context, ModalDialogManager modalDialogManager, PropertyModel model) { Context context, ModalDialogManager modalDialogManager, PropertyModel model) {
// Reset and compute the initial time. // Reset and compute the initial time.
long initialTime = getLong(model, DownloadDateTimePickerDialogProperties.INITIAL_TIME, long initialTime = DownloadDialogUtils.getLong(model,
System.currentTimeMillis()); DownloadDateTimePickerDialogProperties.INITIAL_TIME, System.currentTimeMillis());
mCalendar.setTimeInMillis(initialTime); mCalendar.setTimeInMillis(initialTime);
// Reset dialogs. // Reset dialogs.
...@@ -54,10 +53,10 @@ public class DownloadDateTimePickerDialogImpl ...@@ -54,10 +53,10 @@ public class DownloadDateTimePickerDialogImpl
mDatePickerDialog = new DatePickerDialog(context, mDatePickerDialog = new DatePickerDialog(context,
R.style.Theme_DownloadDateTimePickerDialog, null, mCalendar.get(Calendar.YEAR), R.style.Theme_DownloadDateTimePickerDialog, null, mCalendar.get(Calendar.YEAR),
mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)); mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));
long minDate = long minDate = DownloadDialogUtils.getLong(
getLong(model, DownloadDateTimePickerDialogProperties.MIN_TIME, INVALID_TIMESTAMP); model, DownloadDateTimePickerDialogProperties.MIN_TIME, INVALID_TIMESTAMP);
long maxDate = long maxDate = DownloadDialogUtils.getLong(
getLong(model, DownloadDateTimePickerDialogProperties.MAX_TIME, INVALID_TIMESTAMP); model, DownloadDateTimePickerDialogProperties.MAX_TIME, INVALID_TIMESTAMP);
if (minDate > 0) mDatePickerDialog.getDatePicker().setMinDate(minDate); if (minDate > 0) mDatePickerDialog.getDatePicker().setMinDate(minDate);
if (maxDate > 0) mDatePickerDialog.getDatePicker().setMaxDate(maxDate); if (maxDate > 0) mDatePickerDialog.getDatePicker().setMaxDate(maxDate);
...@@ -111,12 +110,6 @@ public class DownloadDateTimePickerDialogImpl ...@@ -111,12 +110,6 @@ public class DownloadDateTimePickerDialogImpl
mCalendar.clear(); mCalendar.clear();
} }
private static long getLong(
PropertyModel model, ReadableObjectPropertyKey<Long> key, long defaultValue) {
Long value = model.get(key);
return (value != null) ? value : defaultValue;
}
// DownloadTimePickerDialog.Controller overrides. // DownloadTimePickerDialog.Controller overrides.
@Override @Override
public void onDownloadTimePicked(int hour, int minute) { public void onDownloadTimePicked(int hour, int minute) {
......
// 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.
package org.chromium.chrome.browser.download.dialogs;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModel.ReadableObjectPropertyKey;
/**
* Utility functions used in download dialogs.
*/
public class DownloadDialogUtils {
/**
* Returns a long value from property model, or a default value.
* @param model The model that contains the data.
* @param key The key of the data.
* @param defaultValue The default value returned when the given property doesn't exist.
*/
public static long getLong(
PropertyModel model, ReadableObjectPropertyKey<Long> key, long defaultValue) {
Long value = model.get(key);
return (value != null) ? value : defaultValue;
}
private DownloadDialogUtils() {}
}
...@@ -88,8 +88,7 @@ public class DownloadLaterDialogCoordinator implements ModalDialogProperties.Con ...@@ -88,8 +88,7 @@ public class DownloadLaterDialogCoordinator implements ModalDialogProperties.Con
mPropertyModelChangeProcessor = mPropertyModelChangeProcessor =
PropertyModelChangeProcessor.create(mDownloadLaterDialogModel, mCustomView, PropertyModelChangeProcessor.create(mDownloadLaterDialogModel, mCustomView,
DownloadLaterDialogView.Binder::bind, true /*performInitialBind*/); DownloadLaterDialogView.Binder::bind, true /*performInitialBind*/);
mDownloadLaterChoice = mDownloadLaterChoice = model.get(DownloadLaterDialogProperties.INITIAL_CHOICE);
model.get(DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION);
// Set up the modal dialog. // Set up the modal dialog.
mDialogModel = getModalDialogModel(context, this); mDialogModel = getModalDialogModel(context, this);
...@@ -154,12 +153,15 @@ public class DownloadLaterDialogCoordinator implements ModalDialogProperties.Con ...@@ -154,12 +153,15 @@ public class DownloadLaterDialogCoordinator implements ModalDialogProperties.Con
private void showDateTimePicker() { private void showDateTimePicker() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
// TODO(xingliu): Round up default time to next hour from now. long initialTime = DownloadDialogUtils.getLong(mDownloadLaterDialogModel,
DownloadDateTimePickerDialogProperties.INITIAL_TIME, now);
PropertyModel model = PropertyModel model =
new PropertyModel.Builder(DownloadDateTimePickerDialogProperties.ALL_KEYS) new PropertyModel.Builder(DownloadDateTimePickerDialogProperties.ALL_KEYS)
.with(DownloadDateTimePickerDialogProperties.STATE, State.DATE) .with(DownloadDateTimePickerDialogProperties.STATE, State.DATE)
.with(DownloadDateTimePickerDialogProperties.INITIAL_TIME, now) .with(DownloadDateTimePickerDialogProperties.INITIAL_TIME, initialTime)
.with(DownloadDateTimePickerDialogProperties.MIN_TIME, now) .with(DownloadDateTimePickerDialogProperties.MIN_TIME,
Math.min(now, initialTime))
.build(); .build();
mDateTimePickerDialog.showDialog(mContext, mModalDialogManager, model); mDateTimePickerDialog.showDialog(mContext, mModalDialogManager, model);
......
...@@ -82,13 +82,19 @@ public class DownloadLaterDialogHelper implements DownloadLaterDialogController ...@@ -82,13 +82,19 @@ public class DownloadLaterDialogHelper implements DownloadLaterDialogController
mCallback = callback; mCallback = callback;
mSource = source; mSource = source;
PropertyModel model = PropertyModel.Builder builder =
new PropertyModel.Builder(DownloadLaterDialogProperties.ALL_KEYS) new PropertyModel.Builder(DownloadLaterDialogProperties.ALL_KEYS)
.with(DownloadLaterDialogProperties.CONTROLLER, mDownloadLaterDialog) .with(DownloadLaterDialogProperties.CONTROLLER, mDownloadLaterDialog)
.with(DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION, .with(DownloadLaterDialogProperties.INITIAL_CHOICE, initialChoice);
initialChoice)
.build(); // Set the previously selected time to the date time picker UI.
mDownloadLaterDialog.showDialog(mContext, mModalDialogManager, mPrefService, model); if (currentSchedule.startTimeMs > 0) {
builder.with(DownloadDateTimePickerDialogProperties.INITIAL_TIME,
currentSchedule.startTimeMs);
}
mDownloadLaterDialog.showDialog(
mContext, mModalDialogManager, mPrefService, builder.build());
} }
/** /**
......
...@@ -32,6 +32,7 @@ import org.chromium.components.offline_items_collection.OfflineItemSchedule; ...@@ -32,6 +32,7 @@ import org.chromium.components.offline_items_collection.OfflineItemSchedule;
import org.chromium.components.prefs.PrefService; import org.chromium.components.prefs.PrefService;
import org.chromium.testing.local.LocalRobolectricTestRunner; import org.chromium.testing.local.LocalRobolectricTestRunner;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modelutil.PropertyModel;
/** /**
* Unit test for {@link DownloadLaterDialogHelper}. * Unit test for {@link DownloadLaterDialogHelper}.
...@@ -90,6 +91,19 @@ public class DownloadLaterDialogHelperUnitTest { ...@@ -90,6 +91,19 @@ public class DownloadLaterDialogHelperUnitTest {
Assert.assertFalse(captor.getValue().onlyOnWifi); Assert.assertFalse(captor.getValue().onlyOnWifi);
} }
@Test
public void testShowDialogWithScheduledStartTime() {
OfflineItemSchedule schedule = new OfflineItemSchedule(false, START_TIME);
mDownloadLaterDialogHelper.showChangeScheduleDialog(
schedule, Source.DOWNLOAD_HOME, mMockCallback);
ArgumentCaptor<PropertyModel> captor = ArgumentCaptor.forClass(PropertyModel.class);
verify(mDownloadLaterDialog, times(1)).showDialog(any(), any(), any(), captor.capture());
PropertyModel model = captor.getValue();
Assert.assertEquals(
START_TIME, (long) model.get(DownloadDateTimePickerDialogProperties.INITIAL_TIME));
}
@Test @Test
public void testCancel() { public void testCancel() {
OfflineItemSchedule schedule = new OfflineItemSchedule(true, -1); OfflineItemSchedule schedule = new OfflineItemSchedule(true, -1);
......
...@@ -15,8 +15,8 @@ public class DownloadLaterDialogProperties { ...@@ -15,8 +15,8 @@ public class DownloadLaterDialogProperties {
.ReadableObjectPropertyKey<DownloadLaterDialogView.Controller> CONTROLLER = .ReadableObjectPropertyKey<DownloadLaterDialogView.Controller> CONTROLLER =
new PropertyModel.ReadableObjectPropertyKey(); new PropertyModel.ReadableObjectPropertyKey();
/** The initial selection to define when to start the download. */ /** The initial choice of the download later dialog. */
public static final PropertyModel.ReadableIntPropertyKey DOWNLOAD_TIME_INITIAL_SELECTION = public static final PropertyModel.ReadableIntPropertyKey INITIAL_CHOICE =
new PropertyModel.ReadableIntPropertyKey(); new PropertyModel.ReadableIntPropertyKey();
/** The initial selection to define the don't show again checkbox. */ /** The initial selection to define the don't show again checkbox. */
...@@ -34,7 +34,11 @@ public class DownloadLaterDialogProperties { ...@@ -34,7 +34,11 @@ public class DownloadLaterDialogProperties {
public static final PropertyModel.WritableObjectPropertyKey<String> LOCATION_TEXT = public static final PropertyModel.WritableObjectPropertyKey<String> LOCATION_TEXT =
new PropertyModel.WritableObjectPropertyKey<>(); new PropertyModel.WritableObjectPropertyKey<>();
public static final PropertyKey[] ALL_DOWNLOAD_LATER_DIALOG_PROPERTIES =
new PropertyKey[] {CONTROLLER, INITIAL_CHOICE, DONT_SHOW_AGAIN_SELECTION,
DONT_SHOW_AGAIN_DISABLED, LOCATION_TEXT};
public static final PropertyKey[] ALL_KEYS = public static final PropertyKey[] ALL_KEYS =
new PropertyKey[] {CONTROLLER, DOWNLOAD_TIME_INITIAL_SELECTION, PropertyModel.concatKeys(ALL_DOWNLOAD_LATER_DIALOG_PROPERTIES,
DONT_SHOW_AGAIN_SELECTION, DONT_SHOW_AGAIN_DISABLED, LOCATION_TEXT}; new PropertyKey[] {DownloadDateTimePickerDialogProperties.INITIAL_TIME});
} }
...@@ -51,10 +51,8 @@ public class DownloadLaterDialogView extends ScrollView implements OnCheckedChan ...@@ -51,10 +51,8 @@ public class DownloadLaterDialogView extends ScrollView implements OnCheckedChan
PropertyModel model, DownloadLaterDialogView view, PropertyKey propertyKey) { PropertyModel model, DownloadLaterDialogView view, PropertyKey propertyKey) {
if (propertyKey == DownloadLaterDialogProperties.CONTROLLER) { if (propertyKey == DownloadLaterDialogProperties.CONTROLLER) {
view.setController(model.get(DownloadLaterDialogProperties.CONTROLLER)); view.setController(model.get(DownloadLaterDialogProperties.CONTROLLER));
} else if (propertyKey } else if (propertyKey == DownloadLaterDialogProperties.INITIAL_CHOICE) {
== DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION) { view.setChoice(model.get(DownloadLaterDialogProperties.INITIAL_CHOICE));
view.setChoice(
model.get(DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION));
} else if (propertyKey == DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION) { } else if (propertyKey == DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION) {
view.setCheckbox( view.setCheckbox(
model.get(DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION)); model.get(DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION));
......
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