Commit 9a3f8d70 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[PRImpl] Move PRImpl#editAddress into PaymentUIsManager

Change:
* Move the editAddress method into PaymentUIsManager.
* Refactor editAddress by moving journeylogger (business logic) out of
the method.

Bug: 1102522

Change-Id: Ic273827e34574ebf1d4e68e17fe446d7fcc7db83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2330331
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794315}
parent 0823567e
...@@ -1429,7 +1429,8 @@ public class PaymentRequestImpl ...@@ -1429,7 +1429,8 @@ public class PaymentRequestImpl
}); });
} }
private void recordShowEventAndTransactionAmount() { @Override
public void recordShowEventAndTransactionAmount() {
if (mDidRecordShowEvent) return; if (mDidRecordShowEvent) return;
mDidRecordShowEvent = true; mDidRecordShowEvent = true;
mJourneyLogger.setEventOccurred(Event.SHOWN); mJourneyLogger.setEventOccurred(Event.SHOWN);
...@@ -1485,7 +1486,9 @@ public class PaymentRequestImpl ...@@ -1485,7 +1486,9 @@ public class PaymentRequestImpl
mPaymentUIsManager.getShippingAddressesSection().setSelectedItem(option); mPaymentUIsManager.getShippingAddressesSection().setSelectedItem(option);
startShippingAddressChangeNormalization(address); startShippingAddressChangeNormalization(address);
} else { } else {
editAddress(address); // Log the edit of a shipping address.
mJourneyLogger.incrementSelectionEdits(Section.SHIPPING_ADDRESS);
mPaymentUIsManager.editAddress(address);
} }
mPaymentUIsManager.setPaymentInformationCallback(callback); mPaymentUIsManager.setPaymentInformationCallback(callback);
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION; return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
...@@ -1549,7 +1552,9 @@ public class PaymentRequestImpl ...@@ -1549,7 +1552,9 @@ public class PaymentRequestImpl
public int onSectionEditOption(@PaymentRequestUI.DataType int optionType, EditableOption option, public int onSectionEditOption(@PaymentRequestUI.DataType int optionType, EditableOption option,
Callback<PaymentInformation> callback) { Callback<PaymentInformation> callback) {
if (optionType == PaymentRequestUI.DataType.SHIPPING_ADDRESSES) { if (optionType == PaymentRequestUI.DataType.SHIPPING_ADDRESSES) {
editAddress((AutofillAddress) option); // Log the edit of a shipping address.
mJourneyLogger.incrementSelectionEdits(Section.SHIPPING_ADDRESS);
mPaymentUIsManager.editAddress((AutofillAddress) option);
mPaymentUIsManager.setPaymentInformationCallback(callback); mPaymentUIsManager.setPaymentInformationCallback(callback);
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION; return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
...@@ -1575,7 +1580,7 @@ public class PaymentRequestImpl ...@@ -1575,7 +1580,7 @@ public class PaymentRequestImpl
public int onSectionAddOption( public int onSectionAddOption(
@PaymentRequestUI.DataType int optionType, Callback<PaymentInformation> callback) { @PaymentRequestUI.DataType int optionType, Callback<PaymentInformation> callback) {
if (optionType == PaymentRequestUI.DataType.SHIPPING_ADDRESSES) { if (optionType == PaymentRequestUI.DataType.SHIPPING_ADDRESSES) {
editAddress(null); mPaymentUIsManager.editAddress(null);
mPaymentUIsManager.setPaymentInformationCallback(callback); mPaymentUIsManager.setPaymentInformationCallback(callback);
// Log the add of shipping address. // Log the add of shipping address.
mJourneyLogger.incrementSelectionAdds(Section.SHIPPING_ADDRESS); mJourneyLogger.incrementSelectionAdds(Section.SHIPPING_ADDRESS);
...@@ -1605,67 +1610,6 @@ public class PaymentRequestImpl ...@@ -1605,67 +1610,6 @@ public class PaymentRequestImpl
return mPaymentUIsManager.shouldShowContactSection(); return mPaymentUIsManager.shouldShowContactSection();
} }
private void editAddress(final AutofillAddress toEdit) {
if (toEdit != null) {
// Log the edit of a shipping address.
mJourneyLogger.incrementSelectionEdits(Section.SHIPPING_ADDRESS);
}
mPaymentUIsManager.getAddressEditor().edit(toEdit, new Callback<AutofillAddress>() {
@Override
public void onResult(AutofillAddress editedAddress) {
if (mPaymentUIsManager.getPaymentRequestUI() == null) return;
if (editedAddress != null) {
mPaymentUIsManager.getAddressEditor().setAddressErrors(null);
// Sets or updates the shipping address label.
editedAddress.setShippingAddressLabelWithCountry();
mPaymentUIsManager.getCardEditor().updateBillingAddressIfComplete(
editedAddress);
// A partial or complete address came back from the editor (could have been from
// adding/editing or cancelling out of the edit flow).
if (!editedAddress.isComplete()) {
// If the address is not complete, unselect it (editor can return incomplete
// information when cancelled).
mPaymentUIsManager.getShippingAddressesSection().setSelectedItemIndex(
SectionInformation.NO_SELECTION);
mPaymentUIsManager.providePaymentInformationToPaymentRequestUI();
recordShowEventAndTransactionAmount();
} else {
if (toEdit == null) {
// Address is complete and user was in the "Add flow": add an item to
// the list.
mPaymentUIsManager.getShippingAddressesSection().addAndSelectItem(
editedAddress);
}
if (mPaymentUIsManager.getContactSection() != null) {
// Update |mPaymentUIsManager.getContactSection()| with the new/edited
// address, which will update an existing item or add a new one to the
// end of the list.
mPaymentUIsManager.getContactSection().addOrUpdateWithAutofillAddress(
editedAddress);
mPaymentUIsManager.getPaymentRequestUI().updateSection(
PaymentRequestUI.DataType.CONTACT_DETAILS,
mPaymentUIsManager.getContactSection());
}
startShippingAddressChangeNormalization(editedAddress);
}
} else {
mPaymentUIsManager.providePaymentInformationToPaymentRequestUI();
recordShowEventAndTransactionAmount();
}
if (!mPaymentUIsManager.getRetryQueue().isEmpty()) {
mHandler.post(mPaymentUIsManager.getRetryQueue().remove());
}
}
});
}
private void editCard(final AutofillPaymentInstrument toEdit) { private void editCard(final AutofillPaymentInstrument toEdit) {
if (toEdit != null) { if (toEdit != null) {
// Log the edit of a credit card. // Log the edit of a credit card.
...@@ -1945,7 +1889,9 @@ public class PaymentRequestImpl ...@@ -1945,7 +1889,9 @@ public class PaymentRequestImpl
AutofillAddress selectedAddress = AutofillAddress selectedAddress =
(AutofillAddress) mPaymentUIsManager.getShippingAddressesSection() (AutofillAddress) mPaymentUIsManager.getShippingAddressesSection()
.getSelectedItem(); .getSelectedItem();
editAddress(selectedAddress); // Log the edit of a shipping address.
mJourneyLogger.incrementSelectionEdits(Section.SHIPPING_ADDRESS);
mPaymentUIsManager.editAddress(selectedAddress);
}); });
} }
...@@ -2562,12 +2508,12 @@ public class PaymentRequestImpl ...@@ -2562,12 +2508,12 @@ public class PaymentRequestImpl
onAddressNormalized(profile); onAddressNormalized(profile);
} }
/** @Override
* Starts the normalization of the new shipping address. Will call back into either public void startShippingAddressChangeNormalization(AutofillAddress address) {
* onAddressNormalized or onCouldNotNormalize which will send the result to the merchant. // Will call back into either onAddressNormalized or onCouldNotNormalize which will send the
*/ // result to the merchant.
private void startShippingAddressChangeNormalization(AutofillAddress address) { PersonalDataManager.getInstance().normalizeAddress(
PersonalDataManager.getInstance().normalizeAddress(address.getProfile(), this); address.getProfile(), /* delegate= */ this);
} }
/** /**
......
...@@ -94,6 +94,10 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -94,6 +94,10 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
public interface Delegate { public interface Delegate {
/** Dispatch the payer detail change event if needed. */ /** Dispatch the payer detail change event if needed. */
void dispatchPayerDetailChangeEventIfNeeded(PayerDetail detail); void dispatchPayerDetailChangeEventIfNeeded(PayerDetail detail);
/** Record the show event to the journey logger and record the transaction amount. */
void recordShowEventAndTransactionAmount();
/** Start the normalization of the new shipping address. */
void startShippingAddressChangeNormalization(AutofillAddress editedAddress);
} }
/** /**
...@@ -795,4 +799,59 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -795,4 +799,59 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
} }
}); });
} }
/**
* Edit the address on the PaymentRequest UI.
* @param toEdit The address to edit.
*/
public void editAddress(final AutofillAddress toEdit) {
mAddressEditor.edit(toEdit, new Callback<AutofillAddress>() {
@Override
public void onResult(AutofillAddress editedAddress) {
if (mPaymentRequestUI == null) return;
if (editedAddress != null) {
mAddressEditor.setAddressErrors(null);
// Sets or updates the shipping address label.
editedAddress.setShippingAddressLabelWithCountry();
mCardEditor.updateBillingAddressIfComplete(editedAddress);
// A partial or complete address came back from the editor (could have been from
// adding/editing or cancelling out of the edit flow).
if (!editedAddress.isComplete()) {
// If the address is not complete, unselect it (editor can return incomplete
// information when cancelled).
mShippingAddressesSection.setSelectedItemIndex(
SectionInformation.NO_SELECTION);
providePaymentInformationToPaymentRequestUI();
mDelegate.recordShowEventAndTransactionAmount();
} else {
if (toEdit == null) {
// Address is complete and user was in the "Add flow": add an item to
// the list.
mShippingAddressesSection.addAndSelectItem(editedAddress);
}
if (mContactSection != null) {
// Update |mContactSection| with the new/edited
// address, which will update an existing item or add a new one to the
// end of the list.
mContactSection.addOrUpdateWithAutofillAddress(editedAddress);
mPaymentRequestUI.updateSection(
PaymentRequestUI.DataType.CONTACT_DETAILS, mContactSection);
}
mDelegate.startShippingAddressChangeNormalization(editedAddress);
}
} else {
providePaymentInformationToPaymentRequestUI();
mDelegate.recordShowEventAndTransactionAmount();
}
if (!mRetryQueue.isEmpty()) mHandler.post(mRetryQueue.remove());
}
});
}
} }
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