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.work.ui 18 19 import android.app.admin.DevicePolicyManager 20 import android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_WORK_PROFILE_LABEL 21 import android.content.res.Resources 22 import android.service.quicksettings.Tile 23 import com.android.systemui.common.shared.model.Icon 24 import com.android.systemui.dagger.qualifiers.Main 25 import com.android.systemui.qs.tiles.base.interactor.QSTileDataToStateMapper 26 import com.android.systemui.qs.tiles.impl.work.domain.model.WorkModeTileModel 27 import com.android.systemui.qs.tiles.viewmodel.QSTileConfig 28 import com.android.systemui.qs.tiles.viewmodel.QSTileState 29 import com.android.systemui.res.R 30 import javax.inject.Inject 31 32 /** Maps [WorkModeTileModel] to [QSTileState]. */ 33 class WorkModeTileMapper 34 @Inject 35 constructor( 36 @Main private val resources: Resources, 37 private val theme: Resources.Theme, 38 private val devicePolicyManager: DevicePolicyManager, 39 ) : QSTileDataToStateMapper<WorkModeTileModel> { mapnull40 override fun map(config: QSTileConfig, data: WorkModeTileModel): QSTileState = 41 QSTileState.build(resources, theme, config.uiConfig) { 42 label = getTileLabel()!! 43 contentDescription = label 44 iconRes = com.android.internal.R.drawable.stat_sys_managed_profile_status 45 icon = { 46 Icon.Loaded(resources.getDrawable(iconRes!!, theme), contentDescription = null) 47 } 48 49 when (data) { 50 is WorkModeTileModel.HasActiveProfile -> { 51 if (data.isEnabled) { 52 activationState = QSTileState.ActivationState.ACTIVE 53 secondaryLabel = "" 54 } else { 55 activationState = QSTileState.ActivationState.INACTIVE 56 secondaryLabel = 57 resources.getString(R.string.quick_settings_work_mode_paused_state) 58 } 59 supportedActions = 60 setOf(QSTileState.UserAction.CLICK, QSTileState.UserAction.LONG_CLICK) 61 } 62 is WorkModeTileModel.NoActiveProfile -> { 63 activationState = QSTileState.ActivationState.UNAVAILABLE 64 secondaryLabel = 65 resources.getStringArray(R.array.tile_states_work)[Tile.STATE_UNAVAILABLE] 66 supportedActions = setOf() 67 } 68 } 69 70 sideViewIcon = QSTileState.SideViewIcon.None 71 } 72 getTileLabelnull73 private fun getTileLabel(): CharSequence? { 74 return devicePolicyManager.resources.getString(QS_WORK_PROFILE_LABEL) { 75 resources.getString(R.string.quick_settings_work_mode_label) 76 } 77 } 78 } 79