Unifying various model update callbacks into one

Making the BubbleTextView.applyItem stateless so that it does not depend on the order of events

Bug: 390572144
Flag: EXEMPT refactor
Test: atest LauncherBindableItemsContainerTest
      atest BubbleTextViewTest
Change-Id: Ib9c0ac6c330d6f4e08c3db5772d35787fa056b65
This commit is contained in:
Sunny Goyal
2025-01-22 23:44:41 -08:00
parent 1809cb6ff3
commit 36c3112abf
19 changed files with 442 additions and 370 deletions

View File

@@ -27,7 +27,9 @@ import static com.android.launcher3.BubbleTextView.DISPLAY_SEARCH_RESULT_SMALL;
import static com.android.launcher3.Flags.FLAG_ENABLE_SUPPORT_FOR_ARCHIVING;
import static com.android.launcher3.Flags.FLAG_USE_NEW_ICON_FOR_ARCHIVED_APPS;
import static com.android.launcher3.LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE;
import static com.android.launcher3.anim.AnimatorListeners.forEndCallback;
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ARCHIVED;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.google.common.truth.Truth.assertThat;
@@ -39,6 +41,8 @@ import static org.mockito.Mockito.verify;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Typeface;
import android.os.Build;
import android.os.UserHandle;
@@ -57,13 +61,17 @@ import com.android.launcher3.BubbleTextView;
import com.android.launcher3.Flags;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.Utilities;
import com.android.launcher3.graphics.PreloadIconDrawable;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.pm.PackageInstallInfo;
import com.android.launcher3.search.StringMatcherUtility;
import com.android.launcher3.util.ActivityContextWrapper;
import com.android.launcher3.util.FlagOp;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.LauncherModelHelper.SandboxModelContext;
import com.android.launcher3.util.TestUtil;
import com.android.launcher3.views.BaseDragLayer;
import org.junit.After;
@@ -73,6 +81,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import java.util.concurrent.CountDownLatch;
/**
* Unit tests for testing modifyTitleToSupportMultiLine() in BubbleTextView.java
* This class tests a couple of strings and uses the getMaxLines() to determine if the test passes.
@@ -485,4 +495,40 @@ public class BubbleTextViewTest {
assertThat(mBubbleTextView.getIcon().hasBadge()).isEqualTo(true);
}
@Test
public void applyingPendingIcon_preserves_last_icon() throws Exception {
mItemInfoWithIcon.bitmap =
BitmapInfo.fromBitmap(Bitmap.createBitmap(100, 100, Config.ARGB_8888));
mItemInfoWithIcon.setProgressLevel(30, PackageInstallInfo.STATUS_INSTALLING);
TestUtil.runOnExecutorSync(MAIN_EXECUTOR,
() -> mBubbleTextView.applyIconAndLabel(mItemInfoWithIcon));
assertThat(mBubbleTextView.getIcon()).isInstanceOf(PreloadIconDrawable.class);
assertThat(mBubbleTextView.getIcon().getLevel()).isEqualTo(30);
PreloadIconDrawable oldIcon = (PreloadIconDrawable) mBubbleTextView.getIcon();
// Same icon is used when progress changes
mItemInfoWithIcon.setProgressLevel(50, PackageInstallInfo.STATUS_INSTALLING);
TestUtil.runOnExecutorSync(MAIN_EXECUTOR,
() -> mBubbleTextView.applyIconAndLabel(mItemInfoWithIcon));
assertThat(mBubbleTextView.getIcon()).isSameInstanceAs(oldIcon);
assertThat(mBubbleTextView.getIcon().getLevel()).isEqualTo(50);
// Icon is replaced with a non pending icon when download finishes
mItemInfoWithIcon.setProgressLevel(100, PackageInstallInfo.STATUS_INSTALLED);
CountDownLatch animWait = new CountDownLatch(1);
TestUtil.runOnExecutorSync(MAIN_EXECUTOR, () -> {
mBubbleTextView.applyIconAndLabel(mItemInfoWithIcon);
assertThat(mBubbleTextView.getIcon()).isSameInstanceAs(oldIcon);
assertThat(oldIcon.getActiveAnimation()).isNotNull();
oldIcon.getActiveAnimation().addListener(forEndCallback(animWait::countDown));
});
animWait.await();
// Assert that the icon is replaced with a non-pending icon
assertThat(mBubbleTextView.getIcon()).isNotInstanceOf(PreloadIconDrawable.class);
}
}