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
This commit is contained in:
@@ -68,8 +68,6 @@ class TaskViewModel(
|
||||
)
|
||||
}
|
||||
|
||||
val tintAmount: Flow<Float> = recentsViewData.tintAmount
|
||||
|
||||
val state: Flow<TaskTileUiState> =
|
||||
combine(taskData, isLiveTile) { tasks, isLiveTile -> mapToTaskTile(tasks, isLiveTile) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
@@ -27,9 +27,6 @@ class RecentsViewData {
|
||||
// The settled set of visible taskIds that is updated after RecentsView scroll settles.
|
||||
val settledFullyVisibleTaskIds = MutableStateFlow(emptySet<Int>())
|
||||
|
||||
// Color tint on foreground scrim
|
||||
val tintAmount = MutableStateFlow(0f)
|
||||
|
||||
val thumbnailSplashProgress = MutableStateFlow(0f)
|
||||
|
||||
// A list of taskIds that are associated with a RecentsAnimationController. */
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user