1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.qs.tiles.impl.screenrecord.domain.ui 18 19 import android.content.res.Resources 20 import android.text.TextUtils 21 import com.android.systemui.common.shared.model.Icon 22 import com.android.systemui.dagger.qualifiers.Main 23 import com.android.systemui.qs.tiles.base.interactor.QSTileDataToStateMapper 24 import com.android.systemui.qs.tiles.viewmodel.QSTileConfig 25 import com.android.systemui.qs.tiles.viewmodel.QSTileState 26 import com.android.systemui.res.R 27 import com.android.systemui.screenrecord.data.model.ScreenRecordModel 28 import javax.inject.Inject 29 30 /** Maps [ScreenRecordModel] to [QSTileState]. */ 31 class ScreenRecordTileMapper 32 @Inject 33 constructor( 34 @Main private val resources: Resources, 35 private val theme: Resources.Theme, 36 ) : QSTileDataToStateMapper<ScreenRecordModel> { mapnull37 override fun map(config: QSTileConfig, data: ScreenRecordModel): QSTileState = 38 QSTileState.build(resources, theme, config.uiConfig) { 39 label = resources.getString(R.string.quick_settings_screen_record_label) 40 supportedActions = setOf(QSTileState.UserAction.CLICK) 41 42 when (data) { 43 is ScreenRecordModel.Recording -> { 44 activationState = QSTileState.ActivationState.ACTIVE 45 iconRes = R.drawable.qs_screen_record_icon_on 46 val loadedIcon = 47 Icon.Loaded( 48 resources.getDrawable(iconRes!!, theme), 49 contentDescription = null 50 ) 51 icon = { loadedIcon } 52 sideViewIcon = QSTileState.SideViewIcon.None 53 secondaryLabel = resources.getString(R.string.quick_settings_screen_record_stop) 54 } 55 is ScreenRecordModel.Starting -> { 56 activationState = QSTileState.ActivationState.ACTIVE 57 iconRes = R.drawable.qs_screen_record_icon_on 58 val loadedIcon = 59 Icon.Loaded( 60 resources.getDrawable(iconRes!!, theme), 61 contentDescription = null 62 ) 63 icon = { loadedIcon } 64 val countDown = Math.floorDiv(data.millisUntilStarted + 500, 1000) 65 sideViewIcon = QSTileState.SideViewIcon.None 66 secondaryLabel = String.format("%d...", countDown) 67 } 68 is ScreenRecordModel.DoingNothing -> { 69 activationState = QSTileState.ActivationState.INACTIVE 70 iconRes = R.drawable.qs_screen_record_icon_off 71 val loadedIcon = 72 Icon.Loaded( 73 resources.getDrawable(iconRes!!, theme), 74 contentDescription = null 75 ) 76 icon = { loadedIcon } 77 sideViewIcon = QSTileState.SideViewIcon.Chevron // tapping will open dialog 78 secondaryLabel = 79 resources.getString(R.string.quick_settings_screen_record_start) 80 } 81 } 82 contentDescription = 83 if (TextUtils.isEmpty(secondaryLabel)) label 84 else TextUtils.concat(label, ", ", secondaryLabel) 85 } 86 } 87