Commit 4b4e0261 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][WebSignin] Rename account picker state as ViewState

This CL renames AccountPickerBottomSheetState as ViewState to make the
code more readable. There is no behavior change in this CL.

Bug: 1121499
Change-Id: Idaa9d72238e6012fe6f71dec7928ed41760d8582
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2375291Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801760}
parent 913934a4
......@@ -13,7 +13,7 @@ import androidx.annotation.Nullable;
import org.chromium.base.task.AsyncTask;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.signin.ProfileDataCache;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetProperties.AccountPickerBottomSheetState;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetProperties.ViewState;
import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.AccountManagerFacadeProvider;
import org.chromium.components.signin.AccountUtils;
......@@ -68,8 +68,7 @@ class AccountPickerBottomSheetMediator implements AccountPickerCoordinator.Liste
public void onAccountSelected(String accountName, boolean isDefaultAccount) {
// Clicking on one account in the account list when the account list is expanded
// will collapse it to the selected account
mModel.set(AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE,
AccountPickerBottomSheetState.COLLAPSED_ACCOUNT_LIST);
mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, ViewState.COLLAPSED_ACCOUNT_LIST);
setSelectedAccountName(accountName);
}
......@@ -86,8 +85,7 @@ class AccountPickerBottomSheetMediator implements AccountPickerCoordinator.Liste
*/
@Override
public void goIncognitoMode() {
mModel.set(AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE,
AccountPickerBottomSheetState.INCOGNITO_INTERSTITIAL);
mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, ViewState.INCOGNITO_INTERSTITIAL);
mAccountPickerDelegate.goIncognitoMode();
}
......@@ -111,24 +109,22 @@ class AccountPickerBottomSheetMediator implements AccountPickerCoordinator.Liste
if (accounts.isEmpty()) {
// If all accounts disappeared, no matter if the account list is collapsed or expanded,
// we will go to the zero account screen.
mModel.set(AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE,
AccountPickerBottomSheetState.NO_ACCOUNTS);
mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, ViewState.NO_ACCOUNTS);
mSelectedAccountName = null;
mModel.set(AccountPickerBottomSheetProperties.SELECTED_ACCOUNT_DATA, null);
return;
}
@AccountPickerBottomSheetState
int state =
mModel.get(AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE);
if (state == AccountPickerBottomSheetState.NO_ACCOUNTS) {
@ViewState
int viewState = mModel.get(AccountPickerBottomSheetProperties.VIEW_STATE);
if (viewState == ViewState.NO_ACCOUNTS) {
// When a non-empty account list appears while it is currently zero-account screen,
// we should change the screen to collapsed account list and set the selected account
// to the first account of the account list
mModel.set(AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE,
AccountPickerBottomSheetState.COLLAPSED_ACCOUNT_LIST);
mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE,
ViewState.COLLAPSED_ACCOUNT_LIST);
setSelectedAccountName(accounts.get(0).name);
} else if (state == AccountPickerBottomSheetState.COLLAPSED_ACCOUNT_LIST
} else if (viewState == ViewState.COLLAPSED_ACCOUNT_LIST
&& AccountUtils.findAccountByName(accounts, mSelectedAccountName) == null) {
// When it is already collapsed account list, we update the selected account only
// when the current selected account name is no longer in the new account list
......@@ -159,8 +155,7 @@ class AccountPickerBottomSheetMediator implements AccountPickerCoordinator.Liste
private void onSelectedAccountClicked() {
// Clicking on the selected account when the account list is collapsed will expand the
// account list and make the account list visible
mModel.set(AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE,
AccountPickerBottomSheetState.EXPANDED_ACCOUNT_LIST);
mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, ViewState.EXPANDED_ACCOUNT_LIST);
}
/**
......@@ -171,8 +166,7 @@ class AccountPickerBottomSheetMediator implements AccountPickerCoordinator.Liste
if (mSelectedAccountName == null) {
addAccount();
} else {
mModel.set(AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE,
AccountPickerBottomSheetState.SIGNIN_IN_PROGRESS);
mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, ViewState.SIGNIN_IN_PROGRESS);
new AsyncTask<String>() {
@Override
protected String doInBackground() {
......@@ -192,11 +186,10 @@ class AccountPickerBottomSheetMediator implements AccountPickerCoordinator.Liste
private void onSignInError(GoogleServiceAuthError error) {
if (error.getState() == State.INVALID_GAIA_CREDENTIALS) {
mModel.set(AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE,
AccountPickerBottomSheetState.SIGNIN_AUTH_ERROR);
mModel.set(AccountPickerBottomSheetProperties.VIEW_STATE, ViewState.SIGNIN_AUTH_ERROR);
} else {
mModel.set(AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE,
AccountPickerBottomSheetState.SIGNIN_GENERAL_ERROR);
mModel.set(
AccountPickerBottomSheetProperties.VIEW_STATE, ViewState.SIGNIN_GENERAL_ERROR);
}
}
}
......@@ -21,21 +21,21 @@ import java.lang.annotation.RetentionPolicy;
*/
class AccountPickerBottomSheetProperties {
/**
* States of account picker.
* Different account picker state correspond to different account picker bottom sheet
* View states of account picker.
* Different account picker view state correspond to different account picker bottom sheet
* configuration.
*/
@IntDef({
AccountPickerBottomSheetState.NO_ACCOUNTS,
AccountPickerBottomSheetState.COLLAPSED_ACCOUNT_LIST,
AccountPickerBottomSheetState.EXPANDED_ACCOUNT_LIST,
AccountPickerBottomSheetState.SIGNIN_IN_PROGRESS,
AccountPickerBottomSheetState.INCOGNITO_INTERSTITIAL,
AccountPickerBottomSheetState.SIGNIN_GENERAL_ERROR,
AccountPickerBottomSheetState.SIGNIN_AUTH_ERROR,
ViewState.NO_ACCOUNTS,
ViewState.COLLAPSED_ACCOUNT_LIST,
ViewState.EXPANDED_ACCOUNT_LIST,
ViewState.SIGNIN_IN_PROGRESS,
ViewState.INCOGNITO_INTERSTITIAL,
ViewState.SIGNIN_GENERAL_ERROR,
ViewState.SIGNIN_AUTH_ERROR,
})
@Retention(RetentionPolicy.SOURCE)
@interface AccountPickerBottomSheetState {
@interface ViewState {
/**
* When there is no account on device, the user sees only one blue button
* |Add account to device|.
......@@ -112,18 +112,17 @@ class AccountPickerBottomSheetProperties {
static final ReadableObjectPropertyKey<Runnable> ON_CONTINUE_AS_CLICKED =
new ReadableObjectPropertyKey<>("on_continue_as_clicked");
// PropertyKey indicates the state of the account picker bottom sheet
static final WritableIntPropertyKey ACCOUNT_PICKER_BOTTOM_SHEET_STATE =
new WritableIntPropertyKey("account_picker_bottom_sheet_state");
// PropertyKey indicates the view state of the account picker bottom sheet
static final WritableIntPropertyKey VIEW_STATE = new WritableIntPropertyKey("view_state");
static final PropertyKey[] ALL_KEYS = new PropertyKey[] {ON_SELECTED_ACCOUNT_CLICKED,
SELECTED_ACCOUNT_DATA, ON_CONTINUE_AS_CLICKED, ACCOUNT_PICKER_BOTTOM_SHEET_STATE};
static final PropertyKey[] ALL_KEYS = new PropertyKey[] {
ON_SELECTED_ACCOUNT_CLICKED, SELECTED_ACCOUNT_DATA, ON_CONTINUE_AS_CLICKED, VIEW_STATE};
/**
* Creates a default model for the AccountPickerBottomSheet.
*
* In the default model, as the selected account data is null, the bottom sheet is in the
* state {@link AccountPickerBottomSheetState#NO_ACCOUNTS}.
* state {@link ViewState#NO_ACCOUNTS}.
*/
static PropertyModel createModel(
Runnable onSelectedAccountClicked, Runnable onContinueAsClicked) {
......@@ -131,7 +130,7 @@ class AccountPickerBottomSheetProperties {
.with(ON_SELECTED_ACCOUNT_CLICKED, onSelectedAccountClicked)
.with(SELECTED_ACCOUNT_DATA, null)
.with(ON_CONTINUE_AS_CLICKED, onContinueAsClicked)
.with(ACCOUNT_PICKER_BOTTOM_SHEET_STATE, AccountPickerBottomSheetState.NO_ACCOUNTS)
.with(VIEW_STATE, ViewState.NO_ACCOUNTS)
.build();
}
......
......@@ -5,7 +5,7 @@
package org.chromium.chrome.browser.signin.account_picker;
import org.chromium.chrome.browser.signin.DisplayableProfileData;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetProperties.AccountPickerBottomSheetState;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetProperties.ViewState;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
......@@ -19,12 +19,10 @@ class AccountPickerBottomSheetViewBinder {
view.getSelectedAccountView().setOnClickListener(v -> {
model.get(AccountPickerBottomSheetProperties.ON_SELECTED_ACCOUNT_CLICKED).run();
});
} else if (propertyKey
== AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE) {
@AccountPickerBottomSheetState
int state =
model.get(AccountPickerBottomSheetProperties.ACCOUNT_PICKER_BOTTOM_SHEET_STATE);
switchToState(view, state);
} else if (propertyKey == AccountPickerBottomSheetProperties.VIEW_STATE) {
@ViewState
int viewState = model.get(AccountPickerBottomSheetProperties.VIEW_STATE);
switchToState(view, viewState);
} else if (propertyKey == AccountPickerBottomSheetProperties.SELECTED_ACCOUNT_DATA) {
DisplayableProfileData profileData =
model.get(AccountPickerBottomSheetProperties.SELECTED_ACCOUNT_DATA);
......@@ -39,36 +37,35 @@ class AccountPickerBottomSheetViewBinder {
}
/**
* Sets up the configuration of account picker bottom sheet according to the given state.
* Sets up the configuration of account picker bottom sheet according to the given
* {@link ViewState}.
*/
private static void switchToState(AccountPickerBottomSheetView view,
@AccountPickerBottomSheetState int accountPickerBottomSheetState) {
switch (accountPickerBottomSheetState) {
case AccountPickerBottomSheetState.NO_ACCOUNTS:
private static void switchToState(AccountPickerBottomSheetView view, @ViewState int viewState) {
switch (viewState) {
case ViewState.NO_ACCOUNTS:
view.collapseToNoAccountView();
break;
case AccountPickerBottomSheetState.COLLAPSED_ACCOUNT_LIST:
case ViewState.COLLAPSED_ACCOUNT_LIST:
view.collapseAccountList();
break;
case AccountPickerBottomSheetState.EXPANDED_ACCOUNT_LIST:
case ViewState.EXPANDED_ACCOUNT_LIST:
view.expandAccountList();
break;
case AccountPickerBottomSheetState.SIGNIN_IN_PROGRESS:
case ViewState.SIGNIN_IN_PROGRESS:
view.setUpSignInInProgressView();
break;
case AccountPickerBottomSheetState.INCOGNITO_INTERSTITIAL:
case ViewState.INCOGNITO_INTERSTITIAL:
view.setUpIncognitoInterstitialView();
break;
case AccountPickerBottomSheetState.SIGNIN_GENERAL_ERROR:
case ViewState.SIGNIN_GENERAL_ERROR:
view.setUpSignInGeneralErrorView();
break;
case AccountPickerBottomSheetState.SIGNIN_AUTH_ERROR:
case ViewState.SIGNIN_AUTH_ERROR:
view.setUpSignInAuthErrorView();
break;
default:
throw new IllegalArgumentException(
"Cannot bind AccountPickerBottomSheetView for the state:"
+ accountPickerBottomSheetState);
"Cannot bind AccountPickerBottomSheetView for the view state:" + viewState);
}
}
......
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