-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNotificationsTimedSheet.kt
More file actions
49 lines (42 loc) · 1.6 KB
/
NotificationsTimedSheet.kt
File metadata and controls
49 lines (42 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package to.bitkit.utils.timedsheets.sheets
import kotlinx.coroutines.flow.first
import to.bitkit.data.SettingsStore
import to.bitkit.ext.nowMillis
import to.bitkit.repositories.WalletRepo
import to.bitkit.ui.components.TimedSheetType
import to.bitkit.utils.Logger
import to.bitkit.utils.timedsheets.ONE_WEEK_ASK_INTERVAL_MILLIS
import to.bitkit.utils.timedsheets.TimedSheetItem
import to.bitkit.utils.timedsheets.checkTimeout
import javax.inject.Inject
import kotlin.time.ExperimentalTime
class NotificationsTimedSheet @Inject constructor(
private val settingsStore: SettingsStore,
private val walletRepo: WalletRepo,
) : TimedSheetItem {
override val type = TimedSheetType.NOTIFICATIONS
override val priority = 3
override suspend fun shouldShow(): Boolean {
val settings = settingsStore.data.first()
if (settings.notificationsGranted) return false
if (walletRepo.balanceState.value.totalLightningSats == 0UL) return false
return checkTimeout(
lastIgnoredMillis = settings.notificationsIgnoredMillis,
intervalMillis = ONE_WEEK_ASK_INTERVAL_MILLIS
)
}
override suspend fun onShown() {
Logger.debug("Notifications sheet shown", context = TAG)
}
@OptIn(ExperimentalTime::class)
override suspend fun onDismissed() {
val currentTime = nowMillis()
settingsStore.update {
it.copy(notificationsIgnoredMillis = currentTime)
}
Logger.debug("Notifications sheet dismissed", context = TAG)
}
companion object {
private const val TAG = "NotificationsTimedSheet"
}
}