1 /*
2  * Copyright (C) 2024 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.rotationlock
18 
19 import com.android.systemui.camera.CameraRotationModule
20 import com.android.systemui.qs.QsEventLogger
21 import com.android.systemui.qs.pipeline.shared.TileSpec
22 import com.android.systemui.qs.tiles.base.interactor.QSTileAvailabilityInteractor
23 import com.android.systemui.qs.tiles.base.viewmodel.QSTileViewModelFactory
24 import com.android.systemui.qs.tiles.impl.rotation.domain.interactor.RotationLockTileDataInteractor
25 import com.android.systemui.qs.tiles.impl.rotation.domain.interactor.RotationLockTileUserActionInteractor
26 import com.android.systemui.qs.tiles.impl.rotation.domain.model.RotationLockTileModel
27 import com.android.systemui.qs.tiles.impl.rotation.ui.mapper.RotationLockTileMapper
28 import com.android.systemui.qs.tiles.viewmodel.QSTileConfig
29 import com.android.systemui.qs.tiles.viewmodel.QSTileUIConfig
30 import com.android.systemui.qs.tiles.viewmodel.QSTileViewModel
31 import com.android.systemui.res.R
32 import dagger.Binds
33 import dagger.Module
34 import dagger.Provides
35 import dagger.multibindings.IntoMap
36 import dagger.multibindings.StringKey
37 
38 @Module(includes = [CameraRotationModule::class])
39 interface RotationLockNewModule {
40 
41     @Binds
42     @IntoMap
43     @StringKey(ROTATION_TILE_SPEC)
provideRotationAvailabilityInteractornull44     fun provideRotationAvailabilityInteractor(
45             impl: RotationLockTileDataInteractor
46     ): QSTileAvailabilityInteractor
47     companion object {
48         private const val ROTATION_TILE_SPEC = "rotation"
49 
50         /** Inject rotation tile config */
51         @Provides
52         @IntoMap
53         @StringKey(ROTATION_TILE_SPEC)
54         fun provideRotationTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
55             QSTileConfig(
56                 tileSpec = TileSpec.create(ROTATION_TILE_SPEC),
57                 uiConfig =
58                     QSTileUIConfig.Resource(
59                         iconRes = R.drawable.qs_auto_rotate_icon_off,
60                         labelRes = R.string.quick_settings_rotation_unlocked_label,
61                     ),
62                 instanceId = uiEventLogger.getNewInstanceId(),
63             )
64 
65         /** Inject Rotation tile into tileViewModelMap in QSModule */
66         @Provides
67         @IntoMap
68         @StringKey(ROTATION_TILE_SPEC)
69         fun provideRotationTileViewModel(
70             factory: QSTileViewModelFactory.Static<RotationLockTileModel>,
71             mapper: RotationLockTileMapper,
72             stateInteractor: RotationLockTileDataInteractor,
73             userActionInteractor: RotationLockTileUserActionInteractor
74         ): QSTileViewModel =
75             factory.create(
76                 TileSpec.create(ROTATION_TILE_SPEC),
77                 userActionInteractor,
78                 stateInteractor,
79                 mapper,
80             )
81     }
82 }
83