Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4683)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/AccountChooserInfoBar.java

Issue 925593006: Pass all info to account chooser infobar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@java_cpp_enum
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/AccountChooserInfoBar.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AccountChooserInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AccountChooserInfoBar.java
index 7f3a7fc438da21ce2912903ac177c34b0e1a5b61..ea59d8e16c7c4c608ff762f2b610610bf142b2fc 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AccountChooserInfoBar.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AccountChooserInfoBar.java
@@ -25,6 +25,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ResourceId;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.widget.ButtonCompat;
+import org.chromium.components.autofill.core.common.Credential;
/**
* An infobar offers the user the ability to choose credentials for
@@ -32,46 +33,32 @@ import org.chromium.chrome.browser.widget.ButtonCompat;
* full name in case they are available.
*/
public class AccountChooserInfoBar extends InfoBar implements OnMenuItemClickListener {
- private enum CredentialType {
- EMPTY(0),
- LOCAL(1),
- FEDERATED(2);
-
- private final int mType;
- private CredentialType(int type) {
- mType = type;
- };
-
- public int getValue() {
- return mType;
- }
- }
-
- private final String[] mUsernames;
+ private final Credential[] mCredentials;
/**
* Creates and shows the infobar wich allows user to choose credentials for login.
* @param nativeInfoBar Pointer to the native infobar.
* @param enumeratedIconId Enum ID corresponding to the icon that the infobar will show.
- * @param usernames Usernames to display in the infobar.
+ * @param credentials Credentials to display in the infobar.
*/
@CalledByNative
- private static InfoBar show(long nativeInfoBar, int enumeratedIconId, String[] usernames) {
+ private static InfoBar show(
+ long nativeInfoBar, int enumeratedIconId, Credential[] credentials) {
return new AccountChooserInfoBar(
- nativeInfoBar, ResourceId.mapToDrawableId(enumeratedIconId), usernames);
+ nativeInfoBar, ResourceId.mapToDrawableId(enumeratedIconId), credentials);
}
/**
* Creates and shows the infobar which allows user to choose credentials.
* @param nativeInfoBar Pointer to the native infobar.
* @param iconDrawableId Drawable ID corresponding to the icon that the infobar will show.
- * @param usernames list of usernames to display in infobar.
+ * @param credentials Credentials to display in the infobar.
*/
- public AccountChooserInfoBar(long nativeInfoBar, int iconDrawableId, String[] usernames) {
+ public AccountChooserInfoBar(long nativeInfoBar, int iconDrawableId, Credential[] credentials) {
super(null /* Infobar Listener */, iconDrawableId, null /* bitmap*/,
null /* message to show */);
setNativeInfoBar(nativeInfoBar);
- mUsernames = usernames.clone();
+ mCredentials = credentials.clone();
}
@Override
@@ -104,9 +91,10 @@ public class AccountChooserInfoBar extends InfoBar implements OnMenuItemClickLis
}
private void createAccountsView(InfoBarLayout layout) {
- ViewGroup accountsView = (ViewGroup) LayoutInflater.from(getContext()).inflate(
- R.layout.account_chooser_infobar_list, null, false);
- ArrayAdapter<String> adapter = generateAccountsArrayAdapter(getContext(), mUsernames);
+ ViewGroup accountsView =
+ (ViewGroup) LayoutInflater.from(getContext())
+ .inflate(R.layout.account_chooser_infobar_list, null, false);
+ ArrayAdapter<Credential> adapter = generateAccountsArrayAdapter(getContext(), mCredentials);
ListView listView = (ListView) accountsView.findViewById(R.id.account_list);
listView.setAdapter(adapter);
float numVisibleItems = adapter.getCount() > 2 ? 2.5f : adapter.getCount();
@@ -117,8 +105,9 @@ public class AccountChooserInfoBar extends InfoBar implements OnMenuItemClickLis
layout.setCustomContent(accountsView);
}
- private ArrayAdapter<String> generateAccountsArrayAdapter(Context context, String[] usernames) {
- return new ArrayAdapter<String>(context, 0, usernames) {
+ private ArrayAdapter<Credential> generateAccountsArrayAdapter(
+ Context context, Credential[] credentials) {
+ return new ArrayAdapter<Credential>(context, 0, credentials) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
@@ -128,19 +117,18 @@ public class AccountChooserInfoBar extends InfoBar implements OnMenuItemClickLis
ImageView avatarView = (ImageView) convertView.findViewById(R.id.profile_image);
TextView usernameView = (TextView) convertView.findViewById(R.id.username);
TextView displayNameView = (TextView) convertView.findViewById(R.id.display_name);
- String username = getItem(position);
- usernameView.setText(username);
- // TODO(melandory): View should show the full name. Temporarily the view shows
- // username.
- displayNameView.setText(username);
+ Credential credential = getItem(position);
+ usernameView.setText(credential.getUsername());
+ displayNameView.setText(credential.getDisplayName());
// TODO(melandory): View should show proper avatar. Temporarily the view shows
// blue man icon.
avatarView.setImageResource(R.drawable.account_management_no_picture);
- final int currentCredentialIndex = position;
+ final int currentCredentialIndex = credential.getIndex();
+ final int credentialType = credential.getType();
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- passCredentialsToNative(currentCredentialIndex);
+ passCredentialsToNative(currentCredentialIndex, credentialType);
}
});
return convertView;
@@ -167,11 +155,8 @@ public class AccountChooserInfoBar extends InfoBar implements OnMenuItemClickLis
layout.setCustomViewInButtonRow(moreButton);
}
- private void passCredentialsToNative(int credentialIndex) {
- // TODO(melandory): Adding federated login support should change this
- // code.
- nativeOnCredentialClicked(
- mNativeInfoBarPtr, credentialIndex, CredentialType.LOCAL.getValue());
+ private void passCredentialsToNative(int credentialIndex, int credentialType) {
+ nativeOnCredentialClicked(mNativeInfoBarPtr, credentialIndex, credentialType);
}
/** Pops up menu with two items: Setting and Learn More when user clicks More button. */

Powered by Google App Engine
This is Rietveld 408576698