Commit e01a6366 authored by Alice Wang's avatar Alice Wang Committed by Chromium LUCI CQ

[WebSignin][Android] Refactor ViewBinder in account_picker MVC

This CL refactors the ViewBinders in account_picker MVC in two ways:

1/ Make all view binders implements the ViewBinder interface instead of
using static class;
2/ Merge IncognitoRowViewBinder and AddAccountRowViewBinder into one
reusable class.

Bug: 1158373
Change-Id: I6a1f5442c52e4eb8e2115cd34c140822a494bdfe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2589934
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837498}
parent ff2361da
...@@ -1264,9 +1264,8 @@ chrome_java_sources = [ ...@@ -1264,9 +1264,8 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/signin/account_picker/AccountPickerDelegateImpl.java", "java/src/org/chromium/chrome/browser/signin/account_picker/AccountPickerDelegateImpl.java",
"java/src/org/chromium/chrome/browser/signin/account_picker/AccountPickerMediator.java", "java/src/org/chromium/chrome/browser/signin/account_picker/AccountPickerMediator.java",
"java/src/org/chromium/chrome/browser/signin/account_picker/AccountPickerProperties.java", "java/src/org/chromium/chrome/browser/signin/account_picker/AccountPickerProperties.java",
"java/src/org/chromium/chrome/browser/signin/account_picker/AddAccountRowViewBinder.java",
"java/src/org/chromium/chrome/browser/signin/account_picker/ExistingAccountRowViewBinder.java", "java/src/org/chromium/chrome/browser/signin/account_picker/ExistingAccountRowViewBinder.java",
"java/src/org/chromium/chrome/browser/signin/account_picker/IncognitoAccountRowViewBinder.java", "java/src/org/chromium/chrome/browser/signin/account_picker/OnClickListenerViewBinder.java",
"java/src/org/chromium/chrome/browser/site_settings/ChromeSiteSettingsClient.java", "java/src/org/chromium/chrome/browser/site_settings/ChromeSiteSettingsClient.java",
"java/src/org/chromium/chrome/browser/site_settings/ChromeSiteSettingsHelpClient.java", "java/src/org/chromium/chrome/browser/site_settings/ChromeSiteSettingsHelpClient.java",
"java/src/org/chromium/chrome/browser/site_settings/ChromeWebappSettingsClient.java", "java/src/org/chromium/chrome/browser/site_settings/ChromeWebappSettingsClient.java",
......
...@@ -10,6 +10,8 @@ import androidx.recyclerview.widget.RecyclerView; ...@@ -10,6 +10,8 @@ import androidx.recyclerview.widget.RecyclerView;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerProperties.AddAccountRowProperties;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerProperties.IncognitoAccountRowProperties;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerProperties.ItemType; import org.chromium.chrome.browser.signin.account_picker.AccountPickerProperties.ItemType;
import org.chromium.ui.modelutil.LayoutViewBuilder; import org.chromium.ui.modelutil.LayoutViewBuilder;
import org.chromium.ui.modelutil.MVCListAdapter; import org.chromium.ui.modelutil.MVCListAdapter;
...@@ -70,15 +72,15 @@ public class AccountPickerCoordinator { ...@@ -70,15 +72,15 @@ public class AccountPickerCoordinator {
new LayoutViewBuilder<>(isMobileIdentityConsistencyEnabled new LayoutViewBuilder<>(isMobileIdentityConsistencyEnabled
? R.layout.account_picker_new_account_row ? R.layout.account_picker_new_account_row
: R.layout.account_picker_new_account_row_legacy), : R.layout.account_picker_new_account_row_legacy),
AddAccountRowViewBinder::bindView); new OnClickListenerViewBinder(AddAccountRowProperties.ON_CLICK_LISTENER));
adapter.registerType(ItemType.EXISTING_ACCOUNT_ROW, adapter.registerType(ItemType.EXISTING_ACCOUNT_ROW,
new LayoutViewBuilder<>(isMobileIdentityConsistencyEnabled new LayoutViewBuilder<>(isMobileIdentityConsistencyEnabled
? R.layout.account_picker_row ? R.layout.account_picker_row
: R.layout.account_picker_row_legacy), : R.layout.account_picker_row_legacy),
ExistingAccountRowViewBinder::bindView); new ExistingAccountRowViewBinder());
adapter.registerType(ItemType.INCOGNITO_ACCOUNT_ROW, adapter.registerType(ItemType.INCOGNITO_ACCOUNT_ROW,
new LayoutViewBuilder<>(R.layout.account_picker_incognito_row), new LayoutViewBuilder<>(R.layout.account_picker_incognito_row),
IncognitoAccountRowViewBinder::bindView); new OnClickListenerViewBinder(IncognitoAccountRowProperties.ON_CLICK_LISTENER));
view.setAdapter(adapter); view.setAdapter(adapter);
mMediator = new AccountPickerMediator( mMediator = new AccountPickerMediator(
......
...@@ -100,13 +100,13 @@ class AccountPickerProperties { ...@@ -100,13 +100,13 @@ class AccountPickerProperties {
/** /**
* Item type for models created with {@link AddAccountRowProperties#createModel} and * Item type for models created with {@link AddAccountRowProperties#createModel} and
* use {@link AddAccountRowViewBinder} for view setup. * use {@link OnClickListenerViewBinder} for view setup.
*/ */
int ADD_ACCOUNT_ROW = 2; int ADD_ACCOUNT_ROW = 2;
/** /**
* Item type for models created with {@link IncognitoAccountRowProperties#createModel} and * Item type for models created with {@link IncognitoAccountRowProperties#createModel} and
* use {@link IncognitoAccountRowViewBinder} for view setup. * use {@link OnClickListenerViewBinder} for view setup.
*/ */
int INCOGNITO_ACCOUNT_ROW = 3; int INCOGNITO_ACCOUNT_ROW = 3;
} }
......
// 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.signin.account_picker;
import android.view.View;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerProperties.AddAccountRowProperties;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
/**
* This class regroups the buildView and bindView util methods of the
* add account row.
*/
class AddAccountRowViewBinder {
private AddAccountRowViewBinder() {}
static void bindView(PropertyModel model, View view, PropertyKey propertyKey) {
if (propertyKey == AddAccountRowProperties.ON_CLICK_LISTENER) {
view.setOnClickListener(model.get(AddAccountRowProperties.ON_CLICK_LISTENER));
} else {
throw new IllegalArgumentException(
"Cannot update the view for propertyKey: " + propertyKey);
}
}
}
...@@ -17,15 +17,19 @@ import org.chromium.chrome.browser.signin.account_picker.AccountPickerProperties ...@@ -17,15 +17,19 @@ import org.chromium.chrome.browser.signin.account_picker.AccountPickerProperties
import org.chromium.chrome.browser.signin.services.DisplayableProfileData; import org.chromium.chrome.browser.signin.services.DisplayableProfileData;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor.ViewBinder;
/** /**
* This class regroups the buildView and bindView util methods of the * This class regroups the buildView and bindView util methods of the
* existing account row. * existing account row.
*/ */
class ExistingAccountRowViewBinder { class ExistingAccountRowViewBinder implements ViewBinder<PropertyModel, View, PropertyKey> {
private ExistingAccountRowViewBinder() {} /**
* View binder that associates an existing account view with the model of
static void bindView(PropertyModel model, View view, PropertyKey propertyKey) { * {@link ExistingAccountRowProperties}.
*/
@Override
public void bind(PropertyModel model, View view, PropertyKey propertyKey) {
DisplayableProfileData profileData = model.get(ExistingAccountRowProperties.PROFILE_DATA); DisplayableProfileData profileData = model.get(ExistingAccountRowProperties.PROFILE_DATA);
if (propertyKey == ExistingAccountRowProperties.ON_CLICK_LISTENER) { if (propertyKey == ExistingAccountRowProperties.ON_CLICK_LISTENER) {
view.setOnClickListener(v view.setOnClickListener(v
......
// 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.signin.account_picker;
import android.view.View;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerProperties.IncognitoAccountRowProperties;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
/**
* This class regroups the buildView and bindView util methods of the
* incognito account row.
*/
class IncognitoAccountRowViewBinder {
private IncognitoAccountRowViewBinder() {}
static void bindView(PropertyModel model, View view, PropertyKey propertyKey) {
if (propertyKey == IncognitoAccountRowProperties.ON_CLICK_LISTENER) {
view.setOnClickListener(model.get(IncognitoAccountRowProperties.ON_CLICK_LISTENER));
} else {
throw new IllegalArgumentException(
"Cannot update the view for propertyKey: " + propertyKey);
}
}
}
// 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.signin.account_picker;
import android.view.View;
import android.view.View.OnClickListener;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModel.ReadableObjectPropertyKey;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor.ViewBinder;
/**
* This class binds an {@link OnClickListener} to a {@link View}.
*/
class OnClickListenerViewBinder implements ViewBinder<PropertyModel, View, PropertyKey> {
private final ReadableObjectPropertyKey<OnClickListener> mOnClickListenerKey;
OnClickListenerViewBinder(ReadableObjectPropertyKey<OnClickListener> onClickListenerKey) {
mOnClickListenerKey = onClickListenerKey;
}
/**
* View binder that sets the {@link OnClickListener} of the view with the corresponding
* property in model.
*/
@Override
public void bind(PropertyModel model, View view, PropertyKey propertyKey) {
assert propertyKey == mOnClickListenerKey : "Unknown propertyKey: " + propertyKey;
view.setOnClickListener(model.get(mOnClickListenerKey));
}
}
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