Search in sources :

Example 1 with PersonalDataManager

use of org.chromium.chrome.browser.autofill.PersonalDataManager in project AndroidChromium by JackyAndroid.

the class AddressEditor method commitChanges.

/**
 * Saves the edited profile on disk.
 */
private void commitChanges(AutofillProfile profile) {
    // Country code and phone number are always required and are always collected from the
    // editor model.
    profile.setCountryCode(mCountryField.getValue().toString());
    profile.setPhoneNumber(mPhoneField.getValue().toString());
    // Autofill profile bridge normalizes the language code for the autofill profile.
    profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode());
    // Collect data from all visible fields and store it in the autofill profile.
    Set<Integer> visibleFields = new HashSet<>();
    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);
        visibleFields.add(component.id);
        if (component.id != AddressField.COUNTRY) {
            setProfileField(profile, component.id, mAddressFields.get(component.id).getValue());
        }
    }
    // AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings.
    for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) {
        if (!visibleFields.contains(entry.getKey())) {
            setProfileField(profile, entry.getKey(), "");
        }
    }
    // Calculate the label for this profile. The label's format depends on the country and
    // language code for the profile.
    PersonalDataManager pdm = PersonalDataManager.getInstance();
    // TODO(crbug.com/666048): New billing address label is wrong.
    profile.setLabel(pdm.getAddressLabelForPaymentRequest(profile));
    // Save the edited autofill profile locally.
    profile.setGUID(pdm.setProfileToLocal(profile));
    profile.setIsLocal(true);
}
Also used : EditorFieldModel(org.chromium.chrome.browser.payments.ui.EditorFieldModel) AddressUiComponent(org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressUiComponent) PersonalDataManager(org.chromium.chrome.browser.autofill.PersonalDataManager) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with PersonalDataManager

use of org.chromium.chrome.browser.autofill.PersonalDataManager in project AndroidChromium by JackyAndroid.

the class CardEditor method commitChanges.

/**
 * Saves the edited credit card.
 *
 * If this is a server card, then only its billing address identifier is updated.
 *
 * If this is a new local card, then it's saved on this device only if the user has checked the
 * "save this card" checkbox.
 */
private void commitChanges(CreditCard card, boolean isNewCard) {
    card.setBillingAddressId(mBillingAddressField.getValue().toString());
    PersonalDataManager pdm = PersonalDataManager.getInstance();
    if (!card.getIsLocal()) {
        pdm.updateServerCardBillingAddress(card.getServerId(), card.getBillingAddressId());
        return;
    }
    card.setNumber(mNumberField.getValue().toString().replace(" ", "").replace("-", ""));
    card.setName(mNameField.getValue().toString());
    card.setMonth(mMonthField.getValue().toString());
    card.setYear(mYearField.getValue().toString());
    // Calculate the basic card payment type, obfuscated number, and the icon for this card.
    // All of these depend on the card number. The type is sent to the merchant website. The
    // obfuscated number and the icon are displayed in the user interface.
    CreditCard displayableCard = pdm.getCreditCardForNumber(card.getNumber());
    card.setBasicCardPaymentType(displayableCard.getBasicCardPaymentType());
    card.setObfuscatedNumber(displayableCard.getObfuscatedNumber());
    card.setIssuerIconDrawableId(displayableCard.getIssuerIconDrawableId());
    if (!isNewCard) {
        pdm.setCreditCard(card);
        return;
    }
    if (mSaveCardCheckbox != null && mSaveCardCheckbox.isChecked()) {
        card.setGUID(pdm.setCreditCard(card));
    }
}
Also used : PersonalDataManager(org.chromium.chrome.browser.autofill.PersonalDataManager) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Example 3 with PersonalDataManager

use of org.chromium.chrome.browser.autofill.PersonalDataManager in project AndroidChromium by JackyAndroid.

the class AutofillLocalCardEditor method saveEntry.

@Override
protected boolean saveEntry() {
    // Remove all spaces in editText.
    String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", "");
    PersonalDataManager personalDataManager = PersonalDataManager.getInstance();
    // Card Payment Type will be empty if credit card number is not valid.
    if (TextUtils.isEmpty(personalDataManager.getBasicCardPaymentType(cardNumber, true))) {
        mNumberLabel.setError(mContext.getString(R.string.payments_card_number_invalid_validation_message));
        return false;
    }
    CreditCard card = new CreditCard(mGUID, AutofillPreferences.SETTINGS_ORIGIN, true, /* isLocal */
    false, /* isCached */
    mNameText.getText().toString().trim(), cardNumber, "", /* obfuscatedNumber */
    String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1), (String) mExpirationYear.getSelectedItem(), "", /* basicCardPaymentType */
    0, /* issuerIconDrawableId */
    ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID(), /* billing */
    "");
    personalDataManager.setCreditCard(card);
    return true;
}
Also used : PersonalDataManager(org.chromium.chrome.browser.autofill.PersonalDataManager) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Example 4 with PersonalDataManager

use of org.chromium.chrome.browser.autofill.PersonalDataManager in project AndroidChromium by JackyAndroid.

the class AutofillPaymentApp method getInstruments.

@Override
public void getInstruments(JSONObject unusedDetails, final InstrumentsCallback callback) {
    PersonalDataManager pdm = PersonalDataManager.getInstance();
    List<CreditCard> cards = pdm.getCreditCardsToSuggest();
    final List<PaymentInstrument> instruments = new ArrayList<>(cards.size());
    for (int i = 0; i < cards.size(); i++) {
        CreditCard card = cards.get(i);
        AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAddressId()) ? null : pdm.getProfile(card.getBillingAddressId());
        instruments.add(new AutofillPaymentInstrument(mWebContents, card, billingAddress));
    }
    new Handler().post(new Runnable() {

        @Override
        public void run() {
            callback.onInstrumentsReady(AutofillPaymentApp.this, instruments);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Handler(android.os.Handler) PersonalDataManager(org.chromium.chrome.browser.autofill.PersonalDataManager) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Example 5 with PersonalDataManager

use of org.chromium.chrome.browser.autofill.PersonalDataManager in project AndroidChromium by JackyAndroid.

the class AutofillPaymentApp method getInstruments.

@Override
public void getInstruments(Map<String, PaymentMethodData> unusedMethodData, final InstrumentsCallback callback) {
    PersonalDataManager pdm = PersonalDataManager.getInstance();
    List<CreditCard> cards = pdm.getCreditCardsToSuggest();
    final List<PaymentInstrument> instruments = new ArrayList<>(cards.size());
    for (int i = 0; i < cards.size(); i++) {
        CreditCard card = cards.get(i);
        AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAddressId()) ? null : pdm.getProfile(card.getBillingAddressId());
        if (billingAddress != null && AutofillAddress.checkAddressCompletionStatus(billingAddress) != AutofillAddress.COMPLETE) {
            billingAddress = null;
        }
        instruments.add(new AutofillPaymentInstrument(mContext, mWebContents, card, billingAddress));
    }
    new Handler().post(new Runnable() {

        @Override
        public void run() {
            callback.onInstrumentsReady(AutofillPaymentApp.this, instruments);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Handler(android.os.Handler) PersonalDataManager(org.chromium.chrome.browser.autofill.PersonalDataManager) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Aggregations

PersonalDataManager (org.chromium.chrome.browser.autofill.PersonalDataManager)5 CreditCard (org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)4 Handler (android.os.Handler)2 ArrayList (java.util.ArrayList)2 AutofillProfile (org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 EditorFieldModel (org.chromium.chrome.browser.payments.ui.EditorFieldModel)1 AddressUiComponent (org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressUiComponent)1