From 14ec21748b7b48053b8c8a7ff3cddbe795157612 Mon Sep 17 00:00:00 2001 From: Brandon Dayauon Date: Mon, 15 Apr 2024 14:14:30 -0700 Subject: [PATCH] Fix views being visible after closing private space. Its possible views are still being binded before the app list is refreshed. So instead make the views gone in that case (by making sure private profile is disabled). Fixes: - install app icon still showing because it is not identified as a private space item - Divider still containing a decorator when collapsing before app list is refreshed. bug: 334868779 Test video manualy: before:https://drive.google.com/file/d/1IWdGsTSq7-xRZKOJso-5p9g-j7RTEkas/view?usp=sharing after:https://drive.google.com/file/d/1IVNTksryFi5o4uHzZtzNC0Yz7-rxrje3/view?usp=sharing Flag: ACONFIG com.android.launcher3.Flags.private_space_animation trunkfood Change-Id: If93e39753352741fb6f0728f717a67b7f9315d0b --- .../launcher3/allapps/BaseAllAppsAdapter.java | 34 +++++++++++++------ .../allapps/PrivateAppsSectionDecorator.java | 3 ++ .../allapps/PrivateProfileManager.java | 3 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java b/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java index 3ba1eedc5c..a21d7be587 100644 --- a/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java +++ b/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.allapps; +import static android.view.View.GONE; + import static com.android.launcher3.allapps.SectionDecorationInfo.ROUND_BOTTOM_LEFT; import static com.android.launcher3.allapps.SectionDecorationInfo.ROUND_BOTTOM_RIGHT; import static com.android.launcher3.allapps.SectionDecorationInfo.ROUND_NOTHING; @@ -42,6 +44,7 @@ import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; import com.android.launcher3.allapps.search.SearchAdapterProvider; import com.android.launcher3.model.data.AppInfo; +import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.views.ActivityContext; /** @@ -263,15 +266,25 @@ public abstract class BaseAllAppsAdapter ex icon.applyFromApplicationInfo(adapterItem.itemInfo); icon.setOnFocusChangeListener(mIconFocusListener); PrivateProfileManager privateProfileManager = mApps.getPrivateProfileManager(); - // Set the alpha of the private space icon to 0 upon expanding the header so the - // alpha can animate -> 1. - if (icon.getAlpha() == 0 || icon.getAlpha() == 1) { - icon.setAlpha(privateProfileManager != null - && privateProfileManager.isPrivateSpaceItem(adapterItem) - && privateProfileManager.getAnimationScrolling() - && privateProfileManager.getAnimate() - && privateProfileManager.getCurrentState() == STATE_ENABLED - ? 0 : 1); + if (privateProfileManager != null) { + // Set the alpha of the private space icon to 0 upon expanding the header so the + // alpha can animate -> 1. + boolean isPrivateSpaceItem = + privateProfileManager.isPrivateSpaceItem(adapterItem); + if (icon.getAlpha() == 0 || icon.getAlpha() == 1) { + icon.setAlpha(isPrivateSpaceItem + && privateProfileManager.getAnimationScrolling() + && privateProfileManager.getAnimate() + && privateProfileManager.getCurrentState() == STATE_ENABLED + ? 0 : 1); + } + // Views can still be bounded before the app list is updated hence showing icons + // after collapsing. + if (privateProfileManager.getCurrentState() == STATE_DISABLED + && isPrivateSpaceItem) { + adapterItem.decorationInfo = null; + icon.setVisibility(GONE); + } } break; } @@ -298,7 +311,8 @@ public abstract class BaseAllAppsAdapter ex break; case VIEW_TYPE_PRIVATE_SPACE_SYS_APPS_DIVIDER: adapterItem = mApps.getAdapterItems().get(position); - adapterItem.decorationInfo = new SectionDecorationInfo(mActivityContext, + adapterItem.decorationInfo = mApps.getPrivateProfileManager().getCurrentState() + == STATE_DISABLED ? null : new SectionDecorationInfo(mActivityContext, ROUND_NOTHING, true /* decorateTogether */); break; case VIEW_TYPE_ALL_APPS_DIVIDER: diff --git a/src/com/android/launcher3/allapps/PrivateAppsSectionDecorator.java b/src/com/android/launcher3/allapps/PrivateAppsSectionDecorator.java index 18175b6add..339e443642 100644 --- a/src/com/android/launcher3/allapps/PrivateAppsSectionDecorator.java +++ b/src/com/android/launcher3/allapps/PrivateAppsSectionDecorator.java @@ -43,6 +43,9 @@ public class PrivateAppsSectionDecorator extends RecyclerView.ItemDecoration { for (int i = 0; i < parent.getChildCount(); i++) { View view = parent.getChildAt(i); int position = parent.getChildAdapterPosition(view); + if (position < 0 || position >= mAppsList.getAdapterItems().size()) { + continue; + } BaseAllAppsAdapter.AdapterItem adapterItem = mAppsList.getAdapterItems().get(position); SectionDecorationInfo info = adapterItem.decorationInfo; if (info == null) { diff --git a/src/com/android/launcher3/allapps/PrivateProfileManager.java b/src/com/android/launcher3/allapps/PrivateProfileManager.java index 7b1ed6421c..90ed3eb5cc 100644 --- a/src/com/android/launcher3/allapps/PrivateProfileManager.java +++ b/src/com/android/launcher3/allapps/PrivateProfileManager.java @@ -159,6 +159,7 @@ public class PrivateProfileManager extends UserProfileManager { itemInfo.contentDescription = context.getResources().getString( com.android.launcher3.R.string.ps_add_button_content_description); itemInfo.runtimeStatusFlags |= FLAG_NOT_PINNABLE; + itemInfo.user = getProfileUser(); BaseAllAppsAdapter.AdapterItem item = new BaseAllAppsAdapter.AdapterItem(VIEW_TYPE_ICON); item.itemInfo = itemInfo; @@ -746,6 +747,6 @@ public class PrivateProfileManager extends UserProfileManager { } boolean isPrivateSpaceItem(BaseAllAppsAdapter.AdapterItem item) { - return item.decorationInfo != null; + return getItemInfoMatcher().test(item.itemInfo) || item.decorationInfo != null; } }