• 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.ui.viewmodel
18 
19 import androidx.compose.runtime.getValue
20 import com.android.systemui.brightness.ui.viewmodel.BrightnessSliderViewModel
21 import com.android.systemui.lifecycle.ExclusiveActivatable
22 import com.android.systemui.lifecycle.Hydrator
23 import com.android.systemui.media.controls.domain.pipeline.interactor.MediaCarouselInteractor
24 import com.android.systemui.media.controls.ui.controller.MediaCarouselController
25 import com.android.systemui.media.controls.ui.view.MediaHost
26 import com.android.systemui.media.dagger.MediaModule
27 import com.android.systemui.qs.panels.ui.viewmodel.DetailsViewModel
28 import com.android.systemui.qs.panels.ui.viewmodel.EditModeViewModel
29 import com.android.systemui.qs.panels.ui.viewmodel.TileGridViewModel
30 import com.android.systemui.qs.panels.ui.viewmodel.toolbar.ToolbarViewModel
31 import com.android.systemui.shade.domain.interactor.ShadeModeInteractor
32 import com.android.systemui.shade.ui.viewmodel.ShadeHeaderViewModel
33 import dagger.assisted.Assisted
34 import dagger.assisted.AssistedFactory
35 import dagger.assisted.AssistedInject
36 import javax.inject.Named
37 import kotlinx.coroutines.awaitCancellation
38 import kotlinx.coroutines.coroutineScope
39 import kotlinx.coroutines.flow.map
40 import kotlinx.coroutines.launch
41 
42 class QuickSettingsContainerViewModel
43 @AssistedInject
44 constructor(
45     brightnessSliderViewModelFactory: BrightnessSliderViewModel.Factory,
46     shadeHeaderViewModelFactory: ShadeHeaderViewModel.Factory,
47     tileGridViewModelFactory: TileGridViewModel.Factory,
48     @Assisted supportsBrightnessMirroring: Boolean,
49     @Assisted private val expansion: Float?,
50     val editModeViewModel: EditModeViewModel,
51     val detailsViewModel: DetailsViewModel,
52     toolbarViewModelFactory: ToolbarViewModel.Factory,
53     shadeModeInteractor: ShadeModeInteractor,
54     mediaCarouselInteractor: MediaCarouselInteractor,
55     val mediaCarouselController: MediaCarouselController,
56     @Named(MediaModule.QS_PANEL) val mediaHost: MediaHost,
57 ) : ExclusiveActivatable() {
58 
59     private val hydrator = Hydrator("QuickSettingsContainerViewModel.hydrator")
60 
61     val brightnessSliderViewModel =
62         brightnessSliderViewModelFactory.create(supportsBrightnessMirroring)
63 
64     val toolbarViewModel = toolbarViewModelFactory.create()
65 
66     val shadeHeaderViewModel = shadeHeaderViewModelFactory.create()
67 
68     val tileGridViewModel = tileGridViewModelFactory.create()
69 
70     val showHeader: Boolean by
71         hydrator.hydratedStateOf(
72             traceName = "showHeader",
73             initialValue = !shadeModeInteractor.isShadeLayoutWide.value,
<lambda>null74             source = shadeModeInteractor.isShadeLayoutWide.map { !it },
75         )
76 
77     val showMedia: Boolean by
78         hydrator.hydratedStateOf(
79             traceName = "showMedia",
80             source = mediaCarouselInteractor.hasAnyMediaOrRecommendation,
81         )
82 
onActivatednull83     override suspend fun onActivated(): Nothing {
84         coroutineScope {
85             expansion?.let { mediaHost.expansion = it }
86             launch { hydrator.activate() }
87             launch { brightnessSliderViewModel.activate() }
88             launch { toolbarViewModel.activate() }
89             launch { shadeHeaderViewModel.activate() }
90             launch { tileGridViewModel.activate() }
91             awaitCancellation()
92         }
93     }
94 
95     @AssistedFactory
96     interface Factory {
createnull97         fun create(
98             supportsBrightnessMirroring: Boolean,
99             expansion: Float? = null,
100         ): QuickSettingsContainerViewModel
101     }
102 }
103