Commit 39e60ba2 authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[Android] Refactor PasswordManagerDialog

The method called to show the dialog used to take 9 parameters and the
list was growing. This CL bundles the parameters into a separate contents
object which requires the mandatory values to be passed in the constructor
and offers reasonable defaults and setters for the rest of the values.

In addition, some properties of the model are not actually meant to be
changed on the fly, so they are now marked readonly and set before building
the model. This requires a separate initialization step in the coordinator
and mediator.

Bug: 1028947
Change-Id: I4f121e5fee88d095d6c31add59111639e85faedb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1948931
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721576}
parent 568d8acb
...@@ -1189,6 +1189,7 @@ chrome_java_sources = [ ...@@ -1189,6 +1189,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationDialogViewBinder.java", "java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationDialogViewBinder.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationPopupAdapter.java", "java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationPopupAdapter.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationPopupBridge.java", "java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationPopupBridge.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordManagerDialogContents.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordManagerDialogCoordinator.java", "java/src/org/chromium/chrome/browser/password_manager/PasswordManagerDialogCoordinator.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordManagerDialogMediator.java", "java/src/org/chromium/chrome/browser/password_manager/PasswordManagerDialogMediator.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordManagerDialogProperties.java", "java/src/org/chromium/chrome/browser/password_manager/PasswordManagerDialogProperties.java",
......
...@@ -11,7 +11,6 @@ import org.chromium.chrome.browser.help.HelpAndFeedback; ...@@ -11,7 +11,6 @@ import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.modaldialog.DialogDismissalCause; import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
...@@ -27,9 +26,8 @@ public class CredentialLeakDialogBridge { ...@@ -27,9 +26,8 @@ public class CredentialLeakDialogBridge {
ChromeActivity activity = (ChromeActivity) windowAndroid.getActivity().get(); ChromeActivity activity = (ChromeActivity) windowAndroid.getActivity().get();
mActivity = new WeakReference<>(activity); mActivity = new WeakReference<>(activity);
mCredentialLeakDialog = new PasswordManagerDialogCoordinator( mCredentialLeakDialog = new PasswordManagerDialogCoordinator(
windowAndroid.getContext().get(), activity.getModalDialogManager(), activity.getModalDialogManager(), activity.findViewById(android.R.id.content),
activity.findViewById(android.R.id.content), activity.getFullscreenManager(), activity.getFullscreenManager(), activity.getControlContainerHeightResource());
activity.getControlContainerHeightResource(), true);
} }
@CalledByNative @CalledByNative
...@@ -41,11 +39,16 @@ public class CredentialLeakDialogBridge { ...@@ -41,11 +39,16 @@ public class CredentialLeakDialogBridge {
@CalledByNative @CalledByNative
public void showDialog(String credentialLeakTitle, String credentialLeakDetails, public void showDialog(String credentialLeakTitle, String credentialLeakDetails,
String positiveButton, String negativeButton) { String positiveButton, String negativeButton) {
boolean primaryButtonFilled = negativeButton != null; if (mActivity.get() == null) return;
mCredentialLeakDialog.addHelpButton(this::showHelpArticle);
mCredentialLeakDialog.showDialog(credentialLeakTitle, credentialLeakDetails, PasswordManagerDialogContents contents = new PasswordManagerDialogContents(
R.drawable.password_check_warning, positiveButton, negativeButton, this::onClick, credentialLeakTitle, credentialLeakDetails, R.drawable.password_check_warning,
primaryButtonFilled, ModalDialogManager.ModalDialogType.APP); positiveButton, negativeButton, this::onClick);
contents.setPrimaryButtonFilled(negativeButton != null);
contents.setHelpButtonCallback(this::showHelpArticle);
mCredentialLeakDialog.initialize(mActivity.get(), contents);
mCredentialLeakDialog.showDialog();
} }
@CalledByNative @CalledByNative
......
...@@ -7,7 +7,7 @@ package org.chromium.chrome.browser.password_manager; ...@@ -7,7 +7,7 @@ package org.chromium.chrome.browser.password_manager;
import static org.chromium.chrome.browser.ChromeFeatureList.PASSWORD_MANAGER_ONBOARDING_ANDROID; import static org.chromium.chrome.browser.ChromeFeatureList.PASSWORD_MANAGER_ONBOARDING_ANDROID;
import static org.chromium.chrome.browser.ChromeFeatureList.getFieldTrialParamByFeature; import static org.chromium.chrome.browser.ChromeFeatureList.getFieldTrialParamByFeature;
import android.content.res.Resources; import android.content.Context;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
...@@ -17,11 +17,14 @@ import org.chromium.ui.base.WindowAndroid; ...@@ -17,11 +17,14 @@ import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.modaldialog.DialogDismissalCause; import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
import java.lang.ref.WeakReference;
/** JNI call glue between the native password manager onboarding class and Java objects. */ /** JNI call glue between the native password manager onboarding class and Java objects. */
public class OnboardingDialogBridge { public class OnboardingDialogBridge {
private long mNativeOnboardingDialogView; private long mNativeOnboardingDialogView;
private final PasswordManagerDialogCoordinator mOnboardingDialog; private final PasswordManagerDialogCoordinator mOnboardingDialog;
private final Resources mResources; private final WeakReference<Context> mContext;
/** Experiment parameter. */ /** Experiment parameter. */
private static final String EXPERIMENT_PARAMETER = "story"; private static final String EXPERIMENT_PARAMETER = "story";
/** Story centered on password safety and leak detection. */ /** Story centered on password safety and leak detection. */
...@@ -33,11 +36,10 @@ public class OnboardingDialogBridge { ...@@ -33,11 +36,10 @@ public class OnboardingDialogBridge {
mNativeOnboardingDialogView = nativeOnboardingDialogView; mNativeOnboardingDialogView = nativeOnboardingDialogView;
// TODO(crbug.com/983445): Get rid of this in favor of passing in direct dependencies. // TODO(crbug.com/983445): Get rid of this in favor of passing in direct dependencies.
ChromeActivity activity = (ChromeActivity) windowAndroid.getActivity().get(); ChromeActivity activity = (ChromeActivity) windowAndroid.getActivity().get();
mOnboardingDialog = new PasswordManagerDialogCoordinator(windowAndroid.getContext().get(), mOnboardingDialog = new PasswordManagerDialogCoordinator(activity.getModalDialogManager(),
activity.getModalDialogManager(), activity.findViewById(android.R.id.content), activity.findViewById(android.R.id.content), activity.getFullscreenManager(),
activity.getFullscreenManager(), activity.getControlContainerHeightResource(), activity.getControlContainerHeightResource());
false); mContext = new WeakReference<>(activity);
mResources = activity.getResources();
} }
@CalledByNative @CalledByNative
...@@ -64,10 +66,16 @@ public class OnboardingDialogBridge { ...@@ -64,10 +66,16 @@ public class OnboardingDialogBridge {
@CalledByNative @CalledByNative
public void showDialog(String onboardingTitle, String onboardingDetails) { public void showDialog(String onboardingTitle, String onboardingDetails) {
mOnboardingDialog.showDialog(onboardingTitle, onboardingDetails, if (mContext.get() == null) return;
getDrawableResourceFromFeature(), mResources.getString(R.string.continue_button),
mResources.getString(R.string.not_now), this::onClick, true, PasswordManagerDialogContents contents = new PasswordManagerDialogContents(onboardingTitle,
ModalDialogManager.ModalDialogType.TAB); onboardingDetails, getDrawableResourceFromFeature(),
mContext.get().getResources().getString(R.string.continue_button),
mContext.get().getResources().getString(R.string.not_now), this::onClick);
contents.setDialogType(ModalDialogManager.ModalDialogType.TAB);
mOnboardingDialog.initialize(mContext.get(), contents);
mOnboardingDialog.showDialog();
} }
@CalledByNative @CalledByNative
......
// Copyright 2019 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.password_manager;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import org.chromium.base.Callback;
import org.chromium.ui.modaldialog.ModalDialogManager;
/**
* Class containing all data that customizes the contents displayed in the dialog.
*/
public class PasswordManagerDialogContents {
private final String mTitle;
private final String mDetails;
private final String mPrimaryButtonText;
private final @Nullable String mSecondaryButtonText;
private final @IdRes int mIllustrationId;
private final Callback<Integer> mButtonClickCallback;
private boolean mPrimaryButtonFilled;
private @Nullable Runnable mHelpButtonCallback;
private @ModalDialogManager.ModalDialogType int mDialogType;
/**
* Constructor for the dialog contents.
*
* @param title The title of the dialog, to be displayed below the image.
* @param details The details text to be displayed under the title.
* @param illustrationId The resource id of the image displayed above the title.
* @param primaryButtonText The text of the primary button.
* @param secondaryButtonText The text of the secondary button or null if there shouldn't be a
* secondary button.
* @param buttonClickCallback The callback handling the click on the buttons. It takes the type
* of the button as a parameter.
*/
public PasswordManagerDialogContents(String title, String details, int illustrationId,
String primaryButtonText, @Nullable String secondaryButtonText,
Callback<Integer> buttonClickCallback) {
mTitle = title;
mDetails = details;
mPrimaryButtonText = primaryButtonText;
mSecondaryButtonText = secondaryButtonText;
mIllustrationId = illustrationId;
mButtonClickCallback = buttonClickCallback;
mPrimaryButtonFilled = false;
mHelpButtonCallback = null;
mDialogType = ModalDialogManager.ModalDialogType.APP;
}
/**
* Sets whether or not the primary button should be displayed as filled.
*/
public void setPrimaryButtonFilled(boolean primaryButtonFilled) {
mPrimaryButtonFilled = primaryButtonFilled;
}
/**
* Sets a callback to be invoked when the help button is clicked. If left null, no help button
* will be displayed.
*/
public void setHelpButtonCallback(Runnable helpButtonCallback) {
mHelpButtonCallback = helpButtonCallback;
}
/**
* Sets type of the modal dialog to be displayed: app or tab modal.
*/
public void setDialogType(@ModalDialogManager.ModalDialogType int type) {
mDialogType = type;
}
/**
* Returns the title of the dialog. It is also used as content description.
*/
public String getTitle() {
return mTitle;
}
/**
* Returns the details to be displayed in the dialog under the title.
*/
public String getDetails() {
return mDetails;
}
/**
* Returns the text displayed in the primary button.
*/
public String getPrimaryButtonText() {
return mPrimaryButtonText;
}
/**
* Returns the text displayed in the secondary button or null if the dialog has only one button.
*/
@Nullable
public String getSecondaryButtonText() {
return mSecondaryButtonText;
}
/**
* The resource id of the image displayed above the title.
*/
public @IdRes int getIllustrationId() {
return mIllustrationId;
}
/**
* The callback invoked when either of the two dialog buttons is clicked.
* @return A {@link Callback} taking an {@link Integer} as a parameter which represents which
* button was clicked.
*/
public Callback getButtonClickCallback() {
return mButtonClickCallback;
}
/**
* Whether the primary button should be displayed as filled or not.
*/
public boolean isPrimaryButtonFilled() {
return mPrimaryButtonFilled;
}
/**
* Returns the callback handling the click on the help icon or null if no help icon should be
* displayed.
*/
@Nullable
public Runnable getHelpButtonCallback() {
return mHelpButtonCallback;
}
/**
* The type of the dialog: app modal or tab modal.
*/
public @ModalDialogManager.ModalDialogType int getDialogType() {
return mDialogType;
}
}
...@@ -4,14 +4,17 @@ ...@@ -4,14 +4,17 @@
package org.chromium.chrome.browser.password_manager; package org.chromium.chrome.browser.password_manager;
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.DETAILS;
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.HELP_BUTTON_CALLBACK;
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.ILLUSTRATION;
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.TITLE;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import androidx.annotation.DrawableRes;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.Callback;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.ui.modaldialog.DialogDismissalCause; import org.chromium.ui.modaldialog.DialogDismissalCause;
...@@ -26,42 +29,41 @@ import org.chromium.ui.modelutil.PropertyModelChangeProcessor; ...@@ -26,42 +29,41 @@ import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
*/ */
public class PasswordManagerDialogCoordinator { public class PasswordManagerDialogCoordinator {
private final PasswordManagerDialogMediator mMediator; private final PasswordManagerDialogMediator mMediator;
private PropertyModel mModel;
PasswordManagerDialogCoordinator(ModalDialogManager modalDialogManager, View androidContentView,
ChromeFullscreenManager fullscreenManager, int containerHeightResource) {
mMediator = new PasswordManagerDialogMediator(
new PropertyModel.Builder(ModalDialogProperties.ALL_KEYS), modalDialogManager,
androidContentView, fullscreenManager, containerHeightResource);
}
PasswordManagerDialogCoordinator(Context context, ModalDialogManager modalDialogManager, public void initialize(Context context, PasswordManagerDialogContents contents) {
View androidContentView, ChromeFullscreenManager fullscreenManager, View customView = contents.getHelpButtonCallback() != null
int containerHeightResource, boolean withHelpIcon) {
PropertyModel mModel = PasswordManagerDialogProperties.defaultModelBuilder().build();
View customView = withHelpIcon
? LayoutInflater.from(context).inflate( ? LayoutInflater.from(context).inflate(
R.layout.password_manager_dialog_with_help_button, null) R.layout.password_manager_dialog_with_help_button, null)
: LayoutInflater.from(context).inflate(R.layout.password_manager_dialog, null); : LayoutInflater.from(context).inflate(R.layout.password_manager_dialog, null);
mModel = buildModel(contents);
mMediator = new PasswordManagerDialogMediator(mModel, createDialogModelBuilder(customView), mMediator.initialize(mModel, customView, contents);
modalDialogManager, androidContentView, customView.getResources(),
fullscreenManager, containerHeightResource);
PropertyModelChangeProcessor.create( PropertyModelChangeProcessor.create(
mModel, customView, PasswordManagerDialogViewBinder::bind); mModel, customView, PasswordManagerDialogViewBinder::bind);
} }
public void showDialog(String title, String details, @DrawableRes int drawableId, public void showDialog() {
String positiveButtonText, String negativeButtonText, Callback<Integer> onClick, mMediator.showDialog();
boolean primaryButtonFilled, @ModalDialogManager.ModalDialogType int type) {
mMediator.setContents(title, details, drawableId);
mMediator.setButtons(positiveButtonText, negativeButtonText, onClick, primaryButtonFilled);
mMediator.showDialog(type);
}
public void addHelpButton(Runnable callback) {
mMediator.setHelpButtonCallback(callback);
} }
public void dismissDialog(@DialogDismissalCause int dismissalCause) { public void dismissDialog(@DialogDismissalCause int dismissalCause) {
mMediator.dismissDialog(dismissalCause); mMediator.dismissDialog(dismissalCause);
} }
private static PropertyModel.Builder createDialogModelBuilder(View customView) { private PropertyModel buildModel(PasswordManagerDialogContents contents) {
return new PropertyModel.Builder(ModalDialogProperties.ALL_KEYS) return PasswordManagerDialogProperties.defaultModelBuilder()
.with(ModalDialogProperties.CUSTOM_VIEW, customView); .with(TITLE, contents.getTitle())
.with(DETAILS, contents.getDetails())
.with(ILLUSTRATION, contents.getIllustrationId())
.with(HELP_BUTTON_CALLBACK, contents.getHelpButtonCallback())
.build();
} }
@VisibleForTesting @VisibleForTesting
......
...@@ -4,16 +4,11 @@ ...@@ -4,16 +4,11 @@
package org.chromium.chrome.browser.password_manager; package org.chromium.chrome.browser.password_manager;
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.DETAILS;
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.HELP_BUTTON_CALLBACK;
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.ILLUSTRATION;
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.ILLUSTRATION_VISIBLE; import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.ILLUSTRATION_VISIBLE;
import static org.chromium.chrome.browser.password_manager.PasswordManagerDialogProperties.TITLE;
import android.content.res.Resources; import android.content.res.Resources;
import android.view.View; import android.view.View;
import androidx.annotation.DrawableRes;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.Callback; import org.chromium.base.Callback;
...@@ -32,15 +27,17 @@ import org.chromium.ui.modelutil.PropertyModel; ...@@ -32,15 +27,17 @@ import org.chromium.ui.modelutil.PropertyModel;
* dialog). * dialog).
*/ */
class PasswordManagerDialogMediator implements View.OnLayoutChangeListener { class PasswordManagerDialogMediator implements View.OnLayoutChangeListener {
private final PropertyModel mModel;
private final ModalDialogManager mDialogManager; private final ModalDialogManager mDialogManager;
private PropertyModel.Builder mModalDialogBuilder;
private PropertyModel mDialogModel;
private final View mAndroidContentView; private final View mAndroidContentView;
private final Resources mResources;
private final ChromeFullscreenManager mFullscreenManager; private final ChromeFullscreenManager mFullscreenManager;
private final int mContainerHeightResource; private final int mContainerHeightResource;
private PropertyModel.Builder mHostDialogModelBuilder;
private PropertyModel mHostDialogModel;
private PropertyModel mModel;
private Resources mResources;
private @ModalDialogManager.ModalDialogType int mDialogType;
private static class DialogClickHandler implements ModalDialogProperties.Controller { private static class DialogClickHandler implements ModalDialogProperties.Controller {
private Callback<Integer> mCallback; private Callback<Integer> mCallback;
...@@ -68,39 +65,38 @@ class PasswordManagerDialogMediator implements View.OnLayoutChangeListener { ...@@ -68,39 +65,38 @@ class PasswordManagerDialogMediator implements View.OnLayoutChangeListener {
} }
} }
PasswordManagerDialogMediator(PropertyModel model, PropertyModel.Builder dialogBuilder, PasswordManagerDialogMediator(PropertyModel.Builder hostDialogModelBuilder,
ModalDialogManager manager, View androidContentView, Resources resources, ModalDialogManager manager, View androidContentView,
ChromeFullscreenManager fullscreenManager, int containerHeightResource) { ChromeFullscreenManager fullscreenManager, int containerHeightResource) {
mModel = model;
mDialogManager = manager; mDialogManager = manager;
mModalDialogBuilder = dialogBuilder; mHostDialogModelBuilder = hostDialogModelBuilder;
mAndroidContentView = androidContentView; mAndroidContentView = androidContentView;
mResources = resources;
mFullscreenManager = fullscreenManager; mFullscreenManager = fullscreenManager;
mContainerHeightResource = containerHeightResource; mContainerHeightResource = containerHeightResource;
mAndroidContentView.addOnLayoutChangeListener(this); mAndroidContentView.addOnLayoutChangeListener(this);
} }
void setContents(String title, String details, @DrawableRes int drawableId) { void initialize(PropertyModel model, View view, PasswordManagerDialogContents contents) {
mModel.set(ILLUSTRATION, drawableId); mResources = view.getResources();
mModel.set(TITLE, title); mModel = model;
mModalDialogBuilder.with(ModalDialogProperties.CONTENT_DESCRIPTION, title); mHostDialogModel =
mModel.set(DETAILS, details); mHostDialogModelBuilder.with(ModalDialogProperties.CUSTOM_VIEW, view)
} .with(ModalDialogProperties.CONTROLLER,
new DialogClickHandler(contents.getButtonClickCallback()))
void setButtons(String positiveButtonText, String negativeButtonText, Callback<Integer> onClick, .with(ModalDialogProperties.CONTENT_DESCRIPTION, contents.getTitle())
boolean primaryButtonFilled) { .with(ModalDialogProperties.POSITIVE_BUTTON_TEXT,
mModalDialogBuilder.with(ModalDialogProperties.CONTROLLER, new DialogClickHandler(onClick)) contents.getPrimaryButtonText())
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT, positiveButtonText) .with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT,
.with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT, negativeButtonText) contents.getSecondaryButtonText())
.with(ModalDialogProperties.PRIMARY_BUTTON_FILLED, primaryButtonFilled); .with(ModalDialogProperties.PRIMARY_BUTTON_FILLED,
} contents.isPrimaryButtonFilled())
.build();
void setHelpButtonCallback(Runnable callback) { mDialogType = contents.getDialogType();
mModel.set(HELP_BUTTON_CALLBACK, callback);
} }
private boolean hasSufficientSpaceForIllustration(int heightPx) { private boolean hasSufficientSpaceForIllustration(int heightPx) {
// If |mResources| is null, it means that the dialog was not initialized yet.
if (mResources == null) return false;
heightPx -= TabModalPresenter.getContainerTopMargin(mResources, mContainerHeightResource); heightPx -= TabModalPresenter.getContainerTopMargin(mResources, mContainerHeightResource);
heightPx -= TabModalPresenter.getContainerBottomMargin(mFullscreenManager); heightPx -= TabModalPresenter.getContainerBottomMargin(mFullscreenManager);
return heightPx >= mResources.getDimensionPixelSize( return heightPx >= mResources.getDimensionPixelSize(
...@@ -110,6 +106,8 @@ class PasswordManagerDialogMediator implements View.OnLayoutChangeListener { ...@@ -110,6 +106,8 @@ class PasswordManagerDialogMediator implements View.OnLayoutChangeListener {
@Override @Override
public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft,
int oldTop, int oldRight, int oldBottom) { int oldTop, int oldRight, int oldBottom) {
// Return if the dialog wasn't initialized
if (mModel == null) return;
int oldHeight = oldBottom - oldTop; int oldHeight = oldBottom - oldTop;
int newHeight = bottom - top; int newHeight = bottom - top;
if (newHeight == oldHeight) return; if (newHeight == oldHeight) return;
...@@ -118,15 +116,15 @@ class PasswordManagerDialogMediator implements View.OnLayoutChangeListener { ...@@ -118,15 +116,15 @@ class PasswordManagerDialogMediator implements View.OnLayoutChangeListener {
}); });
} }
void showDialog(@ModalDialogManager.ModalDialogType int type) { void showDialog() {
mModel.set(ILLUSTRATION_VISIBLE, mModel.set(ILLUSTRATION_VISIBLE,
hasSufficientSpaceForIllustration(mAndroidContentView.getHeight())); hasSufficientSpaceForIllustration(mAndroidContentView.getHeight()));
mDialogModel = mModalDialogBuilder.build(); mHostDialogModel = mHostDialogModelBuilder.build();
mDialogManager.showDialog(mDialogModel, type); mDialogManager.showDialog(mHostDialogModel, mDialogType);
} }
void dismissDialog(int dismissalClause) { void dismissDialog(int dismissalCause) {
mDialogManager.dismissDialog(mDialogModel, dismissalClause); mDialogManager.dismissDialog(mHostDialogModel, dismissalCause);
mAndroidContentView.removeOnLayoutChangeListener(this); mAndroidContentView.removeOnLayoutChangeListener(this);
} }
......
...@@ -5,30 +5,29 @@ ...@@ -5,30 +5,29 @@
package org.chromium.chrome.browser.password_manager; package org.chromium.chrome.browser.password_manager;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModel.ReadableIntPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.ReadableObjectPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableBooleanPropertyKey; import org.chromium.ui.modelutil.PropertyModel.WritableBooleanPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableIntPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableObjectPropertyKey;
/** /**
* Data properties for the password manager illustration modal dialog. * Data properties for the password manager illustration modal dialog.
*/ */
class PasswordManagerDialogProperties { class PasswordManagerDialogProperties {
// Callback handling clicks on the help button. If present, the button will be shown. // Callback handling clicks on the help button. If present, the button will be shown.
static final WritableObjectPropertyKey<Runnable> HELP_BUTTON_CALLBACK = static final ReadableObjectPropertyKey<Runnable> HELP_BUTTON_CALLBACK =
new WritableObjectPropertyKey<>(); new ReadableObjectPropertyKey<>();
// Illustration drawable resource id for the password manager. // Illustration drawable resource id for the password manager.
static final WritableIntPropertyKey ILLUSTRATION = new WritableIntPropertyKey(); static final ReadableIntPropertyKey ILLUSTRATION = new ReadableIntPropertyKey();
// Boolean indicating whether there is enough space for the illustration to be shown. // Boolean indicating whether there is enough space for the illustration to be shown.
static final WritableBooleanPropertyKey ILLUSTRATION_VISIBLE = new WritableBooleanPropertyKey(); static final WritableBooleanPropertyKey ILLUSTRATION_VISIBLE = new WritableBooleanPropertyKey();
// Title that appears below the illustration. // Title that appears below the illustration.
static final WritableObjectPropertyKey<String> TITLE = new WritableObjectPropertyKey<>(); static final ReadableObjectPropertyKey<String> TITLE = new ReadableObjectPropertyKey<>();
// Multiline explanation text displayed under the illustration. // Multiline explanation text displayed under the illustration.
static final WritableObjectPropertyKey<CharSequence> DETAILS = static final ReadableObjectPropertyKey<String> DETAILS = new ReadableObjectPropertyKey<>();
new WritableObjectPropertyKey<>();
private PasswordManagerDialogProperties() {} private PasswordManagerDialogProperties() {}
......
...@@ -71,7 +71,7 @@ public class PasswordManagerDialogView extends ScrollView { ...@@ -71,7 +71,7 @@ public class PasswordManagerDialogView extends ScrollView {
mTitleView.setText(title); mTitleView.setText(title);
} }
void setDetails(CharSequence details) { void setDetails(String details) {
mDetailsView.setText(details); mDetailsView.setText(details);
} }
} }
...@@ -67,17 +67,16 @@ public class PasswordManagerDialogTest { ...@@ -67,17 +67,16 @@ public class PasswordManagerDialogTest {
public void setUp() throws InterruptedException { public void setUp() throws InterruptedException {
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
ChromeActivity activity = (ChromeActivity) mActivityTestRule.getActivity(); ChromeActivity activity = (ChromeActivity) mActivityTestRule.getActivity();
mCoordinator = new PasswordManagerDialogCoordinator( mCoordinator = new PasswordManagerDialogCoordinator(activity.getModalDialogManager(),
activity.getWindowAndroid().getContext().get(), activity.getModalDialogManager(),
activity.findViewById(android.R.id.content), activity.getFullscreenManager(), activity.findViewById(android.R.id.content), activity.getFullscreenManager(),
activity.getControlContainerHeightResource(), false); activity.getControlContainerHeightResource());
PasswordManagerDialogContents contents = new PasswordManagerDialogContents(TITLE, DETAILS,
R.drawable.data_reduction_illustration, OK_BUTTON, CANCEL_BUTTON, mOnClick);
contents.setDialogType(ModalDialogManager.ModalDialogType.TAB);
mCoordinator.initialize(activity.getWindowAndroid().getContext().get(), contents);
mMediator = mCoordinator.getMediatorForTesting(); mMediator = mCoordinator.getMediatorForTesting();
mModel = mMediator.getModelForTesting(); mModel = mMediator.getModelForTesting();
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> { mCoordinator.showDialog(); });
mCoordinator.showDialog(TITLE, DETAILS, R.drawable.data_reduction_illustration,
OK_BUTTON, CANCEL_BUTTON, mOnClick, false,
ModalDialogManager.ModalDialogType.TAB);
});
} }
@Test @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