use of org.chromium.base.Callback in project AndroidChromium by JackyAndroid.
the class CardEditor method addBillingAddressDropdown.
/**
* Adds the billing address dropdown to the editor with the following items.
*
* | "select" |
* | complete address 1 |
* | complete address 2 |
* ...
* | complete address n |
* | "add address" |
*/
private void addBillingAddressDropdown(EditorModel editor, final CreditCard card) {
final List<DropdownKeyValue> billingAddresses = new ArrayList<>();
billingAddresses.add(new DropdownKeyValue(BILLING_ADDRESS_NONE, mContext.getString(R.string.select)));
for (Map.Entry<String, AutofillProfile> address : mProfilesForBillingAddress.entrySet()) {
// Key is profile GUID. Value is profile label.
billingAddresses.add(new DropdownKeyValue(address.getKey(), address.getValue().getLabel()));
}
billingAddresses.add(new DropdownKeyValue(BILLING_ADDRESS_ADD_NEW, mContext.getString(R.string.autofill_create_profile)));
// Don't cache the billing address dropdown, because the user may have added or removed
// profiles.
mBillingAddressField = EditorFieldModel.createDropdown(mContext.getString(R.string.autofill_credit_card_editor_billing_address), billingAddresses);
// The billing address is required.
mBillingAddressField.setRequiredErrorMessage(mContext.getString(R.string.payments_field_required_validation_message));
mBillingAddressField.setDropdownCallback(new Callback<Pair<String, Runnable>>() {
@Override
public void onResult(final Pair<String, Runnable> eventData) {
if (!BILLING_ADDRESS_ADD_NEW.equals(eventData.first)) {
if (mObserverForTest != null) {
mObserverForTest.onPaymentRequestServiceBillingAddressChangeProcessed();
}
return;
}
mAddressEditor.edit(null, new Callback<AutofillAddress>() {
@Override
public void onResult(AutofillAddress billingAddress) {
if (billingAddress == null) {
// User has cancelled the address editor.
mBillingAddressField.setValue(null);
} else {
// User has added a new complete address. Add it to the top of the
// dropdown, under the "Select" prompt.
mProfilesForBillingAddress.put(billingAddress.getIdentifier(), billingAddress.getProfile());
billingAddresses.add(1, new DropdownKeyValue(billingAddress.getIdentifier(), billingAddress.getSublabel()));
mBillingAddressField.setDropdownKeyValues(billingAddresses);
mBillingAddressField.setValue(billingAddress.getIdentifier());
}
// Let the card editor UI re-read the model and re-create UI elements.
mHandler.post(eventData.second);
}
});
}
});
if (mBillingAddressField.getDropdownKeys().contains(card.getBillingAddressId())) {
mBillingAddressField.setValue(card.getBillingAddressId());
}
editor.addField(mBillingAddressField);
}
Aggregations