-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAppUpdateTimedSheet.kt
More file actions
49 lines (40 loc) · 1.57 KB
/
AppUpdateTimedSheet.kt
File metadata and controls
49 lines (40 loc) · 1.57 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.CoroutineDispatcher
import kotlinx.coroutines.withContext
import to.bitkit.BuildConfig
import to.bitkit.di.BgDispatcher
import to.bitkit.services.AppUpdaterService
import to.bitkit.ui.components.TimedSheetType
import to.bitkit.utils.Logger
import to.bitkit.utils.timedsheets.TimedSheetItem
import javax.inject.Inject
class AppUpdateTimedSheet @Inject constructor(
private val appUpdaterService: AppUpdaterService,
@BgDispatcher private val bgDispatcher: CoroutineDispatcher,
) : TimedSheetItem {
override val type = TimedSheetType.APP_UPDATE
override val priority = 5
override suspend fun shouldShow(): Boolean = withContext(bgDispatcher) {
try {
val androidReleaseInfo = appUpdaterService.getReleaseInfo().platforms.android
val currentBuildNumber = BuildConfig.VERSION_CODE
if (androidReleaseInfo.buildNumber <= currentBuildNumber) return@withContext false
if (androidReleaseInfo.isCritical) {
return@withContext false
}
return@withContext true
} catch (e: Exception) {
Logger.warn("Failure fetching new releases", e = e, context = TAG)
return@withContext false
}
}
override suspend fun onShown() {
Logger.debug("App update sheet shown", context = TAG)
}
override suspend fun onDismissed() {
Logger.debug("App update sheet dismissed", context = TAG)
}
companion object {
private const val TAG = "AppUpdateTimedSheet"
}
}