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.accessibility.qs
18 
19 import com.android.systemui.Flags
20 import com.android.systemui.qs.QsEventLogger
21 import com.android.systemui.qs.pipeline.shared.TileSpec
22 import com.android.systemui.qs.tileimpl.QSTileImpl
23 import com.android.systemui.qs.tiles.ColorCorrectionTile
24 import com.android.systemui.qs.tiles.ColorInversionTile
25 import com.android.systemui.qs.tiles.DreamTile
26 import com.android.systemui.qs.tiles.FontScalingTile
27 import com.android.systemui.qs.tiles.HearingDevicesTile
28 import com.android.systemui.qs.tiles.NightDisplayTile
29 import com.android.systemui.qs.tiles.OneHandedModeTile
30 import com.android.systemui.qs.tiles.ReduceBrightColorsTile
31 import com.android.systemui.qs.tiles.base.interactor.QSTileAvailabilityInteractor
32 import com.android.systemui.qs.tiles.base.viewmodel.QSTileViewModelFactory
33 import com.android.systemui.qs.tiles.impl.colorcorrection.domain.ColorCorrectionTileMapper
34 import com.android.systemui.qs.tiles.impl.colorcorrection.domain.interactor.ColorCorrectionTileDataInteractor
35 import com.android.systemui.qs.tiles.impl.colorcorrection.domain.interactor.ColorCorrectionUserActionInteractor
36 import com.android.systemui.qs.tiles.impl.colorcorrection.domain.model.ColorCorrectionTileModel
37 import com.android.systemui.qs.tiles.impl.fontscaling.domain.FontScalingTileMapper
38 import com.android.systemui.qs.tiles.impl.fontscaling.domain.interactor.FontScalingTileDataInteractor
39 import com.android.systemui.qs.tiles.impl.fontscaling.domain.interactor.FontScalingTileUserActionInteractor
40 import com.android.systemui.qs.tiles.impl.fontscaling.domain.model.FontScalingTileModel
41 import com.android.systemui.qs.tiles.impl.inversion.domain.ColorInversionTileMapper
42 import com.android.systemui.qs.tiles.impl.inversion.domain.interactor.ColorInversionTileDataInteractor
43 import com.android.systemui.qs.tiles.impl.inversion.domain.interactor.ColorInversionUserActionInteractor
44 import com.android.systemui.qs.tiles.impl.inversion.domain.model.ColorInversionTileModel
45 import com.android.systemui.qs.tiles.impl.night.domain.interactor.NightDisplayTileDataInteractor
46 import com.android.systemui.qs.tiles.impl.night.domain.interactor.NightDisplayTileUserActionInteractor
47 import com.android.systemui.qs.tiles.impl.night.domain.model.NightDisplayTileModel
48 import com.android.systemui.qs.tiles.impl.night.ui.NightDisplayTileMapper
49 import com.android.systemui.qs.tiles.impl.onehanded.domain.OneHandedModeTileDataInteractor
50 import com.android.systemui.qs.tiles.impl.onehanded.domain.OneHandedModeTileUserActionInteractor
51 import com.android.systemui.qs.tiles.impl.onehanded.domain.model.OneHandedModeTileModel
52 import com.android.systemui.qs.tiles.impl.onehanded.ui.OneHandedModeTileMapper
53 import com.android.systemui.qs.tiles.impl.reducebrightness.domain.interactor.ReduceBrightColorsTileDataInteractor
54 import com.android.systemui.qs.tiles.impl.reducebrightness.domain.interactor.ReduceBrightColorsTileUserActionInteractor
55 import com.android.systemui.qs.tiles.impl.reducebrightness.domain.model.ReduceBrightColorsTileModel
56 import com.android.systemui.qs.tiles.impl.reducebrightness.ui.ReduceBrightColorsTileMapper
57 import com.android.systemui.qs.tiles.viewmodel.QSTileConfig
58 import com.android.systemui.qs.tiles.viewmodel.QSTileUIConfig
59 import com.android.systemui.qs.tiles.viewmodel.QSTileViewModel
60 import com.android.systemui.qs.tiles.viewmodel.StubQSTileViewModel
61 import com.android.systemui.res.R
62 import dagger.Binds
63 import dagger.Module
64 import dagger.Provides
65 import dagger.multibindings.IntoMap
66 import dagger.multibindings.StringKey
67 
68 @Module
69 interface QSAccessibilityModule {
70 
71     /** Inject ColorInversionTile into tileMap in QSModule */
72     @Binds
73     @IntoMap
74     @StringKey(ColorInversionTile.TILE_SPEC)
bindColorInversionTilenull75     fun bindColorInversionTile(colorInversionTile: ColorInversionTile): QSTileImpl<*>
76 
77     /** Inject NightDisplayTile into tileMap in QSModule */
78     @Binds
79     @IntoMap
80     @StringKey(NightDisplayTile.TILE_SPEC)
81     fun bindNightDisplayTile(nightDisplayTile: NightDisplayTile): QSTileImpl<*>
82 
83     /** Inject ReduceBrightColorsTile into tileMap in QSModule */
84     @Binds
85     @IntoMap
86     @StringKey(ReduceBrightColorsTile.TILE_SPEC)
87     fun bindReduceBrightColorsTile(reduceBrightColorsTile: ReduceBrightColorsTile): QSTileImpl<*>
88 
89     /** Inject OneHandedModeTile into tileMap in QSModule */
90     @Binds
91     @IntoMap
92     @StringKey(OneHandedModeTile.TILE_SPEC)
93     fun bindOneHandedModeTile(oneHandedModeTile: OneHandedModeTile): QSTileImpl<*>
94 
95     /** Inject ColorCorrectionTile into tileMap in QSModule */
96     @Binds
97     @IntoMap
98     @StringKey(ColorCorrectionTile.TILE_SPEC)
99     fun bindColorCorrectionTile(colorCorrectionTile: ColorCorrectionTile): QSTileImpl<*>
100 
101     /** Inject DreamTile into tileMap in QSModule */
102     @Binds
103     @IntoMap
104     @StringKey(DreamTile.TILE_SPEC)
105     fun bindDreamTile(dreamTile: DreamTile): QSTileImpl<*>
106 
107     /** Inject FontScalingTile into tileMap in QSModule */
108     @Binds
109     @IntoMap
110     @StringKey(FontScalingTile.TILE_SPEC)
111     fun bindFontScalingTile(fontScalingTile: FontScalingTile): QSTileImpl<*>
112 
113     /** Inject HearingDevicesTile into tileMap in QSModule */
114     @Binds
115     @IntoMap
116     @StringKey(HearingDevicesTile.TILE_SPEC)
117     fun bindHearingDevicesTile(hearingDevicesTile: HearingDevicesTile): QSTileImpl<*>
118 
119     @Binds
120     @IntoMap
121     @StringKey(COLOR_CORRECTION_TILE_SPEC)
122     fun provideColorCorrectionAvailabilityInteractor(
123             impl: ColorCorrectionTileDataInteractor
124     ): QSTileAvailabilityInteractor
125 
126     @Binds
127     @IntoMap
128     @StringKey(COLOR_INVERSION_TILE_SPEC)
129     fun provideColorInversionAvailabilityInteractor(
130             impl: ColorCorrectionTileDataInteractor
131     ): QSTileAvailabilityInteractor
132 
133     @Binds
134     @IntoMap
135     @StringKey(FONT_SCALING_TILE_SPEC)
136     fun provideFontScalingAvailabilityInteractor(
137             impl: FontScalingTileDataInteractor
138     ): QSTileAvailabilityInteractor
139 
140     @Binds
141     @IntoMap
142     @StringKey(REDUCE_BRIGHTNESS_TILE_SPEC)
143     fun provideReduceBrightnessAvailabilityInteractor(
144             impl: ReduceBrightColorsTileDataInteractor
145     ): QSTileAvailabilityInteractor
146 
147     @Binds
148     @IntoMap
149     @StringKey(ONE_HANDED_TILE_SPEC)
150     fun provideOneHandedAvailabilityInteractor(
151             impl: OneHandedModeTileDataInteractor
152     ): QSTileAvailabilityInteractor
153 
154     @Binds
155     @IntoMap
156     @StringKey(NIGHT_DISPLAY_TILE_SPEC)
157     fun provideNightDisplayAvailabilityInteractor(
158             impl: NightDisplayTileDataInteractor
159     ): QSTileAvailabilityInteractor
160 
161     companion object {
162         const val COLOR_CORRECTION_TILE_SPEC = "color_correction"
163         const val COLOR_INVERSION_TILE_SPEC = "inversion"
164         const val FONT_SCALING_TILE_SPEC = "font_scaling"
165         const val REDUCE_BRIGHTNESS_TILE_SPEC = "reduce_brightness"
166         const val ONE_HANDED_TILE_SPEC = "onehanded"
167         const val NIGHT_DISPLAY_TILE_SPEC = "night"
168 
169         @Provides
170         @IntoMap
171         @StringKey(COLOR_CORRECTION_TILE_SPEC)
172         fun provideColorCorrectionTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
173             QSTileConfig(
174                 tileSpec = TileSpec.create(COLOR_CORRECTION_TILE_SPEC),
175                 uiConfig =
176                     QSTileUIConfig.Resource(
177                         iconRes = R.drawable.ic_qs_color_correction,
178                         labelRes = R.string.quick_settings_color_correction_label,
179                     ),
180                 instanceId = uiEventLogger.getNewInstanceId(),
181             )
182 
183         /** Inject ColorCorrectionTile into tileViewModelMap in QSModule */
184         @Provides
185         @IntoMap
186         @StringKey(COLOR_CORRECTION_TILE_SPEC)
187         fun provideColorCorrectionTileViewModel(
188             factory: QSTileViewModelFactory.Static<ColorCorrectionTileModel>,
189             mapper: ColorCorrectionTileMapper,
190             stateInteractor: ColorCorrectionTileDataInteractor,
191             userActionInteractor: ColorCorrectionUserActionInteractor
192         ): QSTileViewModel =
193             factory.create(
194                 TileSpec.create(COLOR_CORRECTION_TILE_SPEC),
195                 userActionInteractor,
196                 stateInteractor,
197                 mapper,
198             )
199 
200         @Provides
201         @IntoMap
202         @StringKey(COLOR_INVERSION_TILE_SPEC)
203         fun provideColorInversionTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
204             QSTileConfig(
205                 tileSpec = TileSpec.create(COLOR_INVERSION_TILE_SPEC),
206                 uiConfig =
207                     QSTileUIConfig.Resource(
208                         iconRes = R.drawable.qs_invert_colors_icon_off,
209                         labelRes = R.string.quick_settings_inversion_label,
210                     ),
211                 instanceId = uiEventLogger.getNewInstanceId(),
212             )
213 
214         /** Inject ColorInversionTile into tileViewModelMap in QSModule */
215         @Provides
216         @IntoMap
217         @StringKey(COLOR_INVERSION_TILE_SPEC)
218         fun provideColorInversionTileViewModel(
219             factory: QSTileViewModelFactory.Static<ColorInversionTileModel>,
220             mapper: ColorInversionTileMapper,
221             stateInteractor: ColorInversionTileDataInteractor,
222             userActionInteractor: ColorInversionUserActionInteractor
223         ): QSTileViewModel =
224             factory.create(
225                 TileSpec.create(COLOR_INVERSION_TILE_SPEC),
226                 userActionInteractor,
227                 stateInteractor,
228                 mapper,
229             )
230 
231         @Provides
232         @IntoMap
233         @StringKey(FONT_SCALING_TILE_SPEC)
234         fun provideFontScalingTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
235             QSTileConfig(
236                 tileSpec = TileSpec.create(FONT_SCALING_TILE_SPEC),
237                 uiConfig =
238                     QSTileUIConfig.Resource(
239                         iconRes = R.drawable.ic_qs_font_scaling,
240                         labelRes = R.string.quick_settings_font_scaling_label,
241                     ),
242                 instanceId = uiEventLogger.getNewInstanceId(),
243             )
244 
245         /** Inject FontScaling Tile into tileViewModelMap in QSModule */
246         @Provides
247         @IntoMap
248         @StringKey(FONT_SCALING_TILE_SPEC)
249         fun provideFontScalingTileViewModel(
250             factory: QSTileViewModelFactory.Static<FontScalingTileModel>,
251             mapper: FontScalingTileMapper,
252             stateInteractor: FontScalingTileDataInteractor,
253             userActionInteractor: FontScalingTileUserActionInteractor
254         ): QSTileViewModel =
255             factory.create(
256                 TileSpec.create(FONT_SCALING_TILE_SPEC),
257                 userActionInteractor,
258                 stateInteractor,
259                 mapper,
260             )
261 
262         @Provides
263         @IntoMap
264         @StringKey(REDUCE_BRIGHTNESS_TILE_SPEC)
265         fun provideReduceBrightColorsTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
266             QSTileConfig(
267                 tileSpec = TileSpec.create(REDUCE_BRIGHTNESS_TILE_SPEC),
268                 uiConfig =
269                     QSTileUIConfig.Resource(
270                         iconRes = R.drawable.qs_extra_dim_icon_on,
271                         labelRes = com.android.internal.R.string.reduce_bright_colors_feature_name,
272                     ),
273                 instanceId = uiEventLogger.getNewInstanceId(),
274             )
275 
276         /**
277          * Inject Reduce Bright Colors Tile into tileViewModelMap in QSModule. The tile is hidden
278          * behind a flag.
279          */
280         @Provides
281         @IntoMap
282         @StringKey(REDUCE_BRIGHTNESS_TILE_SPEC)
283         fun provideReduceBrightColorsTileViewModel(
284             factory: QSTileViewModelFactory.Static<ReduceBrightColorsTileModel>,
285             mapper: ReduceBrightColorsTileMapper,
286             stateInteractor: ReduceBrightColorsTileDataInteractor,
287             userActionInteractor: ReduceBrightColorsTileUserActionInteractor
288         ): QSTileViewModel =
289             if (Flags.qsNewTilesFuture())
290                 factory.create(
291                     TileSpec.create(REDUCE_BRIGHTNESS_TILE_SPEC),
292                     userActionInteractor,
293                     stateInteractor,
294                     mapper,
295                 )
296             else StubQSTileViewModel
297 
298         @Provides
299         @IntoMap
300         @StringKey(ONE_HANDED_TILE_SPEC)
301         fun provideOneHandedTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
302             QSTileConfig(
303                 tileSpec = TileSpec.create(ONE_HANDED_TILE_SPEC),
304                 uiConfig =
305                     QSTileUIConfig.Resource(
306                         iconRes = com.android.internal.R.drawable.ic_qs_one_handed_mode,
307                         labelRes = R.string.quick_settings_onehanded_label,
308                     ),
309                 instanceId = uiEventLogger.getNewInstanceId(),
310             )
311 
312         /** Inject One Handed Mode Tile into tileViewModelMap in QSModule. */
313         @Provides
314         @IntoMap
315         @StringKey(ONE_HANDED_TILE_SPEC)
316         fun provideOneHandedModeTileViewModel(
317             factory: QSTileViewModelFactory.Static<OneHandedModeTileModel>,
318             mapper: OneHandedModeTileMapper,
319             stateInteractor: OneHandedModeTileDataInteractor,
320             userActionInteractor: OneHandedModeTileUserActionInteractor
321         ): QSTileViewModel =
322             if (Flags.qsNewTilesFuture())
323                 factory.create(
324                     TileSpec.create(ONE_HANDED_TILE_SPEC),
325                     userActionInteractor,
326                     stateInteractor,
327                     mapper,
328                 )
329             else StubQSTileViewModel
330 
331         @Provides
332         @IntoMap
333         @StringKey(NIGHT_DISPLAY_TILE_SPEC)
334         fun provideNightDisplayTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
335             QSTileConfig(
336                 tileSpec = TileSpec.create(NIGHT_DISPLAY_TILE_SPEC),
337                 uiConfig =
338                     QSTileUIConfig.Resource(
339                         iconRes = R.drawable.qs_nightlight_icon_off,
340                         labelRes = R.string.quick_settings_night_display_label,
341                     ),
342                 instanceId = uiEventLogger.getNewInstanceId(),
343             )
344 
345         /**
346          * Inject NightDisplay Tile into tileViewModelMap in QSModule. The tile is hidden behind a
347          * flag.
348          */
349         @Provides
350         @IntoMap
351         @StringKey(NIGHT_DISPLAY_TILE_SPEC)
352         fun provideNightDisplayTileViewModel(
353             factory: QSTileViewModelFactory.Static<NightDisplayTileModel>,
354             mapper: NightDisplayTileMapper,
355             stateInteractor: NightDisplayTileDataInteractor,
356             userActionInteractor: NightDisplayTileUserActionInteractor
357         ): QSTileViewModel =
358             if (Flags.qsNewTilesFuture())
359                 factory.create(
360                     TileSpec.create(NIGHT_DISPLAY_TILE_SPEC),
361                     userActionInteractor,
362                     stateInteractor,
363                     mapper,
364                 )
365             else StubQSTileViewModel
366     }
367 }
368