Commit f62142c6 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Fix progress bar for trigger scripts.

Before this change, the progress bar for trigger scripts would flakily
not show the progress correctly due to missing change notifications.

Bug: b/173790448
Change-Id: I4bb51ceee69f81ad41d69739a20f0c4b1e38d60b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550918
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarSandro Maggi <sandromaggi@google.com>
Cr-Commit-Position: refs/heads/master@{#830130}
parent 91f6ba42
......@@ -59,7 +59,7 @@ public class AssistantTriggerScript {
private final ApplicationViewportInsetSupplier mApplicationViewportInsetSupplier;
private AssistantHeaderCoordinator mHeaderCoordinator;
private final AssistantHeaderModel mHeaderModel = new AssistantHeaderModel();
private AssistantHeaderModel mHeaderModel;
private LinearLayout mChipsContainer;
private final int mInnerChipSpacing;
/** Height of the bottom sheet's shadow, used to compute the viewport resize offset. */
......@@ -109,8 +109,6 @@ public class AssistantTriggerScript {
R.dimen.autofill_assistant_actions_spacing);
mShadowHeight = mContext.getResources().getDimensionPixelSize(
R.dimen.bottom_sheet_toolbar_shadow_height);
mHeaderModel.set(
AssistantHeaderModel.FEEDBACK_BUTTON_CALLBACK, mDelegate::onFeedbackButtonClicked);
}
private void createBottomSheetContents() {
......@@ -133,10 +131,6 @@ public class AssistantTriggerScript {
// Allow swipe-to-dismiss.
mContent.setPeekModeDisabled(true);
if (mHeaderCoordinator != null) {
mHeaderCoordinator.destroy();
}
mHeaderCoordinator = new AssistantHeaderCoordinator(mContext, mHeaderModel);
mChipsContainer = new LinearLayout(mContext);
mChipsContainer.setOrientation(LinearLayout.HORIZONTAL);
int horizontalMargin = mContext.getResources().getDimensionPixelSize(
......@@ -196,7 +190,14 @@ public class AssistantTriggerScript {
}
}
public AssistantHeaderModel getHeaderModel() {
public AssistantHeaderModel createHeaderAndGetModel() {
mHeaderModel = new AssistantHeaderModel();
if (mHeaderCoordinator != null) {
mHeaderCoordinator.destroy();
}
mHeaderCoordinator = new AssistantHeaderCoordinator(mContext, mHeaderModel);
mHeaderModel.set(
AssistantHeaderModel.FEEDBACK_BUTTON_CALLBACK, mDelegate::onFeedbackButtonClicked);
return mHeaderModel;
}
......@@ -248,7 +249,11 @@ public class AssistantTriggerScript {
addChipsToContainer(mChipsContainer, mRightAlignedChips);
}
public void show(boolean resizeVisualViewport) {
public boolean show(boolean resizeVisualViewport) {
if (mHeaderModel == null || mHeaderCoordinator == null) {
assert false : "createHeaderAndGetModel() must be called before show()";
return false;
}
mResizeVisualViewport = resizeVisualViewport;
createBottomSheetContents();
update();
......@@ -256,6 +261,7 @@ public class AssistantTriggerScript {
mBottomSheetController.addObserver(mBottomSheetObserver);
BottomSheetUtils.showContentAndMaybeExpand(mBottomSheetController, mContent,
/* shouldExpand = */ true, /* animate = */ mAnimateBottomSheet);
return true;
}
public void hide() {
......
......@@ -100,9 +100,14 @@ public class AssistantTriggerScriptBridge {
.startTriggerScript(this, initialUrl, scriptParameters, experimentIds);
}
/**
* Re-creates the header and returns the new header model. Must be called before every
* invocation of {@code showTriggerScript}. It is not possible to persist headers across
* multiple shown trigger scripts.
*/
@CalledByNative
private AssistantHeaderModel getHeaderModel() {
return mTriggerScript.getHeaderModel();
private AssistantHeaderModel createHeaderAndGetModel() {
return mTriggerScript.createHeaderAndGetModel();
}
@CalledByNative
......@@ -111,8 +116,8 @@ public class AssistantTriggerScriptBridge {
}
/**
* Used by native to update and show the UI. The header should be updated using {@code
* getHeaderModel} prior to calling this function.
* Used by native to update and show the UI. The header should be created and updated using
* {@code createHeaderAndGetModel} prior to calling this function.
* @return true if the trigger script was displayed, else false.
*/
@CalledByNative
......@@ -130,11 +135,13 @@ public class AssistantTriggerScriptBridge {
mTriggerScript.setCancelPopupMenu(cancelPopupMenuItems, cancelPopupMenuActions);
mTriggerScript.setLeftAlignedChips(leftAlignedChips, leftAlignedChipsActions);
mTriggerScript.setRightAlignedChips(rightAlignedChips, rightAlignedChipsActions);
mTriggerScript.show(resizeVisualViewport);
boolean shown = mTriggerScript.show(resizeVisualViewport);
// A trigger script was displayed, users are no longer considered first-time users.
AutofillAssistantPreferencesUtil.setAutofillAssistantReturningLiteScriptUser();
return true;
if (shown) {
AutofillAssistantPreferencesUtil.setAutofillAssistantReturningLiteScriptUser();
}
return shown;
}
@CalledByNative
......
......@@ -125,7 +125,8 @@ void TriggerScriptBridgeAndroid::OnTriggerScriptShown(
}
JNIEnv* env = AttachCurrentThread();
auto jheader_model =
Java_AssistantTriggerScriptBridge_getHeaderModel(env, java_object_);
Java_AssistantTriggerScriptBridge_createHeaderAndGetModel(env,
java_object_);
AssistantHeaderModel header_model(jheader_model);
if (disable_header_animations_for_testing_) {
header_model.SetDisableAnimations(disable_header_animations_for_testing_);
......
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