Fix stale header height being used in scroll to header calculation

- This fixes the inconsistency of how far down is needed to scroll to since
the values used to calculate the header during drawOnScrimWithScaleAndBottomOffset() is faulty.
- Tweaked the row to scroll to when there are tabs vs no tabs. When there are no tabs, its possible the
header gets cut off most of the time hence subtracting by 1 will help this problem.

bug:332543940
Test locally: https://screenshot.googleplex.com/5y4vYiQcnSMKcA6
manual - before: https://drive.google.com/file/d/14Zj_FyO-3bVfXwuxaqgG_DXMELYS5bQn/view?usp=sharing
after with tabs:
after 5x5: https://drive.google.com/file/d/16rjaut6VqBMxG6uLQSnVTLRhUQnAANZ5/view?usp=sharing
after 4x5: https://drive.google.com/file/d/16jCPN8BewwuIQobt0t6tdVouUKpp1CdI/view?usp=sharing
after 4x4: https://drive.google.com/file/d/16VFQb5s6IfrpjRU9PmLlAJWjh1zIo77o/view?usp=sharing
after 3x3: https://drive.google.com/file/d/16VFQb5s6IfrpjRU9PmLlAJWjh1zIo77o/view?usp=sharing
after 2x2: https://drive.google.com/file/d/16N6Myuv9VtXgI1p4sIuV23iupea7jYLQ/view?usp=sharing

after no tabs:
after 5x5: https://drive.google.com/file/d/17H1oF_9fJnrtSqmJJqQyyn4upuM2CsoG/view?usp=sharing
after 4x5: https://drive.google.com/file/d/178Vu3SvnvSPODIfaR0oz6-jPVYDDNMaA/view?usp=sharing
after 4x4: https://drive.google.com/file/d/16yt_5ePPR7kwSrZlo5Sj3x0DqHoQKqYP/view?usp=sharing
after 3x3: https://drive.google.com/file/d/17HqebtHWcEHg-i9AfqHEVdl4YnQhX06P/view?usp=sharing
after 2x2: https://drive.google.com/file/d/17HqebtHWcEHg-i9AfqHEVdl4YnQhX06P/view?usp=sharing

after tablet:
landscape: https://drive.google.com/file/d/16JQGs0A3ifKpgqrpQwIzssrXbH-OC0Ej/view?usp=sharing
portrait: https://drive.google.com/file/d/16LmLnOEB6XkuAkAcgvP2mKHe5QQqG1oh/view?usp=sharing

Flag: ACONFIG com.android.launcher3.Flags.private_space_animation TRUNKFOOD

Change-Id: If8a70cc71e9cff4a7f8d3b648e3e59c414e40ee5
This commit is contained in:
Brandon Dayauon committed 2024-04-11 16:22:11 -07:00
1 parent 221117bcfd
commit 5da04b231f
4 files changed
+63 -12

No files matched your search

@@ -290,6 +290,7 @@ public class PrivateSpaceHeaderViewTest {
doReturn(0).when(privateProfileManager).addSystemAppsDivider(any());
when(mAllApps.getHeight()).thenReturn(ALL_APPS_HEIGHT);
when(mAllApps.getHeaderProtectionHeight()).thenReturn(HEADER_PROTECTION_HEIGHT);
when(mAllApps.isUsingTabs()).thenReturn(true);
mAlphabeticalAppsList = new AlphabeticalAppsList<>(mContext, mAllAppsStore,
null, privateProfileManager);
mAlphabeticalAppsList.setNumAppsPerRowAllApps(NUM_APP_COLS);
@@ -310,6 +311,43 @@ public class PrivateSpaceHeaderViewTest {
ALL_APPS_CELL_HEIGHT));
}
@Test
public void scrollForViewToBeVisibleInContainer_withHeaderNoTabs() {
when(mAllAppsStore.getApps()).thenReturn(createAppInfoList());
PrivateProfileManager privateProfileManager = spy(mPrivateProfileManager);
when(privateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED);
when(privateProfileManager.splitIntoUserInstalledAndSystemApps())
.thenReturn(iteminfo -> iteminfo.componentName == null
|| !iteminfo.componentName.getPackageName()
.equals(CAMERA_PACKAGE_NAME));
doReturn(0).when(privateProfileManager).addPrivateSpaceHeader(any());
doAnswer(answer(this::addPrivateSpaceHeader)).when(privateProfileManager)
.addPrivateSpaceHeader(any());
doNothing().when(privateProfileManager).addPrivateSpaceInstallAppButton(any());
doReturn(0).when(privateProfileManager).addSystemAppsDivider(any());
when(mAllApps.getHeight()).thenReturn(ALL_APPS_HEIGHT);
when(mAllApps.getHeaderProtectionHeight()).thenReturn(HEADER_PROTECTION_HEIGHT);
when(mAllApps.isUsingTabs()).thenReturn(false);
mAlphabeticalAppsList = new AlphabeticalAppsList<>(mContext, mAllAppsStore,
null, privateProfileManager);
mAlphabeticalAppsList.setNumAppsPerRowAllApps(NUM_APP_COLS);
mAlphabeticalAppsList.updateItemFilter(info -> info != null
&& info.user.equals(MAIN_HANDLE));
int rows = (int) (ALL_APPS_HEIGHT - PS_HEADER_HEIGHT - HEADER_PROTECTION_HEIGHT) - 1;
int position = rows * NUM_APP_COLS - (NUM_APP_COLS-1) + 1;
// The number of adapterItems should be the private space apps + one main app + header.
assertEquals(NUM_PRIVATE_SPACE_APPS + 1 + 1,
mAlphabeticalAppsList.getAdapterItems().size());
assertEquals(position,
privateProfileManager.scrollForHeaderToBeVisibleInContainer(
new AllAppsRecyclerView(mContext),
mAlphabeticalAppsList.getAdapterItems(),
PS_HEADER_HEIGHT,
ALL_APPS_CELL_HEIGHT));
}
@Test
public void scrollForViewToBeVisibleInContainer_withHeaderAndLessAppRowSpace() {
when(mAllAppsStore.getApps()).thenReturn(createAppInfoList());
@@ -325,6 +363,7 @@ public class PrivateSpaceHeaderViewTest {
doNothing().when(privateProfileManager).addPrivateSpaceInstallAppButton(any());
doReturn(0).when(privateProfileManager).addSystemAppsDivider(any());
when(mAllApps.getHeight()).thenReturn(ALL_APPS_HEIGHT);
when(mAllApps.isUsingTabs()).thenReturn(true);
when(mAllApps.getHeaderProtectionHeight()).thenReturn(HEADER_PROTECTION_HEIGHT);
mAlphabeticalAppsList = new AlphabeticalAppsList<>(mContext, mAllAppsStore,
null, privateProfileManager);