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 {
mDialogCoordinator = new DownloadLaterDialogCoordinator(mDateTimePicker);
mModel = new PropertyModel.Builder(DownloadLaterDialogProperties.ALL_KEYS)
.with(DownloadLaterDialogProperties.CONTROLLER, mDialogCoordinator)
.with(DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION,
.with(DownloadLaterDialogProperties.INITIAL_CHOICE,
DownloadLaterDialogChoice.ON_WIFI)
.with(DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION,
DownloadLaterPromptStatus.SHOW_INITIAL)
......
......@@ -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/DownloadDateTimePickerDialogProperties.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/DownloadLaterDialogController.java",
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogCoordinator.java",
......
......@@ -201,8 +201,7 @@ public class DownloadDialogBridge
PropertyModel.Builder builder =
new PropertyModel.Builder(DownloadLaterDialogProperties.ALL_KEYS)
.with(DownloadLaterDialogProperties.CONTROLLER, mDownloadLaterDialog)
.with(DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION,
mDownloadLaterChoice)
.with(DownloadLaterDialogProperties.INITIAL_CHOICE, mDownloadLaterChoice)
.with(DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION,
promptStatus);
if (mShowEditLocation) {
......
......@@ -15,7 +15,6 @@ import org.chromium.base.Log;
import org.chromium.chrome.browser.download.R;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModel.ReadableObjectPropertyKey;
import java.util.Calendar;
......@@ -42,8 +41,8 @@ public class DownloadDateTimePickerDialogImpl
public void showDialog(
Context context, ModalDialogManager modalDialogManager, PropertyModel model) {
// Reset and compute the initial time.
long initialTime = getLong(model, DownloadDateTimePickerDialogProperties.INITIAL_TIME,
System.currentTimeMillis());
long initialTime = DownloadDialogUtils.getLong(model,
DownloadDateTimePickerDialogProperties.INITIAL_TIME, System.currentTimeMillis());
mCalendar.setTimeInMillis(initialTime);
// Reset dialogs.
......@@ -54,10 +53,10 @@ public class DownloadDateTimePickerDialogImpl
mDatePickerDialog = new DatePickerDialog(context,
R.style.Theme_DownloadDateTimePickerDialog, null, mCalendar.get(Calendar.YEAR),
mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));
long minDate =
getLong(model, DownloadDateTimePickerDialogProperties.MIN_TIME, INVALID_TIMESTAMP);
long maxDate =
getLong(model, DownloadDateTimePickerDialogProperties.MAX_TIME, INVALID_TIMESTAMP);
long minDate = DownloadDialogUtils.getLong(
model, DownloadDateTimePickerDialogProperties.MIN_TIME, INVALID_TIMESTAMP);
long maxDate = DownloadDialogUtils.getLong(
model, DownloadDateTimePickerDialogProperties.MAX_TIME, INVALID_TIMESTAMP);
if (minDate > 0) mDatePickerDialog.getDatePicker().setMinDate(minDate);
if (maxDate > 0) mDatePickerDialog.getDatePicker().setMaxDate(maxDate);
......@@ -111,12 +110,6 @@ public class DownloadDateTimePickerDialogImpl
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.
@Override
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
mPropertyModelChangeProcessor =
PropertyModelChangeProcessor.create(mDownloadLaterDialogModel, mCustomView,
DownloadLaterDialogView.Binder::bind, true /*performInitialBind*/);
mDownloadLaterChoice =
model.get(DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION);
mDownloadLaterChoice = model.get(DownloadLaterDialogProperties.INITIAL_CHOICE);
// Set up the modal dialog.
mDialogModel = getModalDialogModel(context, this);
......@@ -154,12 +153,15 @@ public class DownloadLaterDialogCoordinator implements ModalDialogProperties.Con
private void showDateTimePicker() {
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 =
new PropertyModel.Builder(DownloadDateTimePickerDialogProperties.ALL_KEYS)
.with(DownloadDateTimePickerDialogProperties.STATE, State.DATE)
.with(DownloadDateTimePickerDialogProperties.INITIAL_TIME, now)
.with(DownloadDateTimePickerDialogProperties.MIN_TIME, now)
.with(DownloadDateTimePickerDialogProperties.INITIAL_TIME, initialTime)
.with(DownloadDateTimePickerDialogProperties.MIN_TIME,
Math.min(now, initialTime))
.build();
mDateTimePickerDialog.showDialog(mContext, mModalDialogManager, model);
......
......@@ -82,13 +82,19 @@ public class DownloadLaterDialogHelper implements DownloadLaterDialogController
mCallback = callback;
mSource = source;
PropertyModel model =
PropertyModel.Builder builder =
new PropertyModel.Builder(DownloadLaterDialogProperties.ALL_KEYS)
.with(DownloadLaterDialogProperties.CONTROLLER, mDownloadLaterDialog)
.with(DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION,
initialChoice)
.build();
mDownloadLaterDialog.showDialog(mContext, mModalDialogManager, mPrefService, model);
.with(DownloadLaterDialogProperties.INITIAL_CHOICE, initialChoice);
// Set the previously selected time to the date time picker UI.
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;
import org.chromium.components.prefs.PrefService;
import org.chromium.testing.local.LocalRobolectricTestRunner;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modelutil.PropertyModel;
/**
* Unit test for {@link DownloadLaterDialogHelper}.
......@@ -90,6 +91,19 @@ public class DownloadLaterDialogHelperUnitTest {
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
public void testCancel() {
OfflineItemSchedule schedule = new OfflineItemSchedule(true, -1);
......
......@@ -15,8 +15,8 @@ public class DownloadLaterDialogProperties {
.ReadableObjectPropertyKey<DownloadLaterDialogView.Controller> CONTROLLER =
new PropertyModel.ReadableObjectPropertyKey();
/** The initial selection to define when to start the download. */
public static final PropertyModel.ReadableIntPropertyKey DOWNLOAD_TIME_INITIAL_SELECTION =
/** The initial choice of the download later dialog. */
public static final PropertyModel.ReadableIntPropertyKey INITIAL_CHOICE =
new PropertyModel.ReadableIntPropertyKey();
/** The initial selection to define the don't show again checkbox. */
......@@ -34,7 +34,11 @@ public class DownloadLaterDialogProperties {
public static final PropertyModel.WritableObjectPropertyKey<String> LOCATION_TEXT =
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 =
new PropertyKey[] {CONTROLLER, DOWNLOAD_TIME_INITIAL_SELECTION,
DONT_SHOW_AGAIN_SELECTION, DONT_SHOW_AGAIN_DISABLED, LOCATION_TEXT};
PropertyModel.concatKeys(ALL_DOWNLOAD_LATER_DIALOG_PROPERTIES,
new PropertyKey[] {DownloadDateTimePickerDialogProperties.INITIAL_TIME});
}
......@@ -51,10 +51,8 @@ public class DownloadLaterDialogView extends ScrollView implements OnCheckedChan
PropertyModel model, DownloadLaterDialogView view, PropertyKey propertyKey) {
if (propertyKey == DownloadLaterDialogProperties.CONTROLLER) {
view.setController(model.get(DownloadLaterDialogProperties.CONTROLLER));
} else if (propertyKey
== DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION) {
view.setChoice(
model.get(DownloadLaterDialogProperties.DOWNLOAD_TIME_INITIAL_SELECTION));
} else if (propertyKey == DownloadLaterDialogProperties.INITIAL_CHOICE) {
view.setChoice(model.get(DownloadLaterDialogProperties.INITIAL_CHOICE));
} else if (propertyKey == DownloadLaterDialogProperties.DONT_SHOW_AGAIN_SELECTION) {
view.setCheckbox(
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