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 { ...@@ -59,7 +59,7 @@ public class AssistantTriggerScript {
private final ApplicationViewportInsetSupplier mApplicationViewportInsetSupplier; private final ApplicationViewportInsetSupplier mApplicationViewportInsetSupplier;
private AssistantHeaderCoordinator mHeaderCoordinator; private AssistantHeaderCoordinator mHeaderCoordinator;
private final AssistantHeaderModel mHeaderModel = new AssistantHeaderModel(); private AssistantHeaderModel mHeaderModel;
private LinearLayout mChipsContainer; private LinearLayout mChipsContainer;
private final int mInnerChipSpacing; private final int mInnerChipSpacing;
/** Height of the bottom sheet's shadow, used to compute the viewport resize offset. */ /** Height of the bottom sheet's shadow, used to compute the viewport resize offset. */
...@@ -109,8 +109,6 @@ public class AssistantTriggerScript { ...@@ -109,8 +109,6 @@ public class AssistantTriggerScript {
R.dimen.autofill_assistant_actions_spacing); R.dimen.autofill_assistant_actions_spacing);
mShadowHeight = mContext.getResources().getDimensionPixelSize( mShadowHeight = mContext.getResources().getDimensionPixelSize(
R.dimen.bottom_sheet_toolbar_shadow_height); R.dimen.bottom_sheet_toolbar_shadow_height);
mHeaderModel.set(
AssistantHeaderModel.FEEDBACK_BUTTON_CALLBACK, mDelegate::onFeedbackButtonClicked);
} }
private void createBottomSheetContents() { private void createBottomSheetContents() {
...@@ -133,10 +131,6 @@ public class AssistantTriggerScript { ...@@ -133,10 +131,6 @@ public class AssistantTriggerScript {
// Allow swipe-to-dismiss. // Allow swipe-to-dismiss.
mContent.setPeekModeDisabled(true); mContent.setPeekModeDisabled(true);
if (mHeaderCoordinator != null) {
mHeaderCoordinator.destroy();
}
mHeaderCoordinator = new AssistantHeaderCoordinator(mContext, mHeaderModel);
mChipsContainer = new LinearLayout(mContext); mChipsContainer = new LinearLayout(mContext);
mChipsContainer.setOrientation(LinearLayout.HORIZONTAL); mChipsContainer.setOrientation(LinearLayout.HORIZONTAL);
int horizontalMargin = mContext.getResources().getDimensionPixelSize( int horizontalMargin = mContext.getResources().getDimensionPixelSize(
...@@ -196,7 +190,14 @@ public class AssistantTriggerScript { ...@@ -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; return mHeaderModel;
} }
...@@ -248,7 +249,11 @@ public class AssistantTriggerScript { ...@@ -248,7 +249,11 @@ public class AssistantTriggerScript {
addChipsToContainer(mChipsContainer, mRightAlignedChips); 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; mResizeVisualViewport = resizeVisualViewport;
createBottomSheetContents(); createBottomSheetContents();
update(); update();
...@@ -256,6 +261,7 @@ public class AssistantTriggerScript { ...@@ -256,6 +261,7 @@ public class AssistantTriggerScript {
mBottomSheetController.addObserver(mBottomSheetObserver); mBottomSheetController.addObserver(mBottomSheetObserver);
BottomSheetUtils.showContentAndMaybeExpand(mBottomSheetController, mContent, BottomSheetUtils.showContentAndMaybeExpand(mBottomSheetController, mContent,
/* shouldExpand = */ true, /* animate = */ mAnimateBottomSheet); /* shouldExpand = */ true, /* animate = */ mAnimateBottomSheet);
return true;
} }
public void hide() { public void hide() {
......
...@@ -100,9 +100,14 @@ public class AssistantTriggerScriptBridge { ...@@ -100,9 +100,14 @@ public class AssistantTriggerScriptBridge {
.startTriggerScript(this, initialUrl, scriptParameters, experimentIds); .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 @CalledByNative
private AssistantHeaderModel getHeaderModel() { private AssistantHeaderModel createHeaderAndGetModel() {
return mTriggerScript.getHeaderModel(); return mTriggerScript.createHeaderAndGetModel();
} }
@CalledByNative @CalledByNative
...@@ -111,8 +116,8 @@ public class AssistantTriggerScriptBridge { ...@@ -111,8 +116,8 @@ public class AssistantTriggerScriptBridge {
} }
/** /**
* Used by native to update and show the UI. The header should be updated using {@code * Used by native to update and show the UI. The header should be created and updated using
* getHeaderModel} prior to calling this function. * {@code createHeaderAndGetModel} prior to calling this function.
* @return true if the trigger script was displayed, else false. * @return true if the trigger script was displayed, else false.
*/ */
@CalledByNative @CalledByNative
...@@ -130,11 +135,13 @@ public class AssistantTriggerScriptBridge { ...@@ -130,11 +135,13 @@ public class AssistantTriggerScriptBridge {
mTriggerScript.setCancelPopupMenu(cancelPopupMenuItems, cancelPopupMenuActions); mTriggerScript.setCancelPopupMenu(cancelPopupMenuItems, cancelPopupMenuActions);
mTriggerScript.setLeftAlignedChips(leftAlignedChips, leftAlignedChipsActions); mTriggerScript.setLeftAlignedChips(leftAlignedChips, leftAlignedChipsActions);
mTriggerScript.setRightAlignedChips(rightAlignedChips, rightAlignedChipsActions); 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. // A trigger script was displayed, users are no longer considered first-time users.
if (shown) {
AutofillAssistantPreferencesUtil.setAutofillAssistantReturningLiteScriptUser(); AutofillAssistantPreferencesUtil.setAutofillAssistantReturningLiteScriptUser();
return true; }
return shown;
} }
@CalledByNative @CalledByNative
......
...@@ -125,7 +125,8 @@ void TriggerScriptBridgeAndroid::OnTriggerScriptShown( ...@@ -125,7 +125,8 @@ void TriggerScriptBridgeAndroid::OnTriggerScriptShown(
} }
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
auto jheader_model = auto jheader_model =
Java_AssistantTriggerScriptBridge_getHeaderModel(env, java_object_); Java_AssistantTriggerScriptBridge_createHeaderAndGetModel(env,
java_object_);
AssistantHeaderModel header_model(jheader_model); AssistantHeaderModel header_model(jheader_model);
if (disable_header_animations_for_testing_) { if (disable_header_animations_for_testing_) {
header_model.SetDisableAnimations(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