[Search] Fix ItemInfo assignment conflict
When a BubbleTextHolder has more than one bubble text view, BubbleTextView#getParent().onItemInfoChanged is problematic as the ItemInfo associated with the last BubbleTextView will be the final ItemInfo set on parent. This is fixed by setting ItemInfo change receiver more explicitly.
Bug: 203020679
Test: Manual
Change-Id: Ia8aeead1a6151c2aa47148ba4846ae3d3ee39b73
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 9da2b79..521d8f4 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -66,7 +66,6 @@
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.views.ActivityContext;
-import com.android.launcher3.views.BubbleTextHolder;
import com.android.launcher3.views.IconLabelDotView;
import java.text.NumberFormat;
@@ -163,6 +162,7 @@
private HandlerRunnable mIconLoadRequest;
private boolean mEnableIconUpdateAnimation = false;
+ private ItemInfoUpdateReceiver mItemInfoUpdateReceiver;
public BubbleTextView(Context context) {
this(context, null, 0);
@@ -240,6 +240,7 @@
mDotParams.scale = 0f;
mForceHideDot = false;
setBackground(null);
+ mItemInfoUpdateReceiver = null;
}
private void cancelDotScaleAnim() {
@@ -337,13 +338,18 @@
setDownloadStateContentDescription(info, info.getProgressLevel());
}
- private void setItemInfo(ItemInfo itemInfo) {
+ private void setItemInfo(ItemInfoWithIcon itemInfo) {
setTag(itemInfo);
- if (getParent() instanceof BubbleTextHolder) {
- ((BubbleTextHolder) getParent()).onItemInfoChanged(itemInfo);
+ if (mItemInfoUpdateReceiver != null) {
+ mItemInfoUpdateReceiver.reapplyItemInfo(itemInfo);
}
}
+ public void setItemInfoUpdateReceiver(
+ ItemInfoUpdateReceiver itemInfoUpdateReceiver) {
+ mItemInfoUpdateReceiver = itemInfoUpdateReceiver;
+ }
+
@UiThread
protected void applyIconAndLabel(ItemInfoWithIcon info) {
boolean useTheme = mDisplay == DISPLAY_WORKSPACE || mDisplay == DISPLAY_FOLDER
diff --git a/src/com/android/launcher3/views/BubbleTextHolder.java b/src/com/android/launcher3/views/BubbleTextHolder.java
index 78aac06..42701c6 100644
--- a/src/com/android/launcher3/views/BubbleTextHolder.java
+++ b/src/com/android/launcher3/views/BubbleTextHolder.java
@@ -16,12 +16,14 @@
package com.android.launcher3.views;
import com.android.launcher3.BubbleTextView;
+import com.android.launcher3.icons.IconCache;
import com.android.launcher3.model.data.ItemInfo;
+import com.android.launcher3.model.data.ItemInfoWithIcon;
/**
* Views that contain {@link BubbleTextView} should implement this interface.
*/
-public interface BubbleTextHolder {
+public interface BubbleTextHolder extends IconCache.ItemInfoUpdateReceiver {
BubbleTextView getBubbleText();
/**
@@ -29,6 +31,6 @@
*
* @param itemInfo the new itemInfo
*/
- default void onItemInfoChanged(ItemInfo itemInfo) {
- }
+ @Override
+ default void reapplyItemInfo(ItemInfoWithIcon itemInfo){};
}