Commit 1da1d190 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Polish the state when selecting download later.

When selecting download later in the download later dialog, checkbox
is now disabled, and the positive button text is changed to "Next".

Bug: 1107620
Change-Id: Idf08c8675b81b6eb67affbe0ebd231ded621fbf8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2316447Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791630}
parent 356f75bc
...@@ -6,7 +6,9 @@ package org.chromium.chrome.browser.download.dialogs; ...@@ -6,7 +6,9 @@ package org.chromium.chrome.browser.download.dialogs;
import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
...@@ -16,6 +18,9 @@ import static org.mockito.Mockito.times; ...@@ -16,6 +18,9 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.view.View;
import androidx.test.espresso.NoMatchingViewException;
import androidx.test.filters.MediumTest; import androidx.test.filters.MediumTest;
import org.junit.Assert; import org.junit.Assert;
...@@ -162,6 +167,11 @@ public class DownloadLaterDialogTest { ...@@ -162,6 +167,11 @@ public class DownloadLaterDialogTest {
getDownloadLaterDialogView().onCheckedChanged(null, -1); getDownloadLaterDialogView().onCheckedChanged(null, -1);
}); });
onView(withId(org.chromium.chrome.R.id.positive_button)).check(matches(withText("Next")));
onView(withId(R.id.show_again_checkbox)).check((View view, NoMatchingViewException e) -> {
Assert.assertFalse(view.isEnabled());
});
clickPositiveButton(); clickPositiveButton();
verify(mController, times(0)).onDownloadLaterDialogComplete(anyInt(), anyLong()); verify(mController, times(0)).onDownloadLaterDialogComplete(anyInt(), anyLong());
verify(mDateTimePicker).showDialog(any(), any(), any()); verify(mDateTimePicker).showDialog(any(), any(), any());
......
...@@ -168,17 +168,17 @@ public class DownloadLaterDialogCoordinator implements ModalDialogProperties.Con ...@@ -168,17 +168,17 @@ public class DownloadLaterDialogCoordinator implements ModalDialogProperties.Con
private void notifyComplete(long time) { private void notifyComplete(long time) {
assert mController != null; assert mController != null;
updatePromptStatus(); maybeUpdatePromptStatus();
mController.onDownloadLaterDialogComplete(mDownloadLaterChoice, time); mController.onDownloadLaterDialogComplete(mDownloadLaterChoice, time);
} }
private void notifyCancel() { private void notifyCancel() {
assert mController != null; assert mController != null;
updatePromptStatus(); maybeUpdatePromptStatus();
mController.onDownloadLaterDialogCanceled(); mController.onDownloadLaterDialogCanceled();
} }
private void updatePromptStatus() { private void maybeUpdatePromptStatus() {
assert mCustomView != null; assert mCustomView != null;
assert mPrefService != null; assert mPrefService != null;
Integer promptStatus = mCustomView.getPromptStatus(); Integer promptStatus = mCustomView.getPromptStatus();
...@@ -241,7 +241,27 @@ public class DownloadLaterDialogCoordinator implements ModalDialogProperties.Con ...@@ -241,7 +241,27 @@ public class DownloadLaterDialogCoordinator implements ModalDialogProperties.Con
} }
@Override @Override
public void onCheckedChanged(int choice) { public void onCheckedChanged(@DownloadLaterDialogChoice int choice) {
@DownloadLaterDialogChoice
int previousChoice = mDownloadLaterChoice;
mDownloadLaterChoice = choice; mDownloadLaterChoice = choice;
// Change the positive button text and disable the checkbox if the user select download
// later option.
if (previousChoice != DownloadLaterDialogChoice.DOWNLOAD_LATER
&& choice == DownloadLaterDialogChoice.DOWNLOAD_LATER) {
mDialogModel.set(ModalDialogProperties.POSITIVE_BUTTON_TEXT,
mContext.getResources().getString(
R.string.download_date_time_picker_next_text));
mDownloadLaterDialogModel.set(
DownloadLaterDialogProperties.DONT_SHOW_AGAIN_DISABLED, true);
} else if (previousChoice == DownloadLaterDialogChoice.DOWNLOAD_LATER
&& choice != DownloadLaterDialogChoice.DOWNLOAD_LATER) {
mDialogModel.set(ModalDialogProperties.POSITIVE_BUTTON_TEXT,
mContext.getResources().getString(
R.string.duplicate_download_infobar_download_button));
mDownloadLaterDialogModel.set(
DownloadLaterDialogProperties.DONT_SHOW_AGAIN_DISABLED, false);
}
} }
} }
...@@ -23,6 +23,10 @@ public class DownloadLaterDialogProperties { ...@@ -23,6 +23,10 @@ public class DownloadLaterDialogProperties {
public static final PropertyModel.ReadableIntPropertyKey DONT_SHOW_AGAIN_SELECTION = public static final PropertyModel.ReadableIntPropertyKey DONT_SHOW_AGAIN_SELECTION =
new PropertyModel.ReadableIntPropertyKey(); new PropertyModel.ReadableIntPropertyKey();
/** Whether the don't show again checkbox is disabled. */
public static final PropertyModel.WritableBooleanPropertyKey DONT_SHOW_AGAIN_DISABLED =
new PropertyModel.WritableBooleanPropertyKey();
/** /**
* The string representing the download location. If null, no download location edit text will * The string representing the download location. If null, no download location edit text will
* be shown. * be shown.
...@@ -30,6 +34,7 @@ public class DownloadLaterDialogProperties { ...@@ -30,6 +34,7 @@ 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_KEYS = new PropertyKey[] { public static final PropertyKey[] ALL_KEYS =
CONTROLLER, DOWNLOAD_TIME_INITIAL_SELECTION, DONT_SHOW_AGAIN_SELECTION, LOCATION_TEXT}; new PropertyKey[] {CONTROLLER, DOWNLOAD_TIME_INITIAL_SELECTION,
DONT_SHOW_AGAIN_SELECTION, DONT_SHOW_AGAIN_DISABLED, LOCATION_TEXT};
} }
...@@ -58,6 +58,9 @@ public class DownloadLaterDialogView extends ScrollView implements OnCheckedChan ...@@ -58,6 +58,9 @@ public class DownloadLaterDialogView extends ScrollView implements OnCheckedChan
} 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));
} else if (propertyKey == DownloadLaterDialogProperties.DONT_SHOW_AGAIN_DISABLED) {
view.setCheckboxEnabled(
!model.get(DownloadLaterDialogProperties.DONT_SHOW_AGAIN_DISABLED));
} else if (propertyKey == DownloadLaterDialogProperties.LOCATION_TEXT) { } else if (propertyKey == DownloadLaterDialogProperties.LOCATION_TEXT) {
view.setShowEditLocation(model.get(DownloadLaterDialogProperties.LOCATION_TEXT)); view.setShowEditLocation(model.get(DownloadLaterDialogProperties.LOCATION_TEXT));
} }
...@@ -124,8 +127,12 @@ public class DownloadLaterDialogView extends ScrollView implements OnCheckedChan ...@@ -124,8 +127,12 @@ public class DownloadLaterDialogView extends ScrollView implements OnCheckedChan
mCheckBox.setChecked(checked); mCheckBox.setChecked(checked);
} }
void setCheckboxEnabled(boolean enabled) {
mCheckBox.setEnabled(enabled);
}
Integer getPromptStatus() { Integer getPromptStatus() {
if (mCheckBox.getVisibility() == View.GONE) return null; if (mCheckBox.getVisibility() == View.GONE || !mCheckBox.isEnabled()) return null;
return mCheckBox.isChecked() ? DownloadLaterPromptStatus.DONT_SHOW return mCheckBox.isChecked() ? DownloadLaterPromptStatus.DONT_SHOW
: DownloadLaterPromptStatus.SHOW_PREFERENCE; : DownloadLaterPromptStatus.SHOW_PREFERENCE;
......
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