Commit b5188d9f authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][WebSignin] Use OnClickListener for listener property keys

This CL replaces the Runnable type with OnClickListener type for
listener property keys to make the code more readable.

No behavior change for this CL.

Bug: 1124737
Change-Id: I06e5634f68891d52917603fe6ce9fa61f479bd67
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2390911Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804705}
parent ebebefda
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.signin.account_picker; package org.chromium.chrome.browser.signin.account_picker;
import android.view.View.OnClickListener;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import org.chromium.chrome.browser.signin.DisplayableProfileData; import org.chromium.chrome.browser.signin.DisplayableProfileData;
...@@ -102,14 +104,14 @@ class AccountPickerBottomSheetProperties { ...@@ -102,14 +104,14 @@ class AccountPickerBottomSheetProperties {
// PropertyKeys for the selected account view when the account list is collapsed. // PropertyKeys for the selected account view when the account list is collapsed.
// The selected account view is replaced by account list view when the // The selected account view is replaced by account list view when the
// account list is expanded. // account list is expanded.
static final ReadableObjectPropertyKey<Runnable> ON_SELECTED_ACCOUNT_CLICKED = static final ReadableObjectPropertyKey<OnClickListener> ON_SELECTED_ACCOUNT_CLICKED =
new ReadableObjectPropertyKey<>("on_selected_account_clicked"); new ReadableObjectPropertyKey<>("on_selected_account_clicked");
static final WritableObjectPropertyKey<DisplayableProfileData> SELECTED_ACCOUNT_DATA = static final WritableObjectPropertyKey<DisplayableProfileData> SELECTED_ACCOUNT_DATA =
new WritableObjectPropertyKey<>("selected_account_data"); new WritableObjectPropertyKey<>("selected_account_data");
// PropertyKey for the button |Continue as ...| // PropertyKey for the button |Continue as ...|
// The button is visible during all the lifecycle of the bottom sheet // The button is visible during all the lifecycle of the bottom sheet
static final ReadableObjectPropertyKey<Runnable> ON_CONTINUE_AS_CLICKED = static final ReadableObjectPropertyKey<OnClickListener> ON_CONTINUE_AS_CLICKED =
new ReadableObjectPropertyKey<>("on_continue_as_clicked"); new ReadableObjectPropertyKey<>("on_continue_as_clicked");
// PropertyKey indicates the view state of the account picker bottom sheet // PropertyKey indicates the view state of the account picker bottom sheet
...@@ -127,9 +129,9 @@ class AccountPickerBottomSheetProperties { ...@@ -127,9 +129,9 @@ class AccountPickerBottomSheetProperties {
static PropertyModel createModel( static PropertyModel createModel(
Runnable onSelectedAccountClicked, Runnable onContinueAsClicked) { Runnable onSelectedAccountClicked, Runnable onContinueAsClicked) {
return new PropertyModel.Builder(ALL_KEYS) return new PropertyModel.Builder(ALL_KEYS)
.with(ON_SELECTED_ACCOUNT_CLICKED, onSelectedAccountClicked) .with(ON_SELECTED_ACCOUNT_CLICKED, v -> onSelectedAccountClicked.run())
.with(SELECTED_ACCOUNT_DATA, null) .with(SELECTED_ACCOUNT_DATA, null)
.with(ON_CONTINUE_AS_CLICKED, onContinueAsClicked) .with(ON_CONTINUE_AS_CLICKED, v -> onContinueAsClicked.run())
.with(VIEW_STATE, ViewState.NO_ACCOUNTS) .with(VIEW_STATE, ViewState.NO_ACCOUNTS)
.build(); .build();
} }
......
...@@ -16,9 +16,8 @@ class AccountPickerBottomSheetViewBinder { ...@@ -16,9 +16,8 @@ class AccountPickerBottomSheetViewBinder {
static void bind( static void bind(
PropertyModel model, AccountPickerBottomSheetView view, PropertyKey propertyKey) { PropertyModel model, AccountPickerBottomSheetView view, PropertyKey propertyKey) {
if (propertyKey == AccountPickerBottomSheetProperties.ON_SELECTED_ACCOUNT_CLICKED) { if (propertyKey == AccountPickerBottomSheetProperties.ON_SELECTED_ACCOUNT_CLICKED) {
view.getSelectedAccountView().setOnClickListener(v -> { view.getSelectedAccountView().setOnClickListener(
model.get(AccountPickerBottomSheetProperties.ON_SELECTED_ACCOUNT_CLICKED).run(); model.get(AccountPickerBottomSheetProperties.ON_SELECTED_ACCOUNT_CLICKED));
});
} else if (propertyKey == AccountPickerBottomSheetProperties.VIEW_STATE) { } else if (propertyKey == AccountPickerBottomSheetProperties.VIEW_STATE) {
@ViewState @ViewState
int viewState = model.get(AccountPickerBottomSheetProperties.VIEW_STATE); int viewState = model.get(AccountPickerBottomSheetProperties.VIEW_STATE);
...@@ -30,9 +29,8 @@ class AccountPickerBottomSheetViewBinder { ...@@ -30,9 +29,8 @@ class AccountPickerBottomSheetViewBinder {
view.updateSelectedAccount(profileData); view.updateSelectedAccount(profileData);
} }
} else if (propertyKey == AccountPickerBottomSheetProperties.ON_CONTINUE_AS_CLICKED) { } else if (propertyKey == AccountPickerBottomSheetProperties.ON_CONTINUE_AS_CLICKED) {
view.getContinueAsButton().setOnClickListener(v -> { view.getContinueAsButton().setOnClickListener(
model.get(AccountPickerBottomSheetProperties.ON_CONTINUE_AS_CLICKED).run(); model.get(AccountPickerBottomSheetProperties.ON_CONTINUE_AS_CLICKED));
});
} }
} }
......
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