• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.volume.dialog.ringer.data.repository
18 
19 import android.content.Context
20 import com.android.systemui.Prefs
21 import com.android.systemui.dagger.qualifiers.Application
22 import com.android.systemui.dagger.qualifiers.Background
23 import javax.inject.Inject
24 import kotlinx.coroutines.CoroutineDispatcher
25 import kotlinx.coroutines.withContext
26 
27 interface VolumeDialogRingerFeedbackRepository {
28 
29     /** gets number of shown toasts */
getToastCountnull30     suspend fun getToastCount(): Int
31 
32     /** updates number of shown toasts */
33     suspend fun updateToastCount(toastCount: Int)
34 }
35 
36 class VolumeDialogRingerFeedbackRepositoryImpl
37 @Inject
38 constructor(
39     @Application private val applicationContext: Context,
40     @Background val backgroundDispatcher: CoroutineDispatcher,
41 ) : VolumeDialogRingerFeedbackRepository {
42 
43     override suspend fun getToastCount(): Int =
44         withContext(backgroundDispatcher) {
45             return@withContext Prefs.getInt(
46                 applicationContext,
47                 Prefs.Key.SEEN_RINGER_GUIDANCE_COUNT,
48                 0,
49             )
50         }
51 
52     override suspend fun updateToastCount(toastCount: Int) {
53         withContext(backgroundDispatcher) {
54             Prefs.putInt(applicationContext, Prefs.Key.SEEN_RINGER_GUIDANCE_COUNT, toastCount + 1)
55         }
56     }
57 }
58