Skip to content

Commit

Permalink
[Autofill Assistant] Payment Request uses carousel.
Browse files Browse the repository at this point in the history
This CL removes the PR bottom bar and uses the carousel for displaying
chips instead.

Change-Id: Ia030502ede21e8973e387b1ae06d015993a81bd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1503258
Auto-Submit: Jordan Demeulenaere <jdemeulenaere@chromium.org>
Commit-Queue: Jordan Demeulenaere <jdemeulenaere@chromium.org>
Reviewed-by: Stephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638944}
  • Loading branch information
Jordan Demeulenaere authored and Commit Bot committed Mar 8, 2019
1 parent c78ac10 commit e4f6d26
Show file tree
Hide file tree
Showing 25 changed files with 390 additions and 386 deletions.
1 change: 0 additions & 1 deletion chrome/android/features/autofill_assistant/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ android_library("java") {
"java/src/org/chromium/chrome/browser/autofill_assistant/payment/AssistantPaymentRequestOptions.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/payment/AutofillAssistantPaymentRequest.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/payment/AutofillAssistantPaymentRequestSection.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/payment/PaymentRequestBottomBar.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/payment/PaymentRequestUI.java",
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,4 @@
android:text="@string/autofill_assistant_3rd_party_privacy_notice"
android:textAppearance="@style/TextAppearance.AssistantBlackCaption"
android:background="@drawable/autofill_assistant_lightblue_rect_bg"/>

<include layout="@layout/autofill_assistant_payment_request_bottom_bar" />

</org.chromium.chrome.browser.widget.BoundedLinearLayout>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantCarouselModel;
import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChip;
import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChip.Type;
import org.chromium.chrome.browser.autofill_assistant.metrics.DropOutReason;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController;
Expand All @@ -24,7 +25,6 @@
import org.chromium.content_public.browser.WebContents;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -201,30 +201,25 @@ private void setSuggestions(String[] texts) {
for (int i = 0; i < texts.length; i++) {
final int suggestionIndex = i;
chips.add(new AssistantChip(AssistantChip.Type.CHIP_ASSISTIVE, texts[i],
() -> safeNativeOnSuggestionSelected(suggestionIndex)));
/* disabled= */ false, () -> safeNativeOnSuggestionSelected(suggestionIndex)));
}
AssistantCarouselModel model = getModel().getSuggestionsModel();
model.set(ALIGNMENT, AssistantCarouselModel.Alignment.START);
setChips(model, chips);
}

@CalledByNative
private void clearActions() {
getModel().getActionsModel().getChipsModel().set(Collections.emptyList());
}

/** Creates an empty list of chips. */
@CalledByNative
private static List<AssistantChip> createChipList() {
return new ArrayList<AssistantChip>();
return new ArrayList<>();
}

