• 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.panels.ui.viewmodel
18 
19 import androidx.compose.runtime.getValue
20 import com.android.systemui.lifecycle.ExclusiveActivatable
21 import com.android.systemui.lifecycle.Hydrator
22 import com.android.systemui.qs.panels.domain.interactor.GridLayoutTypeInteractor
23 import com.android.systemui.qs.panels.shared.model.GridLayoutType
24 import com.android.systemui.qs.panels.ui.compose.GridLayout
25 import com.android.systemui.qs.pipeline.domain.interactor.CurrentTilesInteractor
26 import dagger.assisted.AssistedFactory
27 import dagger.assisted.AssistedInject
28 import javax.inject.Named
29 import kotlinx.coroutines.flow.map
30 
31 class TileGridViewModel
32 @AssistedInject
33 constructor(
34     gridLayoutTypeInteractor: GridLayoutTypeInteractor,
35     gridLayoutMap: Map<GridLayoutType, @JvmSuppressWildcards GridLayout>,
36     tilesInteractor: CurrentTilesInteractor,
37     @Named("Default") defaultGridLayout: GridLayout,
38 ) : ExclusiveActivatable() {
39 
40     private val hydrator = Hydrator("TileGridViewModel")
41 
42     val gridLayout by
43         hydrator.hydratedStateOf(
44             traceName = "gridLayout",
<lambda>null45             source = gridLayoutTypeInteractor.layout.map { gridLayoutMap[it] ?: defaultGridLayout },
46             initialValue = defaultGridLayout,
47         )
48 
49     private val tileModels by
50         hydrator.hydratedStateOf(traceName = "tileModels", source = tilesInteractor.currentTiles)
51 
52     val tileViewModels: List<TileViewModel>
<lambda>null53         get() = tileModels.map { TileViewModel(it.tile, it.spec) }
54 
onActivatednull55     override suspend fun onActivated(): Nothing {
56         hydrator.activate()
57     }
58 
59     @AssistedFactory
60     interface Factory {
createnull61         fun create(): TileGridViewModel
62     }
63 }
64