• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.statusbar.notification.dagger
18 
19 import android.annotation.StringRes
20 import android.provider.Settings
21 import com.android.systemui.R
22 import com.android.systemui.dagger.SysUISingleton
23 import com.android.systemui.statusbar.notification.collection.render.NodeController
24 import com.android.systemui.statusbar.notification.collection.render.SectionHeaderController
25 import com.android.systemui.statusbar.notification.collection.render.SectionHeaderNodeControllerImpl
26 import dagger.Binds
27 import dagger.BindsInstance
28 import dagger.Module
29 import dagger.Provides
30 import dagger.Subcomponent
31 import javax.inject.Provider
32 import javax.inject.Qualifier
33 import javax.inject.Scope
34 
35 @Module(subcomponents = [SectionHeaderControllerSubcomponent::class])
36 object NotificationSectionHeadersModule {
37 
38     @Provides
39     @IncomingHeader
40     @SysUISingleton
providesIncomingHeaderSubcomponentnull41     @JvmStatic fun providesIncomingHeaderSubcomponent(
42         builder: Provider<SectionHeaderControllerSubcomponent.Builder>
43     ) = builder.get()
44             .nodeLabel("incoming header")
45             .headerText(R.string.notification_section_header_incoming)
46             .clickIntentAction(Settings.ACTION_NOTIFICATION_SETTINGS)
47             .build()
48 
49     @Provides
50     @AlertingHeader
51     @SysUISingleton
52     @JvmStatic fun providesAlertingHeaderSubcomponent(
53         builder: Provider<SectionHeaderControllerSubcomponent.Builder>
54     ) = builder.get()
55             .nodeLabel("alerting header")
56             .headerText(R.string.notification_section_header_alerting)
57             .clickIntentAction(Settings.ACTION_NOTIFICATION_SETTINGS)
58             .build()
59 
60     @Provides
61     @PeopleHeader
62     @SysUISingleton
63     @JvmStatic fun providesPeopleHeaderSubcomponent(
64         builder: Provider<SectionHeaderControllerSubcomponent.Builder>
65     ) = builder.get()
66             .nodeLabel("people header")
67             .headerText(R.string.notification_section_header_conversations)
68             .clickIntentAction(Settings.ACTION_CONVERSATION_SETTINGS)
69             .build()
70 
71     @Provides
72     @SilentHeader
73     @SysUISingleton
74     @JvmStatic fun providesSilentHeaderSubcomponent(
75         builder: Provider<SectionHeaderControllerSubcomponent.Builder>
76     ) = builder.get()
77             .nodeLabel("silent header")
78             .headerText(R.string.notification_section_header_gentle)
79             .clickIntentAction(Settings.ACTION_NOTIFICATION_SETTINGS)
80             .build()
81 
82     @Provides
83     @SilentHeader
84     @JvmStatic fun providesSilentHeaderNodeController(
85         @SilentHeader subcomponent: SectionHeaderControllerSubcomponent
86     ) = subcomponent.nodeController
87 
88     @Provides
89     @SilentHeader
90     @JvmStatic fun providesSilentHeaderController(
91         @SilentHeader subcomponent: SectionHeaderControllerSubcomponent
92     ) = subcomponent.headerController
93 
94     @Provides
95     @AlertingHeader
96     @JvmStatic fun providesAlertingHeaderNodeController(
97         @AlertingHeader subcomponent: SectionHeaderControllerSubcomponent
98     ) = subcomponent.nodeController
99 
100     @Provides
101     @AlertingHeader
102     @JvmStatic fun providesAlertingHeaderController(
103         @AlertingHeader subcomponent: SectionHeaderControllerSubcomponent
104     ) = subcomponent.headerController
105 
106     @Provides
107     @PeopleHeader
108     @JvmStatic fun providesPeopleHeaderNodeController(
109         @PeopleHeader subcomponent: SectionHeaderControllerSubcomponent
110     ) = subcomponent.nodeController
111 
112     @Provides
113     @PeopleHeader
114     @JvmStatic fun providesPeopleHeaderController(
115         @PeopleHeader subcomponent: SectionHeaderControllerSubcomponent
116     ) = subcomponent.headerController
117 
118     @Provides
119     @IncomingHeader
120     @JvmStatic fun providesIncomingHeaderNodeController(
121         @IncomingHeader subcomponent: SectionHeaderControllerSubcomponent
122     ) = subcomponent.nodeController
123 
124     @Provides
125     @IncomingHeader
126     @JvmStatic fun providesIncomingHeaderController(
127         @IncomingHeader subcomponent: SectionHeaderControllerSubcomponent
128     ) = subcomponent.headerController
129 }
130 
131 @Subcomponent(modules = [ SectionHeaderBindingModule::class ])
132 @SectionHeaderScope
133 interface SectionHeaderControllerSubcomponent {
134 
135     val nodeController: NodeController
136     val headerController: SectionHeaderController
137 
138     @Subcomponent.Builder
139     interface Builder {
140         fun build(): SectionHeaderControllerSubcomponent
141         @BindsInstance fun nodeLabel(@NodeLabel nodeLabel: String): Builder
142         @BindsInstance fun headerText(@HeaderText @StringRes headerText: Int): Builder
143         @BindsInstance fun clickIntentAction(@HeaderClickAction clickIntentAction: String): Builder
144     }
145 }
146 
147 @Module
148 private abstract class SectionHeaderBindingModule {
bindsNodeControllernull149     @Binds abstract fun bindsNodeController(impl: SectionHeaderNodeControllerImpl): NodeController
150     @Binds abstract fun bindsSectionHeaderController(
151         impl: SectionHeaderNodeControllerImpl
152     ): SectionHeaderController
153 }
154 
155 @Qualifier
156 @Retention(AnnotationRetention.BINARY)
157 annotation class HeaderText
158 
159 @Qualifier
160 @Retention(AnnotationRetention.BINARY)
161 annotation class IncomingHeader
162 
163 @Qualifier
164 @Retention(AnnotationRetention.BINARY)
165 annotation class AlertingHeader
166 
167 @Qualifier
168 @Retention(AnnotationRetention.BINARY)
169 annotation class SilentHeader
170 
171 @Qualifier
172 @Retention(AnnotationRetention.BINARY)
173 annotation class PeopleHeader
174 
175 @Qualifier
176 @Retention(AnnotationRetention.BINARY)
177 annotation class NodeLabel
178 
179 @Qualifier
180 @Retention(AnnotationRetention.BINARY)
181 annotation class HeaderClickAction
182 
183 @Scope
184 @Retention(AnnotationRetention.BINARY)
185 annotation class SectionHeaderScope