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
}
@Override
public void onSubKeysReceived(String[] adminAreaCodes, String[] adminAreaNames) {
public void onSubKeysReceived(
@Nullable String[] adminAreaCodes, @Nullable String[] adminAreaNames) {
if (mAdminAreasLoaded) return;
mAdminAreasLoaded = true;
// If the dialog is already dismissed, it doesn't make sense to show it.
......@@ -340,10 +341,15 @@ public class AddressEditor
// subkeys.
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,
(contains(adminAreaCodes, mProfile.getRegion())
|| contains(adminAreaNames, mProfile.getRegion()))
? EditorFieldModel.createDropdown()
(adminAreaCodes != null && adminAreaNames != null && adminAreaCodes.length != 0
&& adminAreaCodes.length == adminAreaNames.length)
? EditorFieldModel.createDropdown(null /* label */,
mAutofillProfileBridge.getAdminAreaDropdownList(
adminAreaCodes, adminAreaNames),
mContext.getString(R.string.select))
: EditorFieldModel.createTextInput(
EditorFieldModel.INPUT_TYPE_HINT_REGION));
......@@ -358,16 +364,15 @@ public class AddressEditor
// 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
// language code is "ja-Latn" or "ja".
addAddressFieldsToEditor(mRecentlySelectedCountry, Locale.getDefault().getLanguage(),
adminAreaCodes, adminAreaNames);
addAddressFieldsToEditor(mRecentlySelectedCountry, Locale.getDefault().getLanguage());
// Notify EditorDialog that the fields in the model have changed. EditorDialog should
// re-read the model and update the UI accordingly.
mHandler.post(mCountryChangeCallback);
} else {
// This should be called when all required fields are put in mAddressField.
setAddressFieldValuesFromCache();
addAddressFieldsToEditor(mCountryField.getValue().toString(),
mProfile.getLanguageCode(), adminAreaCodes, adminAreaNames);
addAddressFieldsToEditor(
mCountryField.getValue().toString(), mProfile.getLanguageCode());
mEditorDialog.show(mEditor);
}
}
......@@ -404,8 +409,7 @@ public class AddressEditor
* Adds fields to the editor model based on the country and language code of
* the profile that's being edited.
*/
private void addAddressFieldsToEditor(String countryCode, String languageCode,
String[] adminAreaCodes, String[] adminAreaNames) {
private void addAddressFieldsToEditor(String countryCode, String languageCode) {
mAddressUiComponents =
mAutofillProfileBridge.getAddressUiComponents(countryCode, languageCode);
// In terms of order, country must be the first field.
......@@ -420,11 +424,6 @@ public class AddressEditor
field.setIsFullLine(component.isFullLine || component.id == AddressField.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
// PaymentRequest does.
if (component.isRequired || component.id == AddressField.RECIPIENT) {
......
......@@ -19,8 +19,9 @@ import java.util.List;
/**
* 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
* will have a "+" icon on its left and a blue tint to indicate the option to add an element.
* expanded dropdown options but will be used when no element is selected. In some cases, the last
* 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.
*
......@@ -35,25 +36,26 @@ import java.util.List;
* . hint . -> hidden
* ..............
*/
public class BillingAddressAdapter<T> extends DropdownFieldAdapter<T> {
public class AddressDropDownAdapter<T> extends DropdownFieldAdapter<T> {
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
* expanded view and where the last shown element has a "+" icon on its left and has a blue
* tint.
* expanded view and where in some cases, the last shown element has a "+" icon on its left and
* has a blue tint.
*
* @param context The current context.
* @param resource The resource ID for a layout file containing a layout to use when
* instantiating views.
* @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
* have a "+" icon on its left and will have a blue tint.
* @param objects The objects to represent in the ListView, in some cases, the last
* 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
* not taken into account in the count function and thus will not be
* displayed when in the expanded dropdown view.
*/
public BillingAddressAdapter(
public AddressDropDownAdapter(
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.
super(context, resource, textViewResourceId, objects);
......@@ -62,6 +64,10 @@ public class BillingAddressAdapter<T> extends DropdownFieldAdapter<T> {
add(hint);
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
......@@ -96,9 +102,8 @@ public class BillingAddressAdapter<T> extends DropdownFieldAdapter<T> {
ApiCompatibilityUtils.getPaddingEnd(convertView),
convertView.getPaddingBottom());
}
// The last item is "ADD ADDRESS".
if (position == getCount() - 1) {
// When the last item is "ADD ADDRESS", show the "+" icon.
if (mAddButtonIncluded && position == getCount() - 1) {
// Add a "+" icon and a blue tint to the last element.
Resources resources = getContext().getResources();
if (textView == null) {
......
......@@ -67,8 +67,8 @@ class EditorDropdownField implements EditorFieldView {
final List<CharSequence> dropdownValues = getDropdownValues(dropdownKeyValues);
ArrayAdapter<CharSequence> adapter;
if (mFieldModel.getHint() != null) {
// Use the BillingAddressAdapter and pass it a hint to be displayed as default.
adapter = new BillingAddressAdapter<CharSequence>(context,
// Use the AddressDropDownAdapter and pass it a hint to be displayed as default.
adapter = new AddressDropDownAdapter<CharSequence>(context,
R.layout.multiline_spinner_item, R.id.spinner_item, dropdownValues,
mFieldModel.getHint().toString());
// Wrap the TextView in the dropdown popup around with a FrameLayout to display the text
......@@ -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.
// Using getCount will not result in an out of bounds index because the hint value is
// ommited in the count.
if (mFieldModel.getValue() == null) mSelectedIndex = adapter.getCount();
if (mFieldModel.getValue() == null || mFieldModel.getValue().length() == 0) {
mSelectedIndex = adapter.getCount();
}
} else {
adapter = new DropdownFieldAdapter<CharSequence>(
context, R.layout.multiline_spinner_item, dropdownValues);
......@@ -117,12 +119,6 @@ class EditorDropdownField implements EditorFieldView {
public boolean onTouch(View v, MotionEvent event) {
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;
}
});
......
......@@ -201,11 +201,6 @@ public class EditorFieldModel {
return result;
}
/** Constructs a dropdown field model. */
public static EditorFieldModel createDropdown() {
return new EditorFieldModel(INPUT_TYPE_HINT_DROPDOWN);
}
/**
* Constructs a dropdown field model.
*
......
......@@ -840,7 +840,7 @@ chrome_java_sources = [
"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/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/ContactDetailsSection.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