/**
* Adds an action button to the chip list, which executes the action {@code actionIndex}.
*/
@CalledByNative
private void addActionButton(List<AssistantChip> chips, String text, int actionIndex) {
chips.add(new AssistantChip(AssistantChip.Type.BUTTON_HAIRLINE, text,
chips.add(new AssistantChip(AssistantChip.Type.BUTTON_HAIRLINE, text, /* disabled= */ false,
() -> safeNativeOnActionSelected(actionIndex)));
}

Expand All @@ -234,8 +229,8 @@ private void addActionButton(List<AssistantChip> chips, String text, int actionI
*/
@CalledByNative
private void addHighlightedActionButton(
List<AssistantChip> chips, String text, int actionIndex) {
chips.add(new AssistantChip(AssistantChip.Type.BUTTON_FILLED_BLUE, text,
List<AssistantChip> chips, String text, int actionIndex, boolean disabled) {
chips.add(new AssistantChip(Type.BUTTON_FILLED_BLUE, text, disabled,
() -> safeNativeOnActionSelected(actionIndex)));
}

Expand All @@ -245,7 +240,7 @@ private void addHighlightedActionButton(
*/
@CalledByNative
private void addCancelButton(List<AssistantChip> chips, String text, int actionIndex) {
chips.add(new AssistantChip(AssistantChip.Type.BUTTON_HAIRLINE, text,
chips.add(new AssistantChip(AssistantChip.Type.BUTTON_HAIRLINE, text, /* disabled= */ false,
() -> safeNativeOnCancelButtonClicked(actionIndex)));
}

Expand All @@ -254,8 +249,8 @@ private void addCancelButton(List<AssistantChip> chips, String text, int actionI
*/
@CalledByNative
private void addCloseButton(List<AssistantChip> chips, String text) {
chips.add(new AssistantChip(
AssistantChip.Type.BUTTON_HAIRLINE, text, this::safeNativeOnCloseButtonClicked));
chips.add(new AssistantChip(AssistantChip.Type.BUTTON_HAIRLINE, text, /* disabled= */ false,
this::safeNativeOnCloseButtonClicked));
}

@CalledByNative
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public AssistantCarouselCoordinator(Context context, AssistantCarouselModel mode
mView.setLayoutManager(mLayoutManager);
mView.addItemDecoration(new SpaceItemDecoration(context));
mView.setAdapter(new RecyclerViewAdapter<>(
new SimpleRecyclerViewMcp<>(model.getChipsModel(), AssistantChip::getType,
AssistantChipViewHolder::bind),
new SimpleRecyclerViewMcp<>(model.getChipsModel(),
AssistantChipViewHolder::getViewType, AssistantChipViewHolder::bind),
AssistantChipViewHolder::create));

// Carousel is initially hidden.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@
* A chip to display to the user.
*/
public class AssistantChip {
@IntDef({Type.CHIP_ASSISTIVE, Type.BUTTON_FILLED_BLUE, Type.BUTTON_HAIRLINE,
Type.BUTTON_FILLED_DISABLED})
@IntDef({Type.CHIP_ASSISTIVE, Type.BUTTON_FILLED_BLUE, Type.BUTTON_HAIRLINE})
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
int CHIP_ASSISTIVE = 0;
int BUTTON_FILLED_BLUE = 1;
int BUTTON_HAIRLINE = 2;
int BUTTON_FILLED_DISABLED = 3;

/** The number of types. Increment this value if you add a type. */
int CHIP_TYPE_NUMBER = 3;
}

private final @Type int mType;
private final String mText;
private final boolean mDisabled;
private final Runnable mSelectedListener;

public AssistantChip(@Type int type, String text, Runnable selectedListener) {
public AssistantChip(@Type int type, String text, boolean disabled, Runnable selectedListener) {
mType = type;
mText = text;
mSelectedListener = selectedListener;
mDisabled = disabled;
}

public int getType() {
Expand All @@ -41,6 +44,10 @@ public String getText() {
return mText;
}

public boolean isDisabled() {
return mDisabled;
}

public Runnable getSelectedListener() {
return mSelectedListener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ private AssistantChipViewHolder(TextView itemView) {
static AssistantChipViewHolder create(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
int resId = -1;
switch (viewType) {
switch (viewType % AssistantChip.Type.CHIP_TYPE_NUMBER) {
// TODO: inflate normal chrome buttons instead.
case AssistantChip.Type.CHIP_ASSISTIVE:
resId = R.layout.autofill_assistant_chip_assistive;
break;
case AssistantChip.Type.BUTTON_FILLED_DISABLED:
case AssistantChip.Type.BUTTON_FILLED_BLUE:
resId = R.layout.autofill_assistant_button_filled;
break;
Expand All @@ -43,13 +42,24 @@ static AssistantChipViewHolder create(ViewGroup parent, int viewType) {
}

TextView view = (TextView) layoutInflater.inflate(resId, /* root= */ null);
if (viewType == AssistantChip.Type.BUTTON_FILLED_DISABLED) {
if (viewType >= AssistantChip.Type.CHIP_TYPE_NUMBER) {
view.setEnabled(false);
}

return new AssistantChipViewHolder(view);
}

static int getViewType(AssistantChip chip) {
// We add AssistantChip.Type.CHIP_TYPE_NUMBER to differentiate between enabled and disabled
// chips of the same type. Ideally, we should return a (type, disabled) tuple but
// RecyclerView does not allow that.
if (chip.isDisabled()) {
return chip.getType() + AssistantChip.Type.CHIP_TYPE_NUMBER;
}

return chip.getType();
}

public void bind(AssistantChip chip) {
mText.setText(chip.getText());
mText.setOnClickListener(ignoredView -> chip.getSelectedListener().run());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.payments.AutofillContact;

/** Delegate for the Payment Request UI. */
@JNINamespace("autofill_assistant")
Expand All @@ -25,20 +26,37 @@ private AssistantPaymentRequestDelegate(long nativeAssistantPaymentRequestDelega
mNativeAssistantOverlayDelegate = nativeAssistantPaymentRequestDelegate;
}

public void onPaymentInformationSelected(
AutofillAssistantPaymentRequest.SelectedPaymentInformation selectedInformation) {
public void onContactInfoChanged(AutofillContact contact) {
if (mNativeAssistantOverlayDelegate != 0) {
nativeOnGetPaymentInformation(mNativeAssistantOverlayDelegate,
selectedInformation.succeed, selectedInformation.card,
selectedInformation.address, selectedInformation.payerName,
selectedInformation.payerPhone, selectedInformation.payerEmail,
selectedInformation.isTermsAndConditionsAccepted);
String name = null;
String phone = null;
String email = null;

if (contact != null) {
name = contact.getPayerName();
phone = contact.getPayerPhone();
email = contact.getPayerEmail();
}

nativeOnContactInfoChanged(mNativeAssistantOverlayDelegate, name, phone, email);
}
}

public void onShippingAddressChanged(PersonalDataManager.AutofillProfile address) {
if (mNativeAssistantOverlayDelegate != 0) {
nativeOnShippingAddressChanged(mNativeAssistantOverlayDelegate, address);
}
}

public void onCancelButtonClicked() {
public void onCreditCardChanged(PersonalDataManager.CreditCard card) {
if (mNativeAssistantOverlayDelegate != 0) {
nativeOnCancelButtonClicked(mNativeAssistantOverlayDelegate);
nativeOnCreditCardChanged(mNativeAssistantOverlayDelegate, card);
}
}

public void onTermsAndConditionsChanged(@AssistantTermsAndConditionsState int state) {
if (mNativeAssistantOverlayDelegate != 0) {
nativeOnTermsAndConditionsChanged(mNativeAssistantOverlayDelegate, state);
}
}

Expand All @@ -47,11 +65,12 @@ private void clearNativePtr() {
mNativeAssistantOverlayDelegate = 0;
}

private native void nativeOnGetPaymentInformation(long nativeAssistantPaymentRequestDelegate,
boolean succeed, @Nullable PersonalDataManager.CreditCard card,
@Nullable PersonalDataManager.AutofillProfile address, @Nullable String payerName,
@Nullable String payerPhone, @Nullable String payerEmail,
boolean isTermsAndConditionsAccepted);

private native void nativeOnCancelButtonClicked(long nativeAssistantPaymentRequestDelegate);
private native void nativeOnContactInfoChanged(long nativeAssistantPaymentRequestDelegate,
@Nullable String payerName, @Nullable String payerPhone, @Nullable String payerEmail);
private native void nativeOnShippingAddressChanged(long nativeAssistantPaymentRequestDelegate,
@Nullable PersonalDataManager.AutofillProfile address);
private native void nativeOnCreditCardChanged(long nativeAssistantPaymentRequestDelegate,
@Nullable PersonalDataManager.CreditCard card);
private native void nativeOnTermsAndConditionsChanged(
long nativeAssistantPaymentRequestDelegate, int state);
}
Loading

0 comments on commit e4f6d26

Please sign in to comment.