1 /*
2  * Copyright (C) 2022 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.qrcodescanner.dagger
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.QRCodeScannerTile
24 import com.android.systemui.qs.tiles.base.interactor.QSTileAvailabilityInteractor
25 import com.android.systemui.qs.tiles.base.viewmodel.QSTileViewModelFactory
26 import com.android.systemui.qs.tiles.impl.qr.domain.interactor.QRCodeScannerTileDataInteractor
27 import com.android.systemui.qs.tiles.impl.qr.domain.interactor.QRCodeScannerTileUserActionInteractor
28 import com.android.systemui.qs.tiles.impl.qr.domain.model.QRCodeScannerTileModel
29 import com.android.systemui.qs.tiles.impl.qr.ui.QRCodeScannerTileMapper
30 import com.android.systemui.qs.tiles.viewmodel.QSTileConfig
31 import com.android.systemui.qs.tiles.viewmodel.QSTileUIConfig
32 import com.android.systemui.qs.tiles.viewmodel.QSTileViewModel
33 import com.android.systemui.qs.tiles.viewmodel.StubQSTileViewModel
34 import com.android.systemui.res.R
35 import dagger.Binds
36 import dagger.Module
37 import dagger.Provides
38 import dagger.multibindings.IntoMap
39 import dagger.multibindings.StringKey
40 
41 @Module
42 interface QRCodeScannerModule {
43 
44     /**  */
45     @Binds
46     @IntoMap
47     @StringKey(QRCodeScannerTile.TILE_SPEC)
bindQRCodeScannerTilenull48     fun bindQRCodeScannerTile(qrCodeScannerTile: QRCodeScannerTile): QSTileImpl<*>
49 
50     @Binds
51     @IntoMap
52     @StringKey(QR_CODE_SCANNER_TILE_SPEC)
53     fun provideQrCodeScannerAvailabilityInteractor(
54             impl: QRCodeScannerTileDataInteractor
55     ): QSTileAvailabilityInteractor
56 
57     companion object {
58         const val QR_CODE_SCANNER_TILE_SPEC = "qr_code_scanner"
59 
60         @Provides
61         @IntoMap
62         @StringKey(QR_CODE_SCANNER_TILE_SPEC)
63         fun provideQRCodeScannerTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
64             QSTileConfig(
65                 tileSpec = TileSpec.create(QR_CODE_SCANNER_TILE_SPEC),
66                 uiConfig =
67                     QSTileUIConfig.Resource(
68                         iconRes = R.drawable.ic_qr_code_scanner,
69                         labelRes = R.string.qr_code_scanner_title,
70                     ),
71                 instanceId = uiEventLogger.getNewInstanceId(),
72             )
73 
74         /** Inject QR Code Scanner Tile into tileViewModelMap in QSModule. */
75         @Provides
76         @IntoMap
77         @StringKey(QR_CODE_SCANNER_TILE_SPEC)
78         fun provideQRCodeScannerTileViewModel(
79             factory: QSTileViewModelFactory.Static<QRCodeScannerTileModel>,
80             mapper: QRCodeScannerTileMapper,
81             stateInteractor: QRCodeScannerTileDataInteractor,
82             userActionInteractor: QRCodeScannerTileUserActionInteractor
83         ): QSTileViewModel =
84             if (Flags.qsNewTilesFuture())
85                 factory.create(
86                     TileSpec.create(QR_CODE_SCANNER_TILE_SPEC),
87                     userActionInteractor,
88                     stateInteractor,
89                     mapper,
90                 )
91             else StubQSTileViewModel
92     }
93 }
94