Commit 11ce2ef2 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[PRImpl] Move editCard to PaymentUisManager

Change:
Since PRImpl#editCard() is UI logic, we are moving it into
PaymentUisManager.

Bug: 1102522

Change-Id: Ib0694ea2f5ab2256c4a65ff558aba25bc05fe25b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335801
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795077}
parent 922aa385
......@@ -1455,7 +1455,7 @@ public class PaymentRequestImpl
AutofillPaymentInstrument card = (AutofillPaymentInstrument) paymentApp;
if (!card.isComplete()) {
editCard(card);
mPaymentUIsManager.editCard(card);
return PaymentRequestUI.SelectionResult.EDITOR_LAUNCH;
}
}
......@@ -1489,7 +1489,7 @@ public class PaymentRequestImpl
}
if (optionType == PaymentRequestUI.DataType.PAYMENT_METHODS) {
editCard((AutofillPaymentInstrument) option);
mPaymentUIsManager.editCard((AutofillPaymentInstrument) option);
return PaymentRequestUI.SelectionResult.EDITOR_LAUNCH;
}
......@@ -1513,7 +1513,7 @@ public class PaymentRequestImpl
mJourneyLogger.incrementSelectionAdds(Section.CONTACT_INFO);
return PaymentRequestUI.SelectionResult.EDITOR_LAUNCH;
} else if (optionType == PaymentRequestUI.DataType.PAYMENT_METHODS) {
editCard(null);
mPaymentUIsManager.editCard(null);
// Log the add of credit card.
mJourneyLogger.incrementSelectionAdds(Section.PAYMENT_METHOD);
return PaymentRequestUI.SelectionResult.EDITOR_LAUNCH;
......@@ -1532,43 +1532,6 @@ public class PaymentRequestImpl
return mPaymentUIsManager.shouldShowContactSection();
}
private void editCard(final AutofillPaymentInstrument toEdit) {
if (toEdit != null) {
// Log the edit of a credit card.
mJourneyLogger.incrementSelectionEdits(Section.PAYMENT_METHOD);
}
mPaymentUIsManager.getCardEditor().edit(toEdit, new Callback<AutofillPaymentInstrument>() {
@Override
public void onResult(AutofillPaymentInstrument editedCard) {
if (mPaymentUIsManager.getPaymentRequestUI() == null) return;
if (editedCard != null) {
// A partial or complete card came back from the editor (could have been from
// adding/editing or cancelling out of the edit flow).
if (!editedCard.isComplete()) {
// If the card is not complete, unselect it (editor can return incomplete
// information when cancelled).
mPaymentUIsManager.getPaymentMethodsSection().setSelectedItemIndex(
SectionInformation.NO_SELECTION);
} else if (toEdit == null) {
// Card is complete and we were in the "Add flow": add an item to the list.
mPaymentUIsManager.getPaymentMethodsSection().addAndSelectItem(editedCard);
}
// If card is complete and (toEdit != null), no action needed: the card was
// already selected in the UI.
}
// If |editedCard| is null, the user has cancelled out of the "Add flow". No action
// to take (if another card was selected prior to the add flow, it will stay
// selected).
mPaymentUIsManager.updateAppModifiedTotals();
mPaymentUIsManager.getPaymentRequestUI().updateSection(
PaymentRequestUI.DataType.PAYMENT_METHODS,
mPaymentUIsManager.getPaymentMethodsSection());
}
});
}
@Override
public void onInstrumentDetailsLoadingWithoutUI() {
if (getClient() == null || mPaymentUIsManager.getPaymentRequestUI() == null
......
......@@ -22,6 +22,7 @@ import org.chromium.chrome.browser.payments.AutofillAddress;
import org.chromium.chrome.browser.payments.AutofillContact;
import org.chromium.chrome.browser.payments.AutofillPaymentAppCreator;
import org.chromium.chrome.browser.payments.AutofillPaymentAppFactory;
import org.chromium.chrome.browser.payments.AutofillPaymentInstrument;
import org.chromium.chrome.browser.payments.CardEditor;
import org.chromium.chrome.browser.payments.ContactEditor;
import org.chromium.chrome.browser.payments.PaymentRequestImpl;
......@@ -780,9 +781,9 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
/**
* Edit the contact information on the PaymentRequest UI.
* @param toEdit The information to edit.
* @param toEdit The information to edit, allowed to be null.
**/
public void editContactOnPaymentRequestUI(final AutofillContact toEdit) {
public void editContactOnPaymentRequestUI(@Nullable final AutofillContact toEdit) {
mContactEditor.edit(toEdit, new Callback<AutofillContact>() {
@Override
public void onResult(AutofillContact editedContact) {
......@@ -821,9 +822,9 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
/**
* Edit the address on the PaymentRequest UI.
* @param toEdit The address to edit.
* @param toEdit The address to be updated with, allowed to be null.
*/
public void editAddress(final AutofillAddress toEdit) {
public void editAddress(@Nullable final AutofillAddress toEdit) {
mAddressEditor.edit(toEdit, new Callback<AutofillAddress>() {
@Override
public void onResult(AutofillAddress editedAddress) {
......@@ -946,4 +947,45 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
public void rankPaymentAppsForPaymentRequestUI(List<PaymentApp> paymentApps) {
Collections.sort(paymentApps, mPaymentAppComparator);
}
/**
* Edit the credit cards on the PaymentRequest UI.
* @param toEdit The AutofillPaymentInstrument whose credit card is to replace those on the UI,
* allowed to be null.
*/
public void editCard(@Nullable final AutofillPaymentInstrument toEdit) {
if (toEdit != null) {
// Log the edit of a credit card.
mJourneyLogger.incrementSelectionEdits(Section.PAYMENT_METHOD);
}
mCardEditor.edit(toEdit, new Callback<AutofillPaymentInstrument>() {
@Override
public void onResult(AutofillPaymentInstrument editedCard) {
if (mPaymentRequestUI == null) return;
if (editedCard != null) {
// A partial or complete card came back from the editor (could have been from
// adding/editing or cancelling out of the edit flow).
if (!editedCard.isComplete()) {
// If the card is not complete, unselect it (editor can return incomplete
// information when cancelled).
mPaymentMethodsSection.setSelectedItemIndex(
SectionInformation.NO_SELECTION);
} else if (toEdit == null) {
// Card is complete and we were in the "Add flow": add an item to the list.
mPaymentMethodsSection.addAndSelectItem(editedCard);
}
// If card is complete and (toEdit != null), no action needed: the card was
// already selected in the UI.
}
// If |editedCard| is null, the user has cancelled out of the "Add flow". No action
// to take (if another card was selected prior to the add flow, it will stay
// selected).
updateAppModifiedTotals();
mPaymentRequestUI.updateSection(
PaymentRequestUI.DataType.PAYMENT_METHODS, mPaymentMethodsSection);
}
});
}
}
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