Commit 08b780f0 authored by gogerald's avatar gogerald Committed by Commit bot

List incomplete addresses in the billing address dropdown

The billing addresses in the dropdown contain edit required information
and are sorted by completeness.
Select incomplete address brings up address editor.
Select previously selected address or null if user cancels from address editor.
Select and add the newly added or completed address to the top of the dropdown.

BUG=675686

Review-Url: https://codereview.chromium.org/2614193002
Cr-Commit-Position: refs/heads/master@{#442657}
parent 849c6f79
...@@ -8,6 +8,7 @@ import android.content.Context; ...@@ -8,6 +8,7 @@ import android.content.Context;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.telephony.PhoneNumberUtils; import android.telephony.PhoneNumberUtils;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Pair;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.PersonalDataManager; import org.chromium.chrome.browser.autofill.PersonalDataManager;
...@@ -158,10 +159,31 @@ public class AutofillAddress extends PaymentOption { ...@@ -158,10 +159,31 @@ public class AutofillAddress extends PaymentOption {
* status. * status.
*/ */
private void checkAndUpdateAddressCompleteness() { private void checkAndUpdateAddressCompleteness() {
Pair<Integer, Integer> messageResIds =
getEditMessageAndTitleResIds(checkAddressCompletionStatus(mProfile));
mEditMessage = messageResIds.first.intValue() == 0
? null
: mContext.getString(messageResIds.first);
mEditTitle = messageResIds.second.intValue() == 0
? null
: mContext.getString(messageResIds.second);
mIsComplete = mEditMessage == null;
}
/**
* Gets the edit message and title resource Ids for the completion status.
*
* @param completionStatus The completion status.
* @return The resource Ids. The first is the edit message resource Id. The second is the
* correspond editor title resource Id.
*/
public static Pair<Integer, Integer> getEditMessageAndTitleResIds(
@CompletionStatus int completionStatus) {
int editMessageResId = 0; int editMessageResId = 0;
int editTitleResId = 0; int editTitleResId = 0;
switch (checkAddressCompletionStatus(mProfile)) { switch (completionStatus) {
case COMPLETE: case COMPLETE:
editTitleResId = R.string.autofill_edit_profile; editTitleResId = R.string.autofill_edit_profile;
break; break;
...@@ -185,9 +207,7 @@ public class AutofillAddress extends PaymentOption { ...@@ -185,9 +207,7 @@ public class AutofillAddress extends PaymentOption {
assert false : "Invalid completion status"; assert false : "Invalid completion status";
} }
mEditMessage = editMessageResId == 0 ? null : mContext.getString(editMessageResId); return new Pair<Integer, Integer>(editMessageResId, editTitleResId);
mEditTitle = editTitleResId == 0 ? null : mContext.getString(editTitleResId);
mIsComplete = mEditMessage == null;
} }
/** /**
......
...@@ -65,6 +65,8 @@ public class AutofillPaymentApp implements PaymentApp { ...@@ -65,6 +65,8 @@ public class AutofillPaymentApp implements PaymentApp {
billingAddress = null; billingAddress = null;
} }
if (billingAddress == null) card.setBillingAddressId(null);
String methodName = null; String methodName = null;
if (basicCardSupportedNetworks != null if (basicCardSupportedNetworks != null
&& basicCardSupportedNetworks.contains(card.getBasicCardPaymentType())) { && basicCardSupportedNetworks.contains(card.getBasicCardPaymentType())) {
......
...@@ -19,6 +19,7 @@ import org.chromium.chrome.R; ...@@ -19,6 +19,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue; import org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue;
import org.chromium.ui.UiUtils; import org.chromium.ui.UiUtils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -56,12 +57,13 @@ class EditorDropdownField implements EditorFieldView { ...@@ -56,12 +57,13 @@ class EditorDropdownField implements EditorFieldView {
final List<DropdownKeyValue> dropdownKeyValues = mFieldModel.getDropdownKeyValues(); final List<DropdownKeyValue> dropdownKeyValues = mFieldModel.getDropdownKeyValues();
mSelectedIndex = getDropdownIndex(dropdownKeyValues, mFieldModel.getValue()); mSelectedIndex = getDropdownIndex(dropdownKeyValues, mFieldModel.getValue());
ArrayAdapter<DropdownKeyValue> adapter; final List<CharSequence> dropdownValues = getDropdownValues(dropdownKeyValues);
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 BillingAddressAdapter and pass it a hint to be displayed as default.
adapter = new BillingAddressAdapter<DropdownKeyValue>(context, adapter = new BillingAddressAdapter<CharSequence>(context,
R.layout.multiline_spinner_item, R.id.spinner_item, dropdownKeyValues, R.layout.multiline_spinner_item, R.id.spinner_item, dropdownValues,
new DropdownKeyValue("", 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
// in multiple lines. // in multiple lines.
// Note that the TextView in the dropdown popup is displayed in a DropDownListView for // Note that the TextView in the dropdown popup is displayed in a DropDownListView for
...@@ -74,8 +76,8 @@ class EditorDropdownField implements EditorFieldView { ...@@ -74,8 +76,8 @@ class EditorDropdownField implements EditorFieldView {
// ommited in the count. // ommited in the count.
if (mFieldModel.getValue() == null) mSelectedIndex = adapter.getCount(); if (mFieldModel.getValue() == null) mSelectedIndex = adapter.getCount();
} else { } else {
adapter = new ArrayAdapter<DropdownKeyValue>( adapter = new ArrayAdapter<CharSequence>(
context, R.layout.multiline_spinner_item, dropdownKeyValues); context, R.layout.multiline_spinner_item, dropdownValues);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
} }
...@@ -156,6 +158,14 @@ class EditorDropdownField implements EditorFieldView { ...@@ -156,6 +158,14 @@ class EditorDropdownField implements EditorFieldView {
mDropdown.setSelection(mSelectedIndex); mDropdown.setSelection(mSelectedIndex);
} }
private static List<CharSequence> getDropdownValues(List<DropdownKeyValue> dropdownKeyValues) {
List<CharSequence> dropdownValues = new ArrayList<CharSequence>();
for (int i = 0; i < dropdownKeyValues.size(); i++) {
dropdownValues.add(dropdownKeyValues.get(i).getValue());
}
return dropdownValues;
}
private static int getDropdownIndex( private static int getDropdownIndex(
List<DropdownKeyValue> dropdownKeyValues, CharSequence value) { List<DropdownKeyValue> dropdownKeyValues, CharSequence value) {
for (int i = 0; i < dropdownKeyValues.size(); i++) { for (int i = 0; i < dropdownKeyValues.size(); i++) {
......
...@@ -212,12 +212,8 @@ public class EditorFieldModel { ...@@ -212,12 +212,8 @@ public class EditorFieldModel {
assert dropdownKeyValues != null; assert dropdownKeyValues != null;
EditorFieldModel result = new EditorFieldModel(INPUT_TYPE_HINT_DROPDOWN); EditorFieldModel result = new EditorFieldModel(INPUT_TYPE_HINT_DROPDOWN);
result.mLabel = label; result.mLabel = label;
result.mDropdownKeyValues = dropdownKeyValues;
result.mHint = hint; result.mHint = hint;
result.mDropdownKeys = new HashSet<>(); result.setDropdownKeyValues(dropdownKeyValues);
for (int i = 0; i < result.mDropdownKeyValues.size(); i++) {
result.mDropdownKeys.add(result.mDropdownKeyValues.get(i).getKey());
}
return result; return result;
} }
...@@ -390,6 +386,11 @@ public class EditorFieldModel { ...@@ -390,6 +386,11 @@ public class EditorFieldModel {
public void setDropdownKeyValues(List<DropdownKeyValue> dropdownKeyValues) { public void setDropdownKeyValues(List<DropdownKeyValue> dropdownKeyValues) {
assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN; assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN;
mDropdownKeyValues = dropdownKeyValues; mDropdownKeyValues = dropdownKeyValues;
mDropdownKeys = new HashSet<>();
for (int i = 0; i < mDropdownKeyValues.size(); i++) {
mDropdownKeys.add(mDropdownKeyValues.get(i).getKey());
}
assert mDropdownKeyValues.size() == mDropdownKeys.size();
} }
/** @return The human-readable label for this field. */ /** @return The human-readable label for this field. */
......
...@@ -45,8 +45,8 @@ public class AutofillProfileBridge { ...@@ -45,8 +45,8 @@ public class AutofillProfileBridge {
/** /**
* A convenience class for displaying keyed values in a dropdown. * A convenience class for displaying keyed values in a dropdown.
*/ */
public static class DropdownKeyValue extends Pair<String, String> { public static class DropdownKeyValue extends Pair<String, CharSequence> {
public DropdownKeyValue(String key, String value) { public DropdownKeyValue(String key, CharSequence value) {
super(key, value); super(key, value);
} }
...@@ -56,13 +56,13 @@ public class AutofillProfileBridge { ...@@ -56,13 +56,13 @@ public class AutofillProfileBridge {
} }
/** @return The human-readable localized display value. */ /** @return The human-readable localized display value. */
public String getValue() { public CharSequence getValue() {
return super.second; return super.second;
} }
@Override @Override
public String toString() { public String toString() {
return super.second; return super.second.toString();
} }
} }
......
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