Do not modify the original item info when adding a new item in Worksapce

Fix: 418114270
Test: NA
Flag: EXEMPT bug fix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:dbd6f0d18f69d5d33862aaad015c4c8c5907fb46)
Merged-In: Ic0dd00da4f363868a1c2abeeb736b86f6f706631
Change-Id: Ic0dd00da4f363868a1c2abeeb736b86f6f706631
This commit is contained in:
Sebastian Franco
2025-06-09 16:08:14 -05:00
committed by Android Build Coastguard Worker
parent 1a3a1dea81
commit cc18ee380e
3 changed files with 12 additions and 10 deletions

View File

@@ -2906,8 +2906,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
// TODO(b/414409465) We could just create a new info making a copy with all the new
// needed values instead of choosing on each case what to modify.
info.container = container;
View view = mLauncher.getItemInflater().inflateItem(info, cellLayout);
View view = mLauncher.getItemInflater().inflateItem(info, cellLayout, container);
d.dragInfo = info = (ItemInfo) view.getTag();
// First we find the cell nearest to point at which the item is

View File

@@ -54,7 +54,11 @@ class ItemInflater<T>(
WidgetInflater(context, LauncherAppState.getInstance(context).isSafeModeEnabled)
@JvmOverloads
fun inflateItem(item: ItemInfo, nullableParent: ViewGroup? = null): View? {
fun inflateItem(
item: ItemInfo,
nullableParent: ViewGroup? = null,
container: Int = item.container,
): View? {
val parent = nullableParent ?: defaultParent
when (item.itemType) {
Favorites.ITEM_TYPE_APPLICATION,
@@ -66,11 +70,11 @@ class ItemInflater<T>(
is WorkspaceItemInfo -> item
else -> return null
}
if (info.container == Favorites.CONTAINER_ALL_APPS_PREDICTION) {
if (container == Favorites.CONTAINER_ALL_APPS_PREDICTION) {
// Came from all apps prediction row -- make a copy
info = WorkspaceItemInfo(info)
}
return createShortcut(info, parent)
return createShortcut(info, parent, container)
}
Favorites.ITEM_TYPE_FOLDER ->
return FolderIcon.inflateFolderAndIcon(
@@ -103,10 +107,9 @@ class ItemInflater<T>(
* @param info The data structure describing the shortcut.
* @return A View inflated from layoutResId.
*/
private fun createShortcut(info: WorkspaceItemInfo, parent: ViewGroup): View {
private fun createShortcut(info: WorkspaceItemInfo, parent: ViewGroup, container: Int): View {
val layout =
if (info.container == Favorites.CONTAINER_HOTSEAT_PREDICTION)
R.layout.predicted_app_icon
if (container == Favorites.CONTAINER_HOTSEAT_PREDICTION) R.layout.predicted_app_icon
else R.layout.app_icon
val favorite =
LayoutInflater.from(parent.context).inflate(layout, parent, false) as BubbleTextView
@@ -114,7 +117,7 @@ class ItemInflater<T>(
favorite.setOnClickListener(clickListener)
favorite.onFocusChangeListener = focusListener
if (info.container == Favorites.CONTAINER_HOTSEAT_PREDICTION) favorite.verifyHighRes()
if (container == Favorites.CONTAINER_HOTSEAT_PREDICTION) favorite.verifyHighRes()
return favorite
}

View File

@@ -98,7 +98,7 @@ class AsyncBindingTest {
View(context)
}
.whenever(itemInflater)
.inflateItem(any(), isNull())
.inflateItem(any(), isNull(), any())
doReturn(itemInflater).whenever(launcher).itemInflater
doReturn(InvariantDeviceProfile.INSTANCE.get(context).getDeviceProfile(context))