Commit 36ac3363 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Fix an issue that date time pickers are leaked.

If the the date picker or time picker are dismissed without negative
button clicked. The dialog flow is leaked that any following downloads
will not show dialogs due to
DownloadLocationDialogResult.DUPLICATE_DIALOG.

Bug: 1125066
Change-Id: I1fc54941fdd8486e3346b0f3dca670bf5f5316ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2394717Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804999}
parent fd37d3cb
......@@ -23,11 +23,13 @@ import java.util.Calendar;
* {@link android.app.DatePickerDialog} and {@link android.app.TimePickerDialog} widgets. The user
* will see the date picker and time picker in a sequence when trying to select a time.
*/
// TODO(xingliu): Add instrumentation test for date/time pickers.
public class DownloadDateTimePickerDialogImpl
implements DownloadDateTimePickerDialog, DownloadTimePickerDialog.Controller {
private static final String TAG = "DateTimeDialog";
private static final long INVALID_TIMESTAMP = -1;
private DatePickerDialog mDatePickerDialog;
private boolean mDatePickerButtonClicked;
private DownloadTimePickerDialog mTimePickerDialog;
private Controller mController;
private final Calendar mCalendar = Calendar.getInstance();
......@@ -65,6 +67,7 @@ public class DownloadDateTimePickerDialogImpl
this::onDatePickerClicked);
mDatePickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
context.getResources().getString(R.string.cancel), this::onDatePickerClicked);
mDatePickerDialog.setOnDismissListener(dialogInterface -> { onDatePickerDismissed(); });
mTimePickerDialog = new DownloadTimePickerDialog(
context, this, mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE));
......@@ -80,6 +83,7 @@ public class DownloadDateTimePickerDialogImpl
}
private void onDatePickerClicked(DialogInterface dialogInterface, int which) {
mDatePickerButtonClicked = true;
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
DatePicker datePicker = mDatePickerDialog.getDatePicker();
......@@ -98,6 +102,12 @@ public class DownloadDateTimePickerDialogImpl
}
}
private void onDatePickerDismissed() {
if (mDatePickerButtonClicked) return;
onCancel();
}
private void onCancel() {
assert mController != null;
mCalendar.clear();
......
......@@ -26,6 +26,7 @@ class DownloadTimePickerDialog extends TimePickerDialog {
private int mHourOfDay;
private int mMinute;
private final Controller mController;
private boolean mButtonClicked;
DownloadTimePickerDialog(
Context context, @NonNull Controller controller, int hourOfDay, int minute) {
......@@ -34,6 +35,10 @@ class DownloadTimePickerDialog extends TimePickerDialog {
mHourOfDay = hourOfDay;
mMinute = minute;
mController = controller;
setOnDismissListener((dialogInterface) -> {
if (mButtonClicked) return;
mController.onDownloadTimePickerCanceled();
});
}
// TimePickerDialog overrides.
......@@ -47,6 +52,7 @@ class DownloadTimePickerDialog extends TimePickerDialog {
assert button != null;
button.setText(R.string.download_date_time_picker_next_text);
button.setOnClickListener((view) -> {
mButtonClicked = true;
mController.onDownloadTimePicked(mHourOfDay, mMinute);
dismiss();
});
......@@ -54,6 +60,7 @@ class DownloadTimePickerDialog extends TimePickerDialog {
button = getButton(DialogInterface.BUTTON_NEGATIVE);
button.setText(R.string.cancel);
button.setOnClickListener((view) -> {
mButtonClicked = true;
mController.onDownloadTimePickerCanceled();
dismiss();
});
......
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