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

Download later: Add download later dialog resources.

This CL mainly adds the download later dialog UI xml file and the string
resources.

The view logic is not implemented. A very basic instrumentation test is
added to test the download later dialog Java code.

A Jni bridge will eventually own DownloadLaterDialogCoordinator.

Bug: 1078454
Change-Id: I3508415e437371b38facd7c9ce78b3276f7fa7e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2223001
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774824}
parent ab9c8c16
......@@ -167,6 +167,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/download/ServicificationDownloadTest.java",
"javatests/src/org/chromium/chrome/browser/download/SystemDownloadNotifierTest.java",
"javatests/src/org/chromium/chrome/browser/download/TestDownloadDirectoryProvider.java",
"javatests/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogTest.java",
"javatests/src/org/chromium/chrome/browser/download/home/DownloadActivityV2Test.java",
"javatests/src/org/chromium/chrome/browser/download/home/StubbedOfflineContentProvider.java",
"javatests/src/org/chromium/chrome/browser/download/ui/StubbedProvider.java",
......
// 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 android.support.test.filters.MediumTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogProperties;
/**
* Test to verify download later dialog.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class DownloadLaterDialogTest {
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
private DownloadLaterDialogCoordinator mDialogCoordinator;
@Mock
private ModalDialogProperties.Controller mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mActivityTestRule.startMainActivityOnBlankPage();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertNotNull("controller should not be null", mController);
mDialogCoordinator = new DownloadLaterDialogCoordinator(mActivityTestRule.getActivity(),
mActivityTestRule.getActivity().getModalDialogManager(), mController);
});
}
@Test
@MediumTest
public void testShowDialogThenDismiss() {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mDialogCoordinator.showDialog();
Assert.assertTrue(mActivityTestRule.getActivity().getModalDialogManager().isShowing());
mDialogCoordinator.dismissDialog(DialogDismissalCause.UNKNOWN);
Assert.assertFalse(mActivityTestRule.getActivity().getModalDialogManager().isShowing());
});
}
@Test
@MediumTest
public void testShowDialogThenDestroy() {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mDialogCoordinator.showDialog();
Assert.assertTrue(mActivityTestRule.getActivity().getModalDialogManager().isShowing());
mDialogCoordinator.destroy();
});
}
}
......@@ -22,6 +22,9 @@ android_library("java") {
"java/src/org/chromium/chrome/browser/download/MediaStoreHelper.java",
"java/src/org/chromium/chrome/browser/download/MimeUtils.java",
"java/src/org/chromium/chrome/browser/download/StringUtils.java",
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogCoordinator.java",
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogProperties.java",
"java/src/org/chromium/chrome/browser/download/dialogs/DownloadLaterDialogView.java",
"java/src/org/chromium/chrome/browser/download/home/DownloadManagerCoordinator.java",
"java/src/org/chromium/chrome/browser/download/home/DownloadManagerUiConfig.java",
"java/src/org/chromium/chrome/browser/download/home/FaviconProvider.java",
......@@ -134,6 +137,7 @@ android_resources("java_resources") {
"java/res/layout/confirm_oma_download.xml",
"java/res/layout/download_home_tabs.xml",
"java/res/layout/download_home_toolbar.xml",
"java/res/layout/download_later_dialog.xml",
"java/res/layout/download_location_dialog.xml",
"java/res/layout/download_location_preference.xml",
"java/res/layout/download_location_preference_item.xml",
......
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<org.chromium.chrome.browser.download.dialogs.DownloadLaterDialogView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
style="@style/AlertDialogContent">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:textAppearance="@style/TextAppearance.DownloadLaterTitle"
android:text="@string/download_later_dialog_title" />
<TextView
android:id="@+id/subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:textAppearance="@style/TextAppearance.TextMedium.Secondary"
android:text="@string/download_later_dialog_subtitle" />
<org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout
android:id="@+id/radio_button_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- TODO(xingliu): Use 0 paddingStart for RadioButtonWithDescription. See crbug.com/1090062 -->
<!-- TODO(xingliu): Adjust margin between RadioButtonWithDescription. See crbug.com/1090155 -->
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription
android:id="@+id/download_now"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="1dp"
app:primaryText="@string/download_later_download_now_text" />
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription
android:id="@+id/on_wifi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="1dp"
app:primaryText="@string/download_later_on_wifi_text" />
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription
android:id="@+id/choose_date_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="1dp"
app:primaryText="@string/download_later_pick_time_text" />
</org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout>
<CheckBox
android:id="@+id/show_again_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:layout_marginBottom="11dp"
android:layout_marginStart="-5dp"
android:text="@string/download_location_dialog_checkbox"
style="@style/TextAppearance.TextMedium.Tertiary" />
</LinearLayout>
</org.chromium.chrome.browser.download.dialogs.DownloadLaterDialogView>
......@@ -82,4 +82,9 @@
<item name="android:src">@drawable/ic_play_arrow_white_36dp</item>
<item name="android:tint">@color/modern_grey_800</item>
</style>
<!-- Download Later Styles -->
<style name="TextAppearance.DownloadLaterTitle" parent="TextAppearance.AlertDialogTitleStyle">
<item name="android:textSize">20sp</item>
</style>
</resources>
// 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 android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import org.chromium.chrome.browser.download.R;
import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
/**
* Coordinator to construct the download later dialog.
*/
public class DownloadLaterDialogCoordinator {
private final PropertyModel mDownloadLaterDialogModel;
private final DownloadLaterDialogView mCustomView;
private final ModalDialogManager mModalDialogManager;
private final PropertyModel mDialogModel;
private final ModalDialogProperties.Controller mController;
private final PropertyModelChangeProcessor<PropertyModel, DownloadLaterDialogView, PropertyKey>
mPropertyModelChangeProcessor;
/**
* The coordinator that bridges the download later diaog view logic to multiple data models.
* @param activity The activity mainly to provide the {@link ModalDialogManager}.
*/
public DownloadLaterDialogCoordinator(Activity activity, ModalDialogManager modalDialogManager,
ModalDialogProperties.Controller controller) {
// Set up the download later UI MVC.
mDownloadLaterDialogModel = new PropertyModel(DownloadLaterDialogProperties.ALL_KEYS);
mCustomView = (DownloadLaterDialogView) LayoutInflater.from(activity).inflate(
R.layout.download_later_dialog, null);
mPropertyModelChangeProcessor =
PropertyModelChangeProcessor.create(mDownloadLaterDialogModel, mCustomView,
DownloadLaterDialogView.Binder::bind, true /*performInitialBind*/);
// Set up the modal dialog.
mModalDialogManager = modalDialogManager;
mController = controller;
mDialogModel = getModalDialogModel(activity);
}
/**
* Shows the download later dialog.
*/
public void showDialog() {
mModalDialogManager.showDialog(mDialogModel, ModalDialogManager.ModalDialogType.APP);
}
/**
* Dismisses the download later dialog.
* @param dismissalCause The reason to dismiss the dialog, used in metrics tracking.
*/
public void dismissDialog(@DialogDismissalCause int dismissalCause) {
mModalDialogManager.dismissDialog(mDialogModel, dismissalCause);
}
/**
* Destroy the download later dialog.
*/
public void destroy() {
mPropertyModelChangeProcessor.destroy();
}
private PropertyModel getModalDialogModel(Context context) {
assert mController != null;
assert mCustomView != null;
return new PropertyModel.Builder(ModalDialogProperties.ALL_KEYS)
.with(ModalDialogProperties.CONTROLLER, mController)
.with(ModalDialogProperties.CUSTOM_VIEW, mCustomView)
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, context.getResources(),
R.string.duplicate_download_infobar_download_button)
.with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT, context.getResources(),
R.string.cancel)
.build();
}
}
// 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.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
/**
* Contains all the properties for the download later dialog {@link PropertyModel}.
*/
public class DownloadLaterDialogProperties {
/** The selection to define when to start the download. */
public static final PropertyModel.WritableIntPropertyKey DOWNLOAD_TIME_SELECTION =
new PropertyModel.WritableIntPropertyKey();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {DOWNLOAD_TIME_SELECTION};
}
// 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 android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
/**
* The custom view in the download later dialog.
*/
public class DownloadLaterDialogView extends LinearLayout {
/**
* The view binder to propagate events from model to view.
*/
public static class Binder {
public static void bind(
PropertyModel model, DownloadLaterDialogView view, PropertyKey propertyKey) {}
}
public DownloadLaterDialogView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
}
......@@ -1006,6 +1006,23 @@ Your Google account may have other forms of browsing history like searches and a
Chrome has saved you <ph name="gigabytes">%1$d<ex>10</ex></ph> GB
</message>
<!-- Download later -->
<message name="IDS_DOWNLOAD_LATER_DIALOG_TITLE" desc="Title of the download later dialog that let the user to choose the time to download.">
Choose when to download
</message>
<message name="IDS_DOWNLOAD_LATER_DIALOG_SUBTITLE" desc="Subtitle of the download later dialog that let the user to choose the time to download.">
You'll see a notification when this file is ready
</message>
<message name="IDS_DOWNLOAD_LATER_DOWNLOAD_NOW_TEXT" desc="The text for the radio button to trigger the download now in download later dialog.">
Now
</message>
<message name="IDS_DOWNLOAD_LATER_ON_WIFI_TEXT" desc="The text for the radio button to trigger the download on WIFI in download later dialog.">
On Wi-Fi
</message>
<message name="IDS_DOWNLOAD_LATER_PICK_TIME_TEXT" desc="The text for the radio button to select the download time in download later dialog.">
Pick date &amp; time
</message>
<!-- Downloads location -->
<message name="IDS_DOWNLOADS_LOCATION_SELECTOR_TITLE" desc="Title of the preference that allows the user to select which of the folders they would like to make the default location to save their downloads.">
Download location
......
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