• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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.communal.domain.interactor
18 
19 import android.content.pm.UserInfo
20 import com.android.systemui.communal.data.repository.CommunalPrefsRepository
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.dagger.qualifiers.Background
23 import com.android.systemui.log.dagger.CommunalTableLog
24 import com.android.systemui.log.table.TableLogBuffer
25 import com.android.systemui.log.table.logDiffsForTable
26 import com.android.systemui.settings.UserTracker
27 import com.android.systemui.user.domain.interactor.SelectedUserInteractor
28 import javax.inject.Inject
29 import kotlinx.coroutines.CoroutineScope
30 import kotlinx.coroutines.flow.Flow
31 import kotlinx.coroutines.flow.SharingStarted
32 import kotlinx.coroutines.flow.flatMapLatest
33 import kotlinx.coroutines.flow.stateIn
34 import kotlinx.coroutines.launch
35 
36 @SysUISingleton
37 class CommunalPrefsInteractor
38 @Inject
39 constructor(
40     @Background private val bgScope: CoroutineScope,
41     private val repository: CommunalPrefsRepository,
42     userInteractor: SelectedUserInteractor,
43     private val userTracker: UserTracker,
44     @CommunalTableLog tableLogBuffer: TableLogBuffer,
45 ) {
46 
47     val isCtaDismissed: Flow<Boolean> =
48         userInteractor.selectedUserInfo
49             .flatMapLatest { user -> repository.isCtaDismissed(user) }
50             .logDiffsForTable(
51                 tableLogBuffer = tableLogBuffer,
52                 columnName = "isCtaDismissed",
53                 initialValue = false,
54             )
55             .stateIn(
56                 scope = bgScope,
57                 started = SharingStarted.WhileSubscribed(),
58                 initialValue = false,
59             )
60 
61     suspend fun setCtaDismissed(user: UserInfo = userTracker.userInfo) =
62         repository.setCtaDismissed(user)
63 
64     val isHubOnboardingDismissed: Flow<Boolean> =
65         userInteractor.selectedUserInfo
66             .flatMapLatest { user -> repository.isHubOnboardingDismissed(user) }
67             .logDiffsForTable(
68                 tableLogBuffer = tableLogBuffer,
69                 columnName = "isHubOnboardingDismissed",
70                 initialValue = false,
71             )
72             .stateIn(
73                 scope = bgScope,
74                 started = SharingStarted.WhileSubscribed(),
75                 initialValue = false,
76             )
77 
78     fun setHubOnboardingDismissed(user: UserInfo = userTracker.userInfo) =
79         bgScope.launch { repository.setHubOnboardingDismissed(user) }
80 
81     val isDreamButtonTooltipDismissed: Flow<Boolean> =
82         userInteractor.selectedUserInfo
83             .flatMapLatest { user -> repository.isDreamButtonTooltipDismissed(user) }
84             .logDiffsForTable(
85                 tableLogBuffer = tableLogBuffer,
86                 columnPrefix = "",
87                 columnName = "isDreamButtonTooltipDismissed",
88                 initialValue = false,
89             )
90             .stateIn(
91                 scope = bgScope,
92                 started = SharingStarted.WhileSubscribed(),
93                 initialValue = false,
94             )
95 
96     fun setDreamButtonTooltipDismissed(user: UserInfo = userTracker.userInfo) =
97         bgScope.launch { repository.setDreamButtonTooltipDismissed(user) }
98 
99     private companion object {
100         const val TAG = "CommunalPrefsInteractor"
101     }
102 }
103