From 564d64c8cc81e12dcaaeffbb6058794a1565bd20 Mon Sep 17 00:00:00 2001 From: Jordan Silva Date: Wed, 5 Feb 2025 15:13:57 +0000 Subject: [PATCH] Refactor: Update the way tintAmount is propagated to TTV - Propagate the tintAmount using the Views instead of using a Flow. This was done to minimize the usage of Flows to propagate animations and progress through Views. It should improve the overall performance of UI updates Some stats about the number of collections: - Entering Overview: ~4 collections - Displaying Scrim: ~32 collections - Hiding Scrim: ~35 collections - With 4 apps on screen: ~140 collections Bug: 390581380 Doc: go/launcher-overview-unified-taskviewmodel Flag: com.android.launcher3.enable_refactor_task_thumbnail Test: OverviewImageTest Test: TaskViewModelTest Change-Id: Ice68edef12c7e3b2a26107b0fc6e62578de241b4 --- .../recents/ui/viewmodel/TaskViewModel.kt | 2 -- .../quickstep/recents/viewmodel/RecentsViewData.kt | 3 --- .../recents/viewmodel/RecentsViewModel.kt | 4 ---- .../com/android/quickstep/views/RecentsView.java | 6 +----- .../src/com/android/quickstep/views/TaskView.kt | 14 ++++---------- 5 files changed, 5 insertions(+), 24 deletions(-) diff --git a/quickstep/src/com/android/quickstep/recents/ui/viewmodel/TaskViewModel.kt b/quickstep/src/com/android/quickstep/recents/ui/viewmodel/TaskViewModel.kt index 4936e30202..961446fc98 100644 --- a/quickstep/src/com/android/quickstep/recents/ui/viewmodel/TaskViewModel.kt +++ b/quickstep/src/com/android/quickstep/recents/ui/viewmodel/TaskViewModel.kt @@ -68,8 +68,6 @@ class TaskViewModel( ) } - val tintAmount: Flow = recentsViewData.tintAmount - val state: Flow = combine(taskData, isLiveTile) { tasks, isLiveTile -> mapToTaskTile(tasks, isLiveTile) } .distinctUntilChanged() diff --git a/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewData.kt b/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewData.kt index 4cd7ef1ac3..a1f8454587 100644 --- a/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewData.kt +++ b/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewData.kt @@ -27,9 +27,6 @@ class RecentsViewData { // The settled set of visible taskIds that is updated after RecentsView scroll settles. val settledFullyVisibleTaskIds = MutableStateFlow(emptySet()) - // Color tint on foreground scrim - val tintAmount = MutableStateFlow(0f) - val thumbnailSplashProgress = MutableStateFlow(0f) // A list of taskIds that are associated with a RecentsAnimationController. */ diff --git a/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewModel.kt b/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewModel.kt index 25487b4869..73332fca8c 100644 --- a/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewModel.kt +++ b/quickstep/src/com/android/quickstep/recents/viewmodel/RecentsViewModel.kt @@ -42,10 +42,6 @@ class RecentsViewModel( recentsViewData.overlayEnabled.value = isOverlayEnabled } - fun setTintAmount(tintAmount: Float) { - recentsViewData.tintAmount.value = tintAmount - } - fun updateThumbnailSplashProgress(taskThumbnailSplashAlpha: Float) { recentsViewData.thumbnailSplashProgress.value = taskThumbnailSplashAlpha } diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 5ebb60352d..3d34d2ef73 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -241,8 +241,8 @@ import com.android.wm.shell.shared.desktopmode.DesktopModeTransitionSource; import kotlin.Unit; import kotlin.collections.CollectionsKt; - import kotlin.jvm.functions.Function0; + import kotlinx.coroutines.CoroutineScope; import java.util.ArrayList; @@ -6567,10 +6567,6 @@ public abstract class RecentsView< private void setColorTint(float tintAmount) { mColorTint = tintAmount; - if (enableRefactorTaskThumbnail()) { - mRecentsViewModel.setTintAmount(tintAmount); - } - for (TaskView taskView : getTaskViews()) { taskView.setColorTint(mColorTint, mTintingColor); } diff --git a/quickstep/src/com/android/quickstep/views/TaskView.kt b/quickstep/src/com/android/quickstep/views/TaskView.kt index 062955ba9a..1720110f0a 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskView.kt @@ -33,6 +33,7 @@ import android.util.Log import android.view.Display import android.view.MotionEvent import android.view.View +import android.view.View.OnClickListener import android.view.ViewGroup import android.view.ViewStub import android.view.accessibility.AccessibilityNodeInfo @@ -98,8 +99,6 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch /** A task in the Recents view. */ @@ -742,18 +741,11 @@ constructor( // The TaskView lifecycle is starts the ViewModel during onBind, and cleans it in // onRecycle. So it should be initialized at this point. TaskView Lifecycle: // `bind` -> `onBind` -> onAttachedToWindow() -> onDetachFromWindow -> onRecycle - coroutineJobs += - viewModel!!.tintAmount.onEach(::updateTintAmount).launchIn(coroutineScope) - coroutineJobs += coroutineScope.launch { viewModel!!.state.collectLatest(::updateTaskViewState) } } } - private fun updateTintAmount(amount: Float) { - taskContainers.forEach { it.updateTintAmount(amount) } - } - private fun updateTaskViewState(state: TaskTileUiState) { sysUiStatusNavFlags = state.sysUiStatusNavFlags @@ -1531,7 +1523,9 @@ constructor( /** Set a color tint on the snapshot and supporting views. */ open fun setColorTint(amount: Float, tintColor: Int) { taskContainers.forEach { - if (!enableRefactorTaskThumbnail()) { + if (enableRefactorTaskThumbnail()) { + it.updateTintAmount(amount) + } else { it.thumbnailViewDeprecated.dimAlpha = amount } it.iconView.setIconColorTint(tintColor, amount)