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.qs.tiles.base.interactor.QSTileDataToStateMapper 23 import com.android.systemui.qs.tiles.viewmodel.QSTileConfig 24 import com.android.systemui.qs.tiles.viewmodel.QSTileState 25 import com.android.systemui.res.R 26 import com.android.systemui.screenrecord.data.model.ScreenRecordModel 27 import com.android.systemui.shade.ShadeDisplayAware 28 import javax.inject.Inject 29 30 /** Maps [ScreenRecordModel] to [QSTileState]. */ 31 class ScreenRecordTileMapper 32 @Inject 33 constructor( 34 @ShadeDisplayAware 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 sideViewIcon = QSTileState.SideViewIcon.None 47 secondaryLabel = resources.getString(R.string.quick_settings_screen_record_stop) 48 } 49 is ScreenRecordModel.Starting -> { 50 activationState = QSTileState.ActivationState.ACTIVE 51 iconRes = R.drawable.qs_screen_record_icon_on 52 val countDown = data.countdownSeconds 53 sideViewIcon = QSTileState.SideViewIcon.None 54 secondaryLabel = String.format("%d...", countDown) 55 } 56 is ScreenRecordModel.DoingNothing -> { 57 activationState = QSTileState.ActivationState.INACTIVE 58 iconRes = R.drawable.qs_screen_record_icon_off 59 sideViewIcon = QSTileState.SideViewIcon.Chevron // tapping will open dialog 60 secondaryLabel = 61 resources.getString(R.string.quick_settings_screen_record_start) 62 } 63 } 64 icon = Icon.Loaded(resources.getDrawable(iconRes!!, theme), null) 65 66 contentDescription = 67 if (TextUtils.isEmpty(secondaryLabel)) label 68 else TextUtils.concat(label, ", ", secondaryLabel) 69 } 70 } 71