Commit 2049435c authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[Android] Make buttons text customizable in PWM dialog

The same dialog component will be used for multiple purposes, for
the onboarding flow as well as for leak detection. Since these need
different button strings, this CL makes the strings customizable
from the bridge.

Bug: 986317
Change-Id: Icfb80952b0312cd15e6f16bf722abf292b82a523
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1762230
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689447}
parent 87d0f518
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.password_manager;
import android.content.res.Resources;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
......@@ -14,11 +16,13 @@ import org.chromium.ui.modaldialog.DialogDismissalCause;
public class OnboardingDialogBridge {
private long mNativeOnboardingDialogView;
private final PasswordManagerDialogCoordinator mOnboardingDialog;
private final Resources mResources;
private OnboardingDialogBridge(WindowAndroid windowAndroid, long nativeOnboardingDialogView) {
mNativeOnboardingDialogView = nativeOnboardingDialogView;
ChromeActivity activity = (ChromeActivity) windowAndroid.getActivity().get();
mOnboardingDialog = new PasswordManagerDialogCoordinator(activity);
mResources = activity.getResources();
}
@CalledByNative
......@@ -30,7 +34,9 @@ public class OnboardingDialogBridge {
public void showDialog(String onboardingTitle, String onboardingDetails) {
// TODO(crbug.com/983445): Replace the drawable once the real image is available.
mOnboardingDialog.showDialog(onboardingTitle, onboardingDetails,
R.drawable.data_reduction_illustration, this::onClick);
R.drawable.data_reduction_illustration,
mResources.getString(R.string.continue_button),
mResources.getString(R.string.cancel), this::onClick);
}
@CalledByNative
......
......@@ -4,7 +4,7 @@
package org.chromium.chrome.browser.password_manager;
import android.content.res.Resources;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
......@@ -34,10 +34,11 @@ public class PasswordManagerDialogCoordinator {
mModel, customView, PasswordManagerDialogViewBinder::bind);
}
public void showDialog(
String title, String details, int drawableId, Callback<Boolean> onClick) {
public void showDialog(String title, String details, @DrawableRes int drawableId,
String positiveButtonText, String negativeButtonText, Callback<Boolean> onClick) {
mMediator.setContents(title, details, drawableId);
mMediator.showDialog(onClick);
mMediator.setButtons(positiveButtonText, negativeButtonText, onClick);
mMediator.showDialog();
}
public void dismissDialog(@DialogDismissalCause int dismissalClause) {
......@@ -45,11 +46,7 @@ public class PasswordManagerDialogCoordinator {
}
private static PropertyModel.Builder createDialogModelBuilder(View customView) {
Resources resources = customView.getResources();
return new PropertyModel.Builder(ModalDialogProperties.ALL_KEYS)
.with(ModalDialogProperties.CUSTOM_VIEW, customView)
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, resources,
R.string.continue_button)
.with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT, resources, R.string.cancel);
.with(ModalDialogProperties.CUSTOM_VIEW, customView);
}
}
......@@ -8,6 +8,8 @@ import static org.chromium.chrome.browser.password_manager.PasswordManagerDialog
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.ILLUSTRATION;
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.TITLE;
import android.support.annotation.DrawableRes;
import org.chromium.base.Callback;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties;
......@@ -57,17 +59,21 @@ class PasswordManagerDialogMediator {
mModalDialogBuilder = dialogBuilder;
}
void setContents(String title, String details, int drawableId) {
void setContents(String title, String details, @DrawableRes int drawableId) {
mModel.set(ILLUSTRATION, drawableId);
mModel.set(TITLE, title);
mModel.set(DETAILS, details);
}
void showDialog(Callback<Boolean> onClick) {
mDialogModel =
mModalDialogBuilder
.with(ModalDialogProperties.CONTROLLER, new DialogClickHandler(onClick))
.build();
void setButtons(
String positiveButtonText, String negativeButtonText, Callback<Boolean> onClick) {
mModalDialogBuilder.with(ModalDialogProperties.CONTROLLER, new DialogClickHandler(onClick))
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, positiveButtonText)
.with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT, negativeButtonText);
}
void showDialog() {
mDialogModel = mModalDialogBuilder.build();
mDialogManager.showDialog(mDialogModel, ModalDialogManager.ModalDialogType.TAB);
}
......
......@@ -40,6 +40,8 @@ public class PasswordManagerDialogTest {
private PasswordManagerDialogCoordinator mDialog;
private static final String TITLE = "Title";
private static final String DETAILS = "Explanation text.";
private static final String OK_BUTTON = "OK";
private static final String CANCEL_BUTTON = "Cancel";
@Mock
private Callback<Boolean> mOnClick;
......@@ -56,7 +58,8 @@ public class PasswordManagerDialogTest {
mActivityTestRule.startMainActivityOnBlankPage();
mDialog = new PasswordManagerDialogCoordinator(mActivityTestRule.getActivity());
TestThreadUtils.runOnUiThreadBlocking(() -> {
mDialog.showDialog(TITLE, DETAILS, R.drawable.data_reduction_illustration, mOnClick);
mDialog.showDialog(TITLE, DETAILS, R.drawable.data_reduction_illustration, OK_BUTTON,
CANCEL_BUTTON, mOnClick);
});
}
......@@ -66,6 +69,8 @@ public class PasswordManagerDialogTest {
onView(withId(R.id.password_manager_dialog_title)).check(matches(withText(TITLE)));
onView(withId(R.id.password_manager_dialog_details)).check(matches(withText(DETAILS)));
onView(withId(R.id.password_manager_dialog_illustration)).check(matches(isDisplayed()));
onView(withId(R.id.positive_button)).check(matches(withText(OK_BUTTON)));
onView(withId(R.id.negative_button)).check(matches(withText(CANCEL_BUTTON)));
}
@Test
......
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