1 /*
2  * Copyright (C) 2023 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.volume.panel.dagger
18 
19 import com.android.systemui.volume.dagger.UiEventLoggerStartableModule
20 import com.android.systemui.volume.panel.component.anc.AncModule
21 import com.android.systemui.volume.panel.component.bottombar.BottomBarModule
22 import com.android.systemui.volume.panel.component.captioning.CaptioningModule
23 import com.android.systemui.volume.panel.component.mediaoutput.MediaOutputModule
24 import com.android.systemui.volume.panel.component.spatialaudio.SpatialAudioModule
25 import com.android.systemui.volume.panel.component.volume.VolumeSlidersModule
26 import com.android.systemui.volume.panel.dagger.factory.VolumePanelComponentFactory
27 import com.android.systemui.volume.panel.dagger.scope.VolumePanelScope
28 import com.android.systemui.volume.panel.domain.DomainModule
29 import com.android.systemui.volume.panel.domain.VolumePanelStartable
30 import com.android.systemui.volume.panel.domain.interactor.ComponentsInteractor
31 import com.android.systemui.volume.panel.ui.UiModule
32 import com.android.systemui.volume.panel.ui.composable.ComponentsFactory
33 import com.android.systemui.volume.panel.ui.layout.ComponentsLayoutManager
34 import com.android.systemui.volume.panel.ui.viewmodel.VolumePanelViewModel
35 import dagger.BindsInstance
36 import dagger.Subcomponent
37 import kotlinx.coroutines.CoroutineScope
38 
39 /**
40  * Core Volume Panel dagger component. It's managed by [VolumePanelViewModel] and lives alongside
41  * it.
42  */
43 @VolumePanelScope
44 @Subcomponent(
45     modules =
46         [
47             // Volume Panel infra modules
48             DefaultMultibindsModule::class,
49             DomainModule::class,
50             UiModule::class,
51             UiEventLoggerStartableModule::class,
52             // Components modules
53             BottomBarModule::class,
54             AncModule::class,
55             SpatialAudioModule::class,
56             VolumeSlidersModule::class,
57             CaptioningModule::class,
58             MediaOutputModule::class,
59         ]
60 )
61 interface VolumePanelComponent {
62 
63     /**
64      * Provides a coroutine scope to use inside [VolumePanelScope].
65      * [com.android.systemui.volume.panel.ui.viewmodel.VolumePanelViewModel] manages the lifecycle
66      * of this scope. It's cancelled when the View Model is destroyed. This helps to free occupied
67      * resources when volume panel is not shown.
68      */
coroutineScopenull69     fun coroutineScope(): CoroutineScope
70 
71     fun componentsInteractor(): ComponentsInteractor
72 
73     fun componentsFactory(): ComponentsFactory
74 
75     fun componentsLayoutManager(): ComponentsLayoutManager
76 
77     fun volumePanelStartables(): Set<VolumePanelStartable>
78 
79     @Subcomponent.Factory
80     interface Factory : VolumePanelComponentFactory {
81 
82         override fun create(
83             @BindsInstance viewModel: VolumePanelViewModel,
84             @BindsInstance scope: CoroutineScope,
85         ): VolumePanelComponent
86     }
87 }
88