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.res.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 @NewsHeader 84 @SysUISingleton 85 @JvmStatic fun providesNewsHeaderSubcomponent( 86 builder: Provider<SectionHeaderControllerSubcomponent.Builder> 87 ) = builder.get() 88 .nodeLabel("news header") 89 .headerText(com.android.internal.R.string.news_notification_channel_label) 90 .clickIntentAction(Settings.ACTION_NOTIFICATION_SETTINGS) 91 .build() 92 93 @Provides 94 @SocialHeader 95 @SysUISingleton 96 @JvmStatic fun providesSocialHeaderSubcomponent( 97 builder: Provider<SectionHeaderControllerSubcomponent.Builder> 98 ) = builder.get() 99 .nodeLabel("social header") 100 .headerText(com.android.internal.R.string.social_notification_channel_label) 101 .clickIntentAction(Settings.ACTION_NOTIFICATION_SETTINGS) 102 .build() 103 104 @Provides 105 @RecsHeader 106 @SysUISingleton 107 @JvmStatic fun providesRecsHeaderSubcomponent( 108 builder: Provider<SectionHeaderControllerSubcomponent.Builder> 109 ) = builder.get() 110 .nodeLabel("recs header") 111 .headerText(com.android.internal.R.string.recs_notification_channel_label) 112 .clickIntentAction(Settings.ACTION_NOTIFICATION_SETTINGS) 113 .build() 114 115 @Provides 116 @PromoHeader 117 @SysUISingleton 118 @JvmStatic fun providesPromoHeaderSubcomponent( 119 builder: Provider<SectionHeaderControllerSubcomponent.Builder> 120 ) = builder.get() 121 .nodeLabel("promo header") 122 .headerText(com.android.internal.R.string.promotional_notification_channel_label) 123 .clickIntentAction(Settings.ACTION_NOTIFICATION_SETTINGS) 124 .build() 125 126 @Provides 127 @SilentHeader 128 @JvmStatic fun providesSilentHeaderNodeController( 129 @SilentHeader subcomponent: SectionHeaderControllerSubcomponent 130 ) = subcomponent.nodeController 131 132 @Provides 133 @SilentHeader 134 @JvmStatic fun providesSilentHeaderController( 135 @SilentHeader subcomponent: SectionHeaderControllerSubcomponent 136 ) = subcomponent.headerController 137 138 @Provides 139 @AlertingHeader 140 @JvmStatic fun providesAlertingHeaderNodeController( 141 @AlertingHeader subcomponent: SectionHeaderControllerSubcomponent 142 ) = subcomponent.nodeController 143 144 @Provides 145 @AlertingHeader 146 @JvmStatic fun providesAlertingHeaderController( 147 @AlertingHeader subcomponent: SectionHeaderControllerSubcomponent 148 ) = subcomponent.headerController 149 150 @Provides 151 @PeopleHeader 152 @JvmStatic fun providesPeopleHeaderNodeController( 153 @PeopleHeader subcomponent: SectionHeaderControllerSubcomponent 154 ) = subcomponent.nodeController 155 156 @Provides 157 @PeopleHeader 158 @JvmStatic fun providesPeopleHeaderController( 159 @PeopleHeader subcomponent: SectionHeaderControllerSubcomponent 160 ) = subcomponent.headerController 161 162 @Provides 163 @IncomingHeader 164 @JvmStatic fun providesIncomingHeaderNodeController( 165 @IncomingHeader subcomponent: SectionHeaderControllerSubcomponent 166 ) = subcomponent.nodeController 167 168 @Provides 169 @IncomingHeader 170 @JvmStatic fun providesIncomingHeaderController( 171 @IncomingHeader subcomponent: SectionHeaderControllerSubcomponent 172 ) = subcomponent.headerController 173 174 @Provides 175 @NewsHeader 176 @JvmStatic fun providesNewsHeaderNodeController( 177 @NewsHeader subcomponent: SectionHeaderControllerSubcomponent 178 ) = subcomponent.nodeController 179 180 @Provides 181 @NewsHeader 182 @JvmStatic fun providesNewsHeaderController( 183 @NewsHeader subcomponent: SectionHeaderControllerSubcomponent 184 ) = subcomponent.headerController 185 186 @Provides 187 @SocialHeader 188 @JvmStatic fun providesSocialHeaderNodeController( 189 @SocialHeader subcomponent: SectionHeaderControllerSubcomponent 190 ) = subcomponent.nodeController 191 192 @Provides 193 @SocialHeader 194 @JvmStatic fun providesSocialHeaderController( 195 @SocialHeader subcomponent: SectionHeaderControllerSubcomponent 196 ) = subcomponent.headerController 197 198 @Provides 199 @RecsHeader 200 @JvmStatic fun providesRecsHeaderNodeController( 201 @RecsHeader subcomponent: SectionHeaderControllerSubcomponent 202 ) = subcomponent.nodeController 203 204 @Provides 205 @RecsHeader 206 @JvmStatic fun providesRecsHeaderController( 207 @RecsHeader subcomponent: SectionHeaderControllerSubcomponent 208 ) = subcomponent.headerController 209 210 @Provides 211 @PromoHeader 212 @JvmStatic fun providesPromoHeaderNodeController( 213 @PromoHeader subcomponent: SectionHeaderControllerSubcomponent 214 ) = subcomponent.nodeController 215 216 @Provides 217 @PromoHeader 218 @JvmStatic fun providesPromoHeaderController( 219 @PromoHeader subcomponent: SectionHeaderControllerSubcomponent 220 ) = subcomponent.headerController 221 } 222 223 @Subcomponent(modules = [ SectionHeaderBindingModule::class ]) 224 @SectionHeaderScope 225 interface SectionHeaderControllerSubcomponent { 226 227 val nodeController: NodeController 228 val headerController: SectionHeaderController 229 230 @Subcomponent.Builder 231 interface Builder { 232 fun build(): SectionHeaderControllerSubcomponent 233 @BindsInstance fun nodeLabel(@NodeLabel nodeLabel: String): Builder 234 @BindsInstance fun headerText(@HeaderText @StringRes headerText: Int): Builder 235 @BindsInstance fun clickIntentAction(@HeaderClickAction clickIntentAction: String): Builder 236 } 237 } 238 239 @Module 240 abstract class SectionHeaderBindingModule { bindsNodeControllernull241 @Binds abstract fun bindsNodeController(impl: SectionHeaderNodeControllerImpl): NodeController 242 @Binds abstract fun bindsSectionHeaderController( 243 impl: SectionHeaderNodeControllerImpl 244 ): SectionHeaderController 245 } 246 247 @Qualifier 248 @Retention(AnnotationRetention.BINARY) 249 annotation class HeaderText 250 251 @Qualifier 252 @Retention(AnnotationRetention.BINARY) 253 annotation class IncomingHeader 254 255 @Qualifier 256 @Retention(AnnotationRetention.BINARY) 257 annotation class AlertingHeader 258 259 @Qualifier 260 @Retention(AnnotationRetention.BINARY) 261 annotation class SilentHeader 262 263 @Qualifier 264 @Retention(AnnotationRetention.BINARY) 265 annotation class PeopleHeader 266 267 @Qualifier 268 @Retention(AnnotationRetention.BINARY) 269 annotation class NodeLabel 270 271 @Qualifier 272 @Retention(AnnotationRetention.BINARY) 273 annotation class HeaderClickAction 274 275 @Scope 276 @Retention(AnnotationRetention.BINARY) 277 annotation class SectionHeaderScope 278 279 @Qualifier 280 @Retention(AnnotationRetention.BINARY) 281 annotation class NewsHeader 282 283 @Qualifier 284 @Retention(AnnotationRetention.BINARY) 285 annotation class SocialHeader 286 287 @Qualifier 288 @Retention(AnnotationRetention.BINARY) 289 annotation class RecsHeader 290 291 @Qualifier 292 @Retention(AnnotationRetention.BINARY) 293 annotation class PromoHeader