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.panels.domain.interactor
18 
19 import com.android.systemui.common.shared.model.ContentDescription
20 import com.android.systemui.common.shared.model.Icon
21 import com.android.systemui.common.shared.model.Text
22 import com.android.systemui.dagger.SysUISingleton
23 import com.android.systemui.qs.panels.data.repository.IconAndNameCustomRepository
24 import com.android.systemui.qs.panels.data.repository.StockTilesRepository
25 import com.android.systemui.qs.panels.domain.model.EditTilesModel
26 import com.android.systemui.qs.panels.shared.model.EditTileData
27 import com.android.systemui.qs.tiles.viewmodel.QSTileConfigProvider
28 import javax.inject.Inject
29 
30 @SysUISingleton
31 class EditTilesListInteractor
32 @Inject
33 constructor(
34     private val stockTilesRepository: StockTilesRepository,
35     private val qsTileConfigProvider: QSTileConfigProvider,
36     private val iconAndNameCustomRepository: IconAndNameCustomRepository,
37 ) {
38     /**
39      * Provides a list of the tiles to edit, with their UI information (icon, labels).
40      *
41      * The icons have the label as their content description.
42      */
getTilesToEditnull43     suspend fun getTilesToEdit(): EditTilesModel {
44         val stockTiles =
45             stockTilesRepository.stockTiles.map {
46                 if (qsTileConfigProvider.hasConfig(it.spec)) {
47                     val config = qsTileConfigProvider.getConfig(it.spec)
48                     EditTileData(
49                         it,
50                         Icon.Resource(
51                             config.uiConfig.iconRes,
52                             ContentDescription.Resource(config.uiConfig.labelRes)
53                         ),
54                         Text.Resource(config.uiConfig.labelRes),
55                         null,
56                     )
57                 } else {
58                     EditTileData(
59                         it,
60                         Icon.Resource(
61                             android.R.drawable.star_on,
62                             ContentDescription.Loaded(it.spec)
63                         ),
64                         Text.Loaded(it.spec),
65                         null
66                     )
67                 }
68             }
69         return EditTilesModel(stockTiles, iconAndNameCustomRepository.getCustomTileData())
70     }
71 }
72