Fixing dangling PS container on profile addition.
When Work profile state is changed, the all apps container is redrawn
Eventually `PrivateProfileManager.reset()` is also called but PS decorator
is not added as there is no change in PS state.
https://photos.app.goo.gl/V2bmZWfzBzcRP97C8
To fix this, we allow decorator addition on reset, but only
apply the same when its not already present in the recycler view.
Flag: ACONFIG com.android.launcher3.Flags.enable_private_space DEVELOPMENT
Bug: 313498792
Test: PrivateProfileManagerTest
Change-Id: I4c9a89d84e670ed45bf53a2d2e2c4922b165463e
diff --git a/src/com/android/launcher3/allapps/PrivateProfileManager.java b/src/com/android/launcher3/allapps/PrivateProfileManager.java
index d8f6689..77eb07e 100644
--- a/src/com/android/launcher3/allapps/PrivateProfileManager.java
+++ b/src/com/android/launcher3/allapps/PrivateProfileManager.java
@@ -92,9 +92,6 @@
boolean isEnabled = !mAllApps.getAppsStore()
.hasModelFlag(FLAG_PRIVATE_PROFILE_QUIET_MODE_ENABLED);
int updatedState = isEnabled ? STATE_ENABLED : STATE_DISABLED;
- if (getCurrentState() == updatedState) {
- return;
- }
setCurrentState(updatedState);
resetPrivateSpaceDecorator(updatedState);
}
@@ -126,19 +123,27 @@
@VisibleForTesting
void resetPrivateSpaceDecorator(int updatedState) {
+ ActivityAllAppsContainerView<?>.AdapterHolder mainAdapterHolder = mAllApps.mAH.get(MAIN);
if (updatedState == STATE_ENABLED) {
- // Add Private Space Decorator to the Recycler view.
+ // Create a new decorator instance if not already available.
if (mPrivateAppsSectionDecorator == null) {
mPrivateAppsSectionDecorator = new PrivateAppsSectionDecorator(
mAllApps.mActivityContext,
- mAllApps.mAH.get(MAIN).mAppsList);
+ mainAdapterHolder.mAppsList);
}
- mAllApps.mAH.get(MAIN).mRecyclerView.addItemDecoration(mPrivateAppsSectionDecorator);
+ for (int i = 0; i < mainAdapterHolder.mRecyclerView.getItemDecorationCount(); i++) {
+ if (mainAdapterHolder.mRecyclerView.getItemDecorationAt(i)
+ .equals(mPrivateAppsSectionDecorator)) {
+ // No need to add another decorator if one is already present in recycler view.
+ return;
+ }
+ }
+ // Add Private Space Decorator to the Recycler view.
+ mainAdapterHolder.mRecyclerView.addItemDecoration(mPrivateAppsSectionDecorator);
} else {
// Remove Private Space Decorator from the Recycler view.
if (mPrivateAppsSectionDecorator != null) {
- mAllApps.mAH.get(MAIN).mRecyclerView
- .removeItemDecoration(mPrivateAppsSectionDecorator);
+ mainAdapterHolder.mRecyclerView.removeItemDecoration(mPrivateAppsSectionDecorator);
}
}
}