1 package com.android.systemui.battery
2 
3 import com.android.systemui.qs.QsEventLogger
4 import com.android.systemui.qs.pipeline.shared.TileSpec
5 import com.android.systemui.qs.tileimpl.QSTileImpl
6 import com.android.systemui.qs.tiles.BatterySaverTile
7 import com.android.systemui.qs.tiles.base.interactor.QSTileAvailabilityInteractor
8 import com.android.systemui.qs.tiles.base.viewmodel.QSTileViewModelFactory
9 import com.android.systemui.qs.tiles.impl.battery.domain.interactor.BatterySaverTileDataInteractor
10 import com.android.systemui.qs.tiles.impl.battery.domain.interactor.BatterySaverTileUserActionInteractor
11 import com.android.systemui.qs.tiles.impl.battery.domain.model.BatterySaverTileModel
12 import com.android.systemui.qs.tiles.impl.battery.ui.BatterySaverTileMapper
13 import com.android.systemui.qs.tiles.viewmodel.QSTileConfig
14 import com.android.systemui.qs.tiles.viewmodel.QSTileUIConfig
15 import com.android.systemui.qs.tiles.viewmodel.QSTileViewModel
16 import com.android.systemui.res.R
17 import dagger.Binds
18 import dagger.Module
19 import dagger.Provides
20 import dagger.multibindings.IntoMap
21 import dagger.multibindings.StringKey
22 
23 @Module
24 interface BatterySaverModule {
25 
26     /** Inject BatterySaverTile into tileMap in QSModule */
27     @Binds
28     @IntoMap
29     @StringKey(BatterySaverTile.TILE_SPEC)
bindBatterySaverTilenull30     fun bindBatterySaverTile(batterySaverTile: BatterySaverTile): QSTileImpl<*>
31 
32     @Binds
33     @IntoMap
34     @StringKey(BATTERY_SAVER_TILE_SPEC)
35     fun provideBatterySaverAvailabilityInteractor(
36             impl: BatterySaverTileDataInteractor
37     ): QSTileAvailabilityInteractor
38 
39     companion object {
40         private const val BATTERY_SAVER_TILE_SPEC = "battery"
41 
42         @Provides
43         @IntoMap
44         @StringKey(BATTERY_SAVER_TILE_SPEC)
45         fun provideBatterySaverTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
46             QSTileConfig(
47                 tileSpec = TileSpec.create(BATTERY_SAVER_TILE_SPEC),
48                 uiConfig =
49                     QSTileUIConfig.Resource(
50                         iconRes = R.drawable.qs_battery_saver_icon_off,
51                         labelRes = R.string.battery_detail_switch_title,
52                     ),
53                 instanceId = uiEventLogger.getNewInstanceId(),
54             )
55 
56         /** Inject BatterySaverTile into tileViewModelMap in QSModule */
57         @Provides
58         @IntoMap
59         @StringKey(BATTERY_SAVER_TILE_SPEC)
60         fun provideBatterySaverTileViewModel(
61             factory: QSTileViewModelFactory.Static<BatterySaverTileModel>,
62             mapper: BatterySaverTileMapper,
63             stateInteractor: BatterySaverTileDataInteractor,
64             userActionInteractor: BatterySaverTileUserActionInteractor
65         ): QSTileViewModel =
66             factory.create(
67                 TileSpec.create(BATTERY_SAVER_TILE_SPEC),
68                 userActionInteractor,
69                 stateInteractor,
70                 mapper,
71             )
72     }
73 }
74