Merge changes from topic "dwb-refactor-domain" into main

* changes:
  Move app timer in the taskContentView behind a refactor flag.
  Change task content view to be a constraint layout.
  Extract out timer text specific utility from the dwb view
  Add a ui state for the app timer toast and add a mapper function for it
This commit is contained in:
Shamali Patwa
2025-04-23 19:49:38 -07:00
committed by Android (Google) Code Review
16 changed files with 917 additions and 63 deletions

View File

@@ -26,7 +26,11 @@ import android.view.Surface
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.launcher3.Flags
import com.android.launcher3.R
import com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT
import com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT
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.LiveTile
@@ -189,6 +193,96 @@ class TaskUiStateMapperTest {
assertThat(result).isEqualTo(expected)
}
@Test
fun toTaskAppTimer_nullTaskData_returnsUninitialized() {
val result =
TaskUiStateMapper.toTaskAppTimerUiState(
canShowAppTimer = true,
stagePosition = STAGE_POSITION_DEFAULT,
taskData = null,
)
val expected = TaskAppTimerUiState.Uninitialized
assertThat(result).isEqualTo(expected)
}
@Test
fun toTaskAppTimer_noTaskData_returnsUninitialized() {
val result =
TaskUiStateMapper.toTaskAppTimerUiState(
canShowAppTimer = true,
stagePosition = STAGE_POSITION_DEFAULT,
taskData = TaskData.NoData(TASK_ID),
)
val expected = TaskAppTimerUiState.Uninitialized
assertThat(result).isEqualTo(expected)
}
@Test
fun toTaskAppTimer_canShowAppTimerFalse_returnsNoTimer() {
val result =
TaskUiStateMapper.toTaskAppTimerUiState(
canShowAppTimer = false,
stagePosition = STAGE_POSITION_DEFAULT,
taskData = TASK_DATA,
)
val expected = TaskAppTimerUiState.NoTimer(taskDescription = TASK_TITLE_DESCRIPTION)
assertThat(result).isEqualTo(expected)
}
@Test
fun toTaskAppTimer_timerNullAndCanShow_returnsNoTimer() {
val result =
TaskUiStateMapper.toTaskAppTimerUiState(
canShowAppTimer = false,
stagePosition = STAGE_POSITION_DEFAULT,
taskData = TASK_DATA.copy(remainingAppTimerDuration = null),
)
val expected = TaskAppTimerUiState.NoTimer(taskDescription = TASK_TITLE_DESCRIPTION)
assertThat(result).isEqualTo(expected)
}
@Test
fun toTaskAppTimer_timerPresentAndCanShow_returnsTimer() {
val result =
TaskUiStateMapper.toTaskAppTimerUiState(
canShowAppTimer = true,
stagePosition = STAGE_POSITION_DEFAULT,
taskData = TASK_DATA.copy(remainingAppTimerDuration = TASK_APP_TIMER_DURATION),
)
val expected =
TaskAppTimerUiState.Timer(
timeRemaining = TASK_APP_TIMER_DURATION,
taskDescription = TASK_DATA.titleDescription,
taskPackageName = TASK_DATA.packageName,
accessibilityActionId = R.id.action_digital_wellbeing_top_left,
)
assertThat(result).isEqualTo(expected)
}
@Test
fun toTaskAppTimer_stagePositionBottomOrRight_returnsTimerWithCorrectActionId() {
val result =
TaskUiStateMapper.toTaskAppTimerUiState(
canShowAppTimer = true,
stagePosition = STAGE_POSITION_BOTTOM_OR_RIGHT,
taskData = TASK_DATA.copy(remainingAppTimerDuration = TASK_APP_TIMER_DURATION),
)
val expected =
TaskAppTimerUiState.Timer(
timeRemaining = TASK_APP_TIMER_DURATION,
taskDescription = TASK_DATA.titleDescription,
taskPackageName = TASK_DATA.packageName,
accessibilityActionId = R.id.action_digital_wellbeing_bottom_right,
)
assertThat(result).isEqualTo(expected)
}
private companion object {
const val TASK_TITLE_DESCRIPTION = "Title Description 1"
var TASK_ID = 1
@@ -198,6 +292,8 @@ class TaskUiStateMapperTest {
val TASK_THUMBNAIL_DATA =
ThumbnailData(thumbnail = TASK_THUMBNAIL, rotation = Surface.ROTATION_0)
val TASK_BACKGROUND_COLOR = Color.rgb(1, 2, 3)
val TASK_APP_TIMER_DURATION: Duration = Duration.ofMillis(30)
val STAGE_POSITION_DEFAULT = STAGE_POSITION_TOP_OR_LEFT
val TASK_DATA =
TaskData.Data(
TASK_ID,
@@ -209,7 +305,7 @@ class TaskUiStateMapperTest {
backgroundColor = TASK_BACKGROUND_COLOR,
isLocked = false,
isLiveTile = false,
remainingAppTimerDuration = Duration.ofMillis(30),
remainingAppTimerDuration = TASK_APP_TIMER_DURATION,
)
}
}

View File

@@ -0,0 +1,87 @@
/*
* 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.test.ext.junit.runners.AndroidJUnit4
import com.android.launcher3.R
import com.android.launcher3.util.SandboxApplication
import com.google.common.truth.Truth.assertThat
import java.time.Duration
import java.util.Locale
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class DurationFormatterTest {
@get:Rule val context = SandboxApplication()
private var systemLocale: Locale? = null
@Before
fun setup() {
systemLocale = Locale.getDefault()
val testLocale = Locale("en", "us")
Locale.setDefault(testLocale)
}
@Test
fun getReadableDuration_hasHoursAndMinutes_returnsNarrowString() {
val result =
DurationFormatter.format(
context,
Duration.ofHours(12).plusMinutes(55),
durationLessThanOneMinuteStringId = R.string.shorter_duration_less_than_one_minute,
)
val expected = "12h 55m"
assertThat(result).isEqualTo(expected)
}
@Test
fun getReadableDuration_hasFullHours_returnsWideString() {
val result =
DurationFormatter.format(
context = context,
duration = Duration.ofHours(12),
durationLessThanOneMinuteStringId = R.string.shorter_duration_less_than_one_minute,
)
val expected = "12 hours"
assertThat(result).isEqualTo(expected)
}
@Test
fun getReadableDuration_hasFullMinutesNoHours_returnsWideString() {
val result =
DurationFormatter.format(
context = context,
duration = Duration.ofMinutes(50),
durationLessThanOneMinuteStringId = R.string.shorter_duration_less_than_one_minute,
)
val expected = "50 minutes"
assertThat(result).isEqualTo(expected)
}
@After
fun tearDown() {
Locale.setDefault(systemLocale)
}
}