Add a ui state for the app timer toast and add a mapper function for it

Bug: 405359383
Flag: com.android.launcher3.enable_refactor_digital_wellbeing_toast
Test: Unit test for mapper
Change-Id: I35271ff33c8610d79674438fb18a3d851eb3d2d3
This commit is contained in:
Shamali P
2025-04-15 16:20:53 +00:00
committed by Shamali Patwa
parent 05e4134b73
commit 1ce7abb6fb
3 changed files with 183 additions and 1 deletions

View File

@@ -18,7 +18,10 @@ package com.android.quickstep.recents.ui.mapper
import android.view.View.OnClickListener
import com.android.launcher3.Flags.enableDesktopExplodedView
import com.android.launcher3.R
import com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT
import com.android.quickstep.recents.ui.viewmodel.TaskData
import com.android.quickstep.task.apptimer.TaskAppTimerUiState
import com.android.quickstep.task.thumbnail.TaskHeaderUiState
import com.android.quickstep.task.thumbnail.TaskThumbnailUiState
import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.BackgroundOnly
@@ -105,4 +108,37 @@ object TaskUiStateMapper {
taskData.icon != null &&
taskData.titleDescription != null &&
clickCloseListener != null
/**
* Converts a [TaskData] object into a [TaskAppTimerUiState] for displaying an app timer toast
*
* @property taskData The [TaskData] to convert. Can be null or a specific sub-class.
* @property stagePosition the position of this task when shown as a group
* @return a [TaskAppTimerUiState] representing state for the information displayed in the app
* timer toast.
*/
fun toTaskAppTimerUiState(
canShowAppTimer: Boolean,
stagePosition: Int,
taskData: TaskData?,
): TaskAppTimerUiState =
when {
taskData !is TaskData.Data -> TaskAppTimerUiState.Uninitialized
!canShowAppTimer || taskData.remainingAppTimerDuration == null ->
TaskAppTimerUiState.NoTimer(taskDescription = taskData.titleDescription)
else ->
TaskAppTimerUiState.Timer(
taskDescription = taskData.titleDescription,
timeRemaining = taskData.remainingAppTimerDuration,
taskPackageName = taskData.packageName,
accessibilityActionId =
if (stagePosition == STAGE_POSITION_BOTTOM_OR_RIGHT) {
R.id.action_digital_wellbeing_bottom_right
} else {
R.id.action_digital_wellbeing_top_left
},
)
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.quickstep.task.apptimer
import androidx.annotation.IdRes
import java.time.Duration
/**
* UI state of the digital wellbeing app timer toast
*
* @property taskDescription description of the task for which the timer is being displayed.
*/
sealed class TaskAppTimerUiState(open val taskDescription: String?) {
/** Timer information not available in UI. */
data object Uninitialized : TaskAppTimerUiState(null)
/** No timer information to display */
data class NoTimer(override val taskDescription: String?) :
TaskAppTimerUiState(taskDescription)
/**
* Represents the UI state necessary to show an app timer on a task
*
* @property timeRemaining time remaining on the app timer for the application.
* @property taskDescription description of the task for which the timer is being displayed.
* @property taskPackageName package name for of the top component for the task's app.
* @property accessibilityActionId action id to use for tap like accessibility actions on this
* timer.
*/
data class Timer(
val timeRemaining: Duration,
override val taskDescription: String?,
val taskPackageName: String,
@IdRes val accessibilityActionId: Int,
) : TaskAppTimerUiState(taskDescription)
}