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.mapper 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.qs.tiles.base.shared.model.QSTileConfig 25 import com.android.systemui.qs.tiles.base.shared.model.QSTileState 26 import com.android.systemui.qs.tiles.base.ui.model.QSTileDataToStateMapper 27 import com.android.systemui.qs.tiles.impl.work.domain.model.WorkModeTileModel 28 import com.android.systemui.res.R 29 import com.android.systemui.shade.ShadeDisplayAware 30 import javax.inject.Inject 31 32 /** Maps [WorkModeTileModel] to [QSTileState]. */ 33 class WorkModeTileMapper 34 @Inject 35 constructor( 36 @ShadeDisplayAware 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 val iconRes = com.android.internal.R.drawable.stat_sys_managed_profile_status 45 icon = Icon.Loaded(resources.getDrawable(iconRes, theme), null, iconRes) 46 47 when (data) { 48 is WorkModeTileModel.HasActiveProfile -> { 49 if (data.isEnabled) { 50 activationState = QSTileState.ActivationState.ACTIVE 51 secondaryLabel = "" 52 } else { 53 activationState = QSTileState.ActivationState.INACTIVE 54 secondaryLabel = 55 resources.getString(R.string.quick_settings_work_mode_paused_state) 56 } 57 supportedActions = 58 setOf(QSTileState.UserAction.CLICK, QSTileState.UserAction.LONG_CLICK) 59 } 60 is WorkModeTileModel.NoActiveProfile -> { 61 activationState = QSTileState.ActivationState.UNAVAILABLE 62 secondaryLabel = 63 resources.getStringArray(R.array.tile_states_work)[Tile.STATE_UNAVAILABLE] 64 supportedActions = setOf() 65 } 66 } 67 68 sideViewIcon = QSTileState.SideViewIcon.None 69 } 70 getTileLabelnull71 private fun getTileLabel(): CharSequence? { 72 return devicePolicyManager.resources.getString(QS_WORK_PROFILE_LABEL) { 73 resources.getString(R.string.quick_settings_work_mode_label) 74 } 75 } 76 } 77