From 0a6e9d765de44f6c4ebf0cba3154bb8564ddf2e6 Mon Sep 17 00:00:00 2001 From: Willie Koomson Date: Fri, 5 Apr 2024 02:28:45 +0000 Subject: [PATCH] Fix issue with tap-to-add on recycled WidgetCells Updates BaseWidgetSheet to check if the last recorded widget cell to show an add button is still showing an add button before deciding how to handle the current click. When a widget is recycled or loses focus, it will reset to the default state of hiding the add button. However, BaseWidgetSheet still tracks it. If that cell is clicked again after being reset, we want to show the add button. Bug: TODO Test: manual Flag: ACONFIG com.android.launcher3.enable_widget_tap_to_add TEAMFOOD Change-Id: I4614674948a52b8908fabf5c0e5734bf76b9282b --- .../android/launcher3/widget/BaseWidgetSheet.java | 12 ++++++++++-- src/com/android/launcher3/widget/WidgetCell.java | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java index aa797ab8a0..7795806798 100644 --- a/src/com/android/launcher3/widget/BaseWidgetSheet.java +++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java @@ -143,9 +143,17 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView if (enableWidgetTapToAdd()) { scrollToWidgetCell(wc); + if (mWidgetCellWithAddButton != null) { - // If there is a add button currently showing, hide it. - mWidgetCellWithAddButton.hideAddButton(/* animate= */ true); + if (mWidgetCellWithAddButton.isShowingAddButton()) { + // If there is a add button currently showing, hide it. + mWidgetCellWithAddButton.hideAddButton(/* animate= */ true); + } else { + // The last recorded widget cell to show an add button is no longer showing it, + // likely because the widget cell has been recycled or lost focus. If this is + // the cell that has been clicked, we will show it below. + mWidgetCellWithAddButton = null; + } } if (mWidgetCellWithAddButton != wc) { diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java index ab007fb6a7..ea167d75ea 100644 --- a/src/com/android/launcher3/widget/WidgetCell.java +++ b/src/com/android/launcher3/widget/WidgetCell.java @@ -110,6 +110,7 @@ public class WidgetCell extends LinearLayout { private int mSourceContainer = CONTAINER_WIDGETS_TRAY; private CancellableTask mIconLoadRequest; + private boolean mIsShowingAddButton = false; public WidgetCell(Context context) { this(context, null); @@ -534,6 +535,9 @@ public class WidgetCell extends LinearLayout { * @param callback Callback to be set on the button. */ public void showAddButton(View.OnClickListener callback) { + if (mIsShowingAddButton) return; + mIsShowingAddButton = true; + mWidgetAddButton.setAlpha(0F); mWidgetAddButton.setVisibility(VISIBLE); mWidgetAddButton.setOnClickListener(callback); @@ -555,6 +559,9 @@ public class WidgetCell extends LinearLayout { * Hide tap to add button. */ public void hideAddButton(boolean animate) { + if (!mIsShowingAddButton) return; + mIsShowingAddButton = false; + mWidgetAddButton.setOnClickListener(null); mWidgetAddButton.animate().cancel(); mWidgetTextContainer.animate().cancel(); @@ -579,4 +586,8 @@ public class WidgetCell extends LinearLayout { .alpha(1F) .setDuration(ADD_BUTTON_FADE_DURATION_MS); } + + public boolean isShowingAddButton() { + return mIsShowingAddButton; + } }