Commit 51c7fe0b authored by Parastoo Geranmayeh's avatar Parastoo Geranmayeh Committed by Commit Bot

In address editor, the state field needs a hint.

In the Payment Request and the Autofill address editor,
for the admin area field (state/province),
the default selection must be the hint (which is "Select").
Previously, the default was the first item in the list.

BillingAddressAdapter is used for both Card Editor and
Address Editor dropdown lists. Modify it so that it works
correctly for Address Editor as well.


Bug: 793436
Change-Id: Ib91b9d62105f255edddbc67fc295387e23aaffb2
Reviewed-on: https://chromium-review.googlesource.com/820050
Commit-Queue: Parastoo Geranmayeh <parastoog@google.com>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523534}
parent 9190ef1c
...@@ -332,7 +332,8 @@ public class AddressEditor ...@@ -332,7 +332,8 @@ public class AddressEditor
} }
@Override @Override
public void onSubKeysReceived(String[] adminAreaCodes, String[] adminAreaNames) { public void onSubKeysReceived(
@Nullable String[] adminAreaCodes, @Nullable String[] adminAreaNames) {
if (mAdminAreasLoaded) return; if (mAdminAreasLoaded) return;
mAdminAreasLoaded = true; mAdminAreasLoaded = true;
// If the dialog is already dismissed, it doesn't make sense to show it. // If the dialog is already dismissed, it doesn't make sense to show it.
...@@ -340,10 +341,15 @@ public class AddressEditor ...@@ -340,10 +341,15 @@ public class AddressEditor
// subkeys. // subkeys.
if (mEditorDialog.isDismissed()) return; if (mEditorDialog.isDismissed()) return;
// When there is a timeout in the subkey request process, the admin area codes/names will be
// null.
mAddressFields.put(AddressField.ADMIN_AREA, mAddressFields.put(AddressField.ADMIN_AREA,
(contains(adminAreaCodes, mProfile.getRegion()) (adminAreaCodes != null && adminAreaNames != null && adminAreaCodes.length != 0
|| contains(adminAreaNames, mProfile.getRegion())) && adminAreaCodes.length == adminAreaNames.length)
? EditorFieldModel.createDropdown() ? EditorFieldModel.createDropdown(null /* label */,
mAutofillProfileBridge.getAdminAreaDropdownList(
adminAreaCodes, adminAreaNames),
mContext.getString(R.string.select))
: EditorFieldModel.createTextInput( : EditorFieldModel.createTextInput(
EditorFieldModel.INPUT_TYPE_HINT_REGION)); EditorFieldModel.INPUT_TYPE_HINT_REGION));
...@@ -358,16 +364,15 @@ public class AddressEditor ...@@ -358,16 +364,15 @@ public class AddressEditor
// For example, "US" will not add dependent locality to the editor. A "JP" address will // For example, "US" will not add dependent locality to the editor. A "JP" address will
// start with a person's full name or a with a prefecture name, depending on whether the // start with a person's full name or a with a prefecture name, depending on whether the
// language code is "ja-Latn" or "ja". // language code is "ja-Latn" or "ja".
addAddressFieldsToEditor(mRecentlySelectedCountry, Locale.getDefault().getLanguage(), addAddressFieldsToEditor(mRecentlySelectedCountry, Locale.getDefault().getLanguage());
adminAreaCodes, adminAreaNames);
// Notify EditorDialog that the fields in the model have changed. EditorDialog should // Notify EditorDialog that the fields in the model have changed. EditorDialog should
// re-read the model and update the UI accordingly. // re-read the model and update the UI accordingly.
mHandler.post(mCountryChangeCallback); mHandler.post(mCountryChangeCallback);
} else { } else {
// This should be called when all required fields are put in mAddressField. // This should be called when all required fields are put in mAddressField.
setAddressFieldValuesFromCache(); setAddressFieldValuesFromCache();
addAddressFieldsToEditor(mCountryField.getValue().toString(), addAddressFieldsToEditor(
mProfile.getLanguageCode(), adminAreaCodes, adminAreaNames); mCountryField.getValue().toString(), mProfile.getLanguageCode());
mEditorDialog.show(mEditor); mEditorDialog.show(mEditor);
} }
} }
...@@ -404,8 +409,7 @@ public class AddressEditor ...@@ -404,8 +409,7 @@ public class AddressEditor
* Adds fields to the editor model based on the country and language code of * Adds fields to the editor model based on the country and language code of
* the profile that's being edited. * the profile that's being edited.
*/ */
private void addAddressFieldsToEditor(String countryCode, String languageCode, private void addAddressFieldsToEditor(String countryCode, String languageCode) {
String[] adminAreaCodes, String[] adminAreaNames) {
mAddressUiComponents = mAddressUiComponents =
mAutofillProfileBridge.getAddressUiComponents(countryCode, languageCode); mAutofillProfileBridge.getAddressUiComponents(countryCode, languageCode);
// In terms of order, country must be the first field. // In terms of order, country must be the first field.
...@@ -420,11 +424,6 @@ public class AddressEditor ...@@ -420,11 +424,6 @@ public class AddressEditor
field.setIsFullLine(component.isFullLine || component.id == AddressField.LOCALITY field.setIsFullLine(component.isFullLine || component.id == AddressField.LOCALITY
|| component.id == AddressField.DEPENDENT_LOCALITY); || component.id == AddressField.DEPENDENT_LOCALITY);
if (component.id == AddressField.ADMIN_AREA && field.isDropdownField()) {
field.setDropdownKeyValues(mAutofillProfileBridge.getAdminAreaDropdownList(
adminAreaCodes, adminAreaNames));
}
// Libaddressinput formats do not always require the full name (RECIPIENT), but // Libaddressinput formats do not always require the full name (RECIPIENT), but
// PaymentRequest does. // PaymentRequest does.
if (component.isRequired || component.id == AddressField.RECIPIENT) { if (component.isRequired || component.id == AddressField.RECIPIENT) {
......
...@@ -19,8 +19,9 @@ import java.util.List; ...@@ -19,8 +19,9 @@ import java.util.List;
/** /**
* Subclass of DropdownFieldAdapter used to display a dropdown hint that won't appear in the * Subclass of DropdownFieldAdapter used to display a dropdown hint that won't appear in the
* expanded dropdown options but will be used when no element is selected. The last shown element * expanded dropdown options but will be used when no element is selected. In some cases, the last
* will have a "+" icon on its left and a blue tint to indicate the option to add an element. * shown element will have a "+" icon on its left and a blue tint to indicate the option to add an
* element.
* *
* @param <T> The type of element to be inserted into the adapter. * @param <T> The type of element to be inserted into the adapter.
* *
...@@ -35,25 +36,26 @@ import java.util.List; ...@@ -35,25 +36,26 @@ import java.util.List;
* . hint . -> hidden * . hint . -> hidden
* .............. * ..............
*/ */
public class BillingAddressAdapter<T> extends DropdownFieldAdapter<T> { public class AddressDropDownAdapter<T> extends DropdownFieldAdapter<T> {
private final int mTextViewResourceId; private final int mTextViewResourceId;
private boolean mAddButtonIncluded;
/** /**
* Creates an array adapter for which the last element is a hint that is not shown in the * Creates an array adapter for which the last element is a hint that is not shown in the
* expanded view and where the last shown element has a "+" icon on its left and has a blue * expanded view and where in some cases, the last shown element has a "+" icon on its left and
* tint. * has a blue tint.
* *
* @param context The current context. * @param context The current context.
* @param resource The resource ID for a layout file containing a layout to use when * @param resource The resource ID for a layout file containing a layout to use when
* instantiating views. * instantiating views.
* @param textViewResourceId The id of the TextView within the layout resource to be populated. * @param textViewResourceId The id of the TextView within the layout resource to be populated.
* @param objects The objects to represent in the ListView, the last of which will * @param objects The objects to represent in the ListView, in some cases, the last
* have a "+" icon on its left and will have a blue tint. * item will have a "+" icon on its left and will have a blue tint.
* @param hint The element to be used as a hint when no element is selected. It is * @param hint The element to be used as a hint when no element is selected. It is
* not taken into account in the count function and thus will not be * not taken into account in the count function and thus will not be
* displayed when in the expanded dropdown view. * displayed when in the expanded dropdown view.
*/ */
public BillingAddressAdapter( public AddressDropDownAdapter(
Context context, int resource, int textViewResourceId, List<T> objects, T hint) { Context context, int resource, int textViewResourceId, List<T> objects, T hint) {
// Make a copy of objects so the hint is not added to the original list. // Make a copy of objects so the hint is not added to the original list.
super(context, resource, textViewResourceId, objects); super(context, resource, textViewResourceId, objects);
...@@ -62,6 +64,10 @@ public class BillingAddressAdapter<T> extends DropdownFieldAdapter<T> { ...@@ -62,6 +64,10 @@ public class BillingAddressAdapter<T> extends DropdownFieldAdapter<T> {
add(hint); add(hint);
mTextViewResourceId = textViewResourceId; mTextViewResourceId = textViewResourceId;
// The "+" icon is displayed only when the last item is "Add Address."
mAddButtonIncluded = objects.get(getCount() - 1)
.toString()
.equals(context.getString(R.string.payments_add_address));
} }
@Override @Override
...@@ -96,9 +102,8 @@ public class BillingAddressAdapter<T> extends DropdownFieldAdapter<T> { ...@@ -96,9 +102,8 @@ public class BillingAddressAdapter<T> extends DropdownFieldAdapter<T> {
ApiCompatibilityUtils.getPaddingEnd(convertView), ApiCompatibilityUtils.getPaddingEnd(convertView),
convertView.getPaddingBottom()); convertView.getPaddingBottom());
} }
// When the last item is "ADD ADDRESS", show the "+" icon.
// The last item is "ADD ADDRESS". if (mAddButtonIncluded && position == getCount() - 1) {
if (position == getCount() - 1) {
// Add a "+" icon and a blue tint to the last element. // Add a "+" icon and a blue tint to the last element.
Resources resources = getContext().getResources(); Resources resources = getContext().getResources();
if (textView == null) { if (textView == null) {
...@@ -128,4 +133,4 @@ public class BillingAddressAdapter<T> extends DropdownFieldAdapter<T> { ...@@ -128,4 +133,4 @@ public class BillingAddressAdapter<T> extends DropdownFieldAdapter<T> {
return convertView; return convertView;
} }
} }
\ No newline at end of file
...@@ -67,8 +67,8 @@ class EditorDropdownField implements EditorFieldView { ...@@ -67,8 +67,8 @@ class EditorDropdownField implements EditorFieldView {
final List<CharSequence> dropdownValues = getDropdownValues(dropdownKeyValues); final List<CharSequence> dropdownValues = getDropdownValues(dropdownKeyValues);
ArrayAdapter<CharSequence> adapter; ArrayAdapter<CharSequence> adapter;
if (mFieldModel.getHint() != null) { if (mFieldModel.getHint() != null) {
// Use the BillingAddressAdapter and pass it a hint to be displayed as default. // Use the AddressDropDownAdapter and pass it a hint to be displayed as default.
adapter = new BillingAddressAdapter<CharSequence>(context, adapter = new AddressDropDownAdapter<CharSequence>(context,
R.layout.multiline_spinner_item, R.id.spinner_item, dropdownValues, R.layout.multiline_spinner_item, R.id.spinner_item, dropdownValues,
mFieldModel.getHint().toString()); mFieldModel.getHint().toString());
// Wrap the TextView in the dropdown popup around with a FrameLayout to display the text // Wrap the TextView in the dropdown popup around with a FrameLayout to display the text
...@@ -81,7 +81,9 @@ class EditorDropdownField implements EditorFieldView { ...@@ -81,7 +81,9 @@ class EditorDropdownField implements EditorFieldView {
// If no value is selected, select the hint entry which is the last item in the adapter. // If no value is selected, select the hint entry which is the last item in the adapter.
// Using getCount will not result in an out of bounds index because the hint value is // Using getCount will not result in an out of bounds index because the hint value is
// ommited in the count. // ommited in the count.
if (mFieldModel.getValue() == null) mSelectedIndex = adapter.getCount(); if (mFieldModel.getValue() == null || mFieldModel.getValue().length() == 0) {
mSelectedIndex = adapter.getCount();
}
} else { } else {
adapter = new DropdownFieldAdapter<CharSequence>( adapter = new DropdownFieldAdapter<CharSequence>(
context, R.layout.multiline_spinner_item, dropdownValues); context, R.layout.multiline_spinner_item, dropdownValues);
...@@ -117,12 +119,6 @@ class EditorDropdownField implements EditorFieldView { ...@@ -117,12 +119,6 @@ class EditorDropdownField implements EditorFieldView {
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) requestFocusAndHideKeyboard(); if (event.getAction() == MotionEvent.ACTION_DOWN) requestFocusAndHideKeyboard();
// If the dropdown supports an hint and the hint is selected, select the first
// element instead.
if (mDropdown.getSelectedItemPosition() == count) {
mDropdown.setSelection(0);
}
return false; return false;
} }
}); });
......
...@@ -201,11 +201,6 @@ public class EditorFieldModel { ...@@ -201,11 +201,6 @@ public class EditorFieldModel {
return result; return result;
} }
/** Constructs a dropdown field model. */
public static EditorFieldModel createDropdown() {
return new EditorFieldModel(INPUT_TYPE_HINT_DROPDOWN);
}
/** /**
* Constructs a dropdown field model. * Constructs a dropdown field model.
* *
......
...@@ -840,7 +840,7 @@ chrome_java_sources = [ ...@@ -840,7 +840,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/payments/ShippingStrings.java", "java/src/org/chromium/chrome/browser/payments/ShippingStrings.java",
"java/src/org/chromium/chrome/browser/payments/SslValidityChecker.java", "java/src/org/chromium/chrome/browser/payments/SslValidityChecker.java",
"java/src/org/chromium/chrome/browser/payments/UriUtils.java", "java/src/org/chromium/chrome/browser/payments/UriUtils.java",
"java/src/org/chromium/chrome/browser/payments/ui/BillingAddressAdapter.java", "java/src/org/chromium/chrome/browser/payments/ui/AddressDropDownAdapter.java",
"java/src/org/chromium/chrome/browser/payments/ui/Completable.java", "java/src/org/chromium/chrome/browser/payments/ui/Completable.java",
"java/src/org/chromium/chrome/browser/payments/ui/ContactDetailsSection.java", "java/src/org/chromium/chrome/browser/payments/ui/ContactDetailsSection.java",
"java/src/org/chromium/chrome/browser/payments/ui/DropdownFieldAdapter.java", "java/src/org/chromium/chrome/browser/payments/ui/DropdownFieldAdapter.java",
......
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