• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.modes.ui.mapper
18 
19 import android.content.res.Resources
20 import android.icu.text.MessageFormat
21 import android.widget.Button
22 import com.android.systemui.qs.tiles.base.shared.model.QSTileConfig
23 import com.android.systemui.qs.tiles.base.shared.model.QSTileState
24 import com.android.systemui.qs.tiles.base.ui.model.QSTileDataToStateMapper
25 import com.android.systemui.qs.tiles.impl.modes.domain.model.ModesTileModel
26 import com.android.systemui.res.R
27 import com.android.systemui.shade.ShadeDisplayAware
28 import java.util.Locale
29 import javax.inject.Inject
30 
31 class ModesTileMapper
32 @Inject
33 constructor(@ShadeDisplayAware private val resources: Resources, val theme: Resources.Theme) :
34     QSTileDataToStateMapper<ModesTileModel> {
mapnull35     override fun map(config: QSTileConfig, data: ModesTileModel): QSTileState =
36         QSTileState.build(resources, theme, config.uiConfig) {
37             icon = data.icon
38             activationState =
39                 if (data.isActivated) {
40                     QSTileState.ActivationState.ACTIVE
41                 } else {
42                     QSTileState.ActivationState.INACTIVE
43                 }
44             secondaryLabel = getModesStatus(data, resources)
45             contentDescription = "$label. $secondaryLabel"
46             supportedActions =
47                 setOf(
48                     QSTileState.UserAction.CLICK,
49                     QSTileState.UserAction.LONG_CLICK,
50                     QSTileState.UserAction.TOGGLE_CLICK,
51                 )
52             sideViewIcon = QSTileState.SideViewIcon.Chevron
53             expandedAccessibilityClass = Button::class
54         }
55 
getModesStatusnull56     private fun getModesStatus(data: ModesTileModel, resources: Resources): String {
57         val msgFormat =
58             MessageFormat(resources.getString(R.string.zen_mode_active_modes), Locale.getDefault())
59         val count = data.activeModes.count()
60         val args: MutableMap<String, Any> = HashMap()
61         args["count"] = count
62         if (count >= 1) {
63             args["mode"] = data.activeModes[0]
64         }
65         return msgFormat.format(args)
66     }
67 }
68