Commit de43c424 authored by Luca Hunkeler's avatar Luca Hunkeler Committed by Commit Bot

[Autofill Assistant] Add onclick listener to checkbox inner view

If a TextView containing a link (ClickableSpan) is specified as
right/left content view, the onclick of the checkbox will not trigger
while clicking the TextView. To make sure it does, we need to direclty
specify the onclick on the sub view.


Bug: b/170293718
Change-Id: Id5498b0617fd01a507b97c3377ad79aa3d67421c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2489646
Commit-Queue: Luca Hunkeler <hluca@google.com>
Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#823475}
parent 3dcbf868
......@@ -46,8 +46,20 @@ class AssistantToggleButton extends LinearLayout {
addView(rightContentView);
}
setOnClickListener(unusedView
-> mToggleButton.setChecked(isCheckbox ? !mToggleButton.isChecked() : true));
View.OnClickListener clickListener = unusedView
-> mToggleButton.setChecked(isCheckbox ? !mToggleButton.isChecked() : true);
setOnClickListener(clickListener);
// If a view contains a url (ClickableSpan) and is contained in a LinearLayout, the
// OnClickListener of the LinearLayout will not extend to the contained view. To avoid this,
// we specifically set the listener on the subview as well.
if (leftContentView != null) {
leftContentView.setOnClickListener(clickListener);
}
if (rightContentView != null) {
rightContentView.setOnClickListener(clickListener);
}
mToggleButton.setOnCheckedChangeListener(
(unusedView, isChecked) -> onCheckedChanged.onResult(isChecked));
}
......
......@@ -1987,6 +1987,12 @@ public class AutofillAssistantGenericUiTest {
// Pre-select check box e.
modelValues.add((ModelProto.ModelValue) ModelProto.ModelValue.newBuilder()
.setIdentifier("option_e_toggled")
.setValue(ValueProto.newBuilder().setBooleans(
BooleanList.newBuilder().addValues(true)))
.build());
// Check box is initially unselected
modelValues.add((ModelProto.ModelValue) ModelProto.ModelValue.newBuilder()
.setIdentifier("option_f_toggled")
.setValue(ValueProto.newBuilder().setBooleans(
BooleanList.newBuilder().addValues(false)))
.build());
......@@ -2038,7 +2044,9 @@ public class AutofillAssistantGenericUiTest {
"group_b", "option_d_view",
"option_d_toggled"),
createCheckBoxView("Optional option E",
"option_e_view", "option_e_toggled")))))
"option_e_view", "option_e_toggled"),
createCheckBoxView("Optional option F",
"option_f_view", "option_f_toggled")))))
.setInteractions(
InteractionsProto.newBuilder().addAllInteractions(interactions))
.setModel(ModelProto.newBuilder().addAllValues(modelValues))
......@@ -2051,7 +2059,7 @@ public class AutofillAssistantGenericUiTest {
.addAllOutputModelIdentifiers(Arrays.asList(
"option_a_toggled", "option_b_toggled",
"option_c_toggled", "option_d_toggled",
"option_e_toggled")))
"option_e_toggled", "option_f_toggled")))
.build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder()
......@@ -2081,6 +2089,9 @@ public class AutofillAssistantGenericUiTest {
.check(matches(isChecked()));
onView(allOf(withClassName(is(CheckBox.class.getName())),
hasSibling(withText("Optional option E"))))
.check(matches(isChecked()));
onView(allOf(withClassName(is(CheckBox.class.getName())),
hasSibling(withText("Optional option F"))))
.check(matches(isNotChecked()));
onView(withText("Option A")).perform(click());
......@@ -2093,7 +2104,8 @@ public class AutofillAssistantGenericUiTest {
// Selecting an already checked check box inverts its value.
onView(withText("Optional option E")).perform(click());
onView(withText("Optional option E")).perform(click());
onView(withText("Optional option F")).perform(click());
int numNextActionsCalled = testService.getNextActionsCounter();
onView(withText("Done")).perform(click());
......@@ -2105,7 +2117,7 @@ public class AutofillAssistantGenericUiTest {
processedActions.get(0).getStatus(), is(ProcessedActionStatusProto.ACTION_APPLIED));
ShowGenericUiProto.Result result = processedActions.get(0).getShowGenericUiResult();
List<ModelProto.ModelValue> resultModelValues = result.getModel().getValuesList();
assertThat(resultModelValues, iterableWithSize(5));
assertThat(resultModelValues, iterableWithSize(6));
assertThat(resultModelValues,
containsInAnyOrder((ModelProto.ModelValue) ModelProto.ModelValue.newBuilder()
.setIdentifier("option_a_toggled")
......@@ -2131,6 +2143,11 @@ public class AutofillAssistantGenericUiTest {
.setIdentifier("option_e_toggled")
.setValue(ValueProto.newBuilder().setBooleans(
BooleanList.newBuilder().addValues(false)))
.build(),
(ModelProto.ModelValue) ModelProto.ModelValue.newBuilder()
.setIdentifier("option_f_toggled")
.setValue(ValueProto.newBuilder().setBooleans(
BooleanList.newBuilder().addValues(true)))
.build()));
}
......
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