From 81cec527e902e035d1b342be0624c888740e10d0 Mon Sep 17 00:00:00 2001 From: Sebastian Franco Date: Mon, 23 May 2022 16:33:38 -0700 Subject: [PATCH] Fix folder preview animation when adding or removing icons. The functions PreviewItemManager.updatePreviewItems calls PreviewItemManager.buildParamsForPage using mFirstPageParams and it expects that mFirstPageParams contains the values before the reoredering but they get updated in a previous call to updatePreviewItems(false), so when doing the animation, the icons are animated to their current position and nothing changes. Fix: 233401274 Test: Add icons to a folder 1 to 5 without expanding the folder and make sure they animate to their new position. Make sure they animate when removing items as well. Change-Id: Ia3e1393d8fb2b30eb107e8b2c6eefdf9e50e9f70 --- .../android/launcher3/folder/PreviewItemManager.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/folder/PreviewItemManager.java b/src/com/android/launcher3/folder/PreviewItemManager.java index 6355b62e27..2e5f2e5d60 100644 --- a/src/com/android/launcher3/folder/PreviewItemManager.java +++ b/src/com/android/launcher3/folder/PreviewItemManager.java @@ -79,6 +79,8 @@ public class PreviewItemManager { private int mPrevTopPadding = -1; private Drawable mReferenceDrawable = null; + private int mNumOfPrevItems = 0; + // These hold the first page preview items private ArrayList mFirstPageParams = new ArrayList<>(); // These hold the current page preview items. It is empty if the current page is the first page. @@ -254,7 +256,6 @@ public class PreviewItemManager { void buildParamsForPage(int page, ArrayList params, boolean animate) { List items = mIcon.getPreviewItemsOnPage(page); - int prevNumItems = params.size(); // We adjust the size of the list to match the number of items in the preview. while (items.size() < params.size()) { @@ -278,8 +279,9 @@ public class PreviewItemManager { mReferenceDrawable = p.drawable; } } else { - FolderPreviewItemAnim anim = new FolderPreviewItemAnim(this, p, i, prevNumItems, i, - numItemsInFirstPagePreview, DROP_IN_ANIMATION_DURATION, null); + FolderPreviewItemAnim anim = new FolderPreviewItemAnim(this, p, i, + mNumOfPrevItems, i, numItemsInFirstPagePreview, DROP_IN_ANIMATION_DURATION, + null); if (p.anim != null) { if (p.anim.hasEqualFinalState(anim)) { @@ -318,7 +320,9 @@ public class PreviewItemManager { } void updatePreviewItems(boolean animate) { + int numOfPrevItemsAux = mFirstPageParams.size(); buildParamsForPage(0, mFirstPageParams, animate); + mNumOfPrevItems = numOfPrevItemsAux; } void updatePreviewItems(Predicate itemCheck) {