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.qs.tiles.impl.night.domain.interactor
18 
19 import android.content.Intent
20 import android.hardware.display.ColorDisplayManager.AUTO_MODE_CUSTOM_TIME
21 import android.provider.Settings
22 import com.android.systemui.accessibility.data.repository.NightDisplayRepository
23 import com.android.systemui.accessibility.qs.QSAccessibilityModule
24 import com.android.systemui.qs.pipeline.shared.TileSpec
25 import com.android.systemui.qs.tiles.base.actions.QSTileIntentUserInputHandler
26 import com.android.systemui.qs.tiles.base.interactor.QSTileInput
27 import com.android.systemui.qs.tiles.base.interactor.QSTileUserActionInteractor
28 import com.android.systemui.qs.tiles.base.logging.QSTileLogger
29 import com.android.systemui.qs.tiles.impl.night.domain.model.NightDisplayTileModel
30 import com.android.systemui.qs.tiles.viewmodel.QSTileUserAction
31 import javax.inject.Inject
32 
33 /** Handles night display tile clicks. */
34 class NightDisplayTileUserActionInteractor
35 @Inject
36 constructor(
37     private val nightDisplayRepository: NightDisplayRepository,
38     private val qsTileIntentUserActionHandler: QSTileIntentUserInputHandler,
39     private val qsLogger: QSTileLogger,
40 ) : QSTileUserActionInteractor<NightDisplayTileModel> {
handleInputnull41     override suspend fun handleInput(input: QSTileInput<NightDisplayTileModel>): Unit =
42         with(input) {
43             when (action) {
44                 is QSTileUserAction.Click -> {
45                     // Enroll in forced auto mode if eligible.
46                     if (data.isEnrolledInForcedNightDisplayAutoMode) {
47                         nightDisplayRepository.setNightDisplayAutoMode(AUTO_MODE_CUSTOM_TIME, user)
48                         qsLogger.logInfo(spec, "Enrolled in forced night display auto mode")
49                     }
50                     nightDisplayRepository.setNightDisplayActivated(!data.isActivated, user)
51                 }
52                 is QSTileUserAction.LongClick -> {
53                     qsTileIntentUserActionHandler.handle(
54                         action.expandable,
55                         Intent(Settings.ACTION_NIGHT_DISPLAY_SETTINGS)
56                     )
57                 }
58             }
59         }
60 
61     companion object {
62         val spec = TileSpec.create(QSAccessibilityModule.NIGHT_DISPLAY_TILE_SPEC)
63     }
64 }
65