mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 13:37:29 +01:00
App state banner tweaks (#8746)
* Move download indexing notification to this banner group * Animate state changes
This commit is contained in:
@@ -20,11 +20,14 @@ import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.flow.shareIn
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
@@ -53,8 +56,6 @@ class DownloadCache(
|
||||
.onStart { emit(Unit) }
|
||||
.shareIn(scope, SharingStarted.Eagerly, 1)
|
||||
|
||||
private val notifier by lazy { DownloadNotifier(context) }
|
||||
|
||||
/**
|
||||
* The interval after which this cache should be invalidated. 1 hour shouldn't cause major
|
||||
* issues, as the cache is only used for UI feedback.
|
||||
@@ -66,6 +67,10 @@ class DownloadCache(
|
||||
*/
|
||||
private var lastRenew = 0L
|
||||
private var renewalJob: Job? = null
|
||||
val isRenewing = changes
|
||||
.map { renewalJob?.isActive ?: false }
|
||||
.distinctUntilChanged()
|
||||
.stateIn(scope, SharingStarted.WhileSubscribed(), false)
|
||||
|
||||
private var rootDownloadsDir = RootDirectory(getDirectoryFromPreference())
|
||||
|
||||
@@ -260,8 +265,6 @@ class DownloadCache(
|
||||
}
|
||||
|
||||
renewalJob = scope.launchIO {
|
||||
notifier.onCacheProgress()
|
||||
|
||||
var sources = getSources()
|
||||
|
||||
// Try to wait until extensions and sources have loaded
|
||||
@@ -320,7 +323,6 @@ class DownloadCache(
|
||||
lastRenew = System.currentTimeMillis()
|
||||
notifyChanges()
|
||||
}
|
||||
renewalJob?.invokeOnCompletion { notifier.dismissCacheProgress() }
|
||||
}
|
||||
|
||||
private fun getSources(): List<Source> {
|
||||
|
||||
@@ -39,17 +39,6 @@ internal class DownloadNotifier(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
private val cacheNotificationBuilder by lazy {
|
||||
context.notificationBuilder(Notifications.CHANNEL_DOWNLOADER_CACHE) {
|
||||
setSmallIcon(R.drawable.ic_tachi)
|
||||
setContentTitle(context.getString(R.string.download_notifier_cache_renewal))
|
||||
setProgress(100, 100, true)
|
||||
setOngoing(true)
|
||||
setAutoCancel(false)
|
||||
setOnlyAlertOnce(true)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Status of download. Used for correct notification icon.
|
||||
*/
|
||||
@@ -223,14 +212,4 @@ internal class DownloadNotifier(private val context: Context) {
|
||||
errorThrown = true
|
||||
isDownloading = false
|
||||
}
|
||||
|
||||
fun onCacheProgress() {
|
||||
with(cacheNotificationBuilder) {
|
||||
show(Notifications.ID_DOWNLOAD_CACHE)
|
||||
}
|
||||
}
|
||||
|
||||
fun dismissCacheProgress() {
|
||||
context.notificationManager.cancel(Notifications.ID_DOWNLOAD_CACHE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,6 @@ object Notifications {
|
||||
const val ID_DOWNLOAD_CHAPTER_PROGRESS = -201
|
||||
const val CHANNEL_DOWNLOADER_ERROR = "downloader_error_channel"
|
||||
const val ID_DOWNLOAD_CHAPTER_ERROR = -202
|
||||
const val CHANNEL_DOWNLOADER_CACHE = "downloader_cache_renewal"
|
||||
const val ID_DOWNLOAD_CACHE = -204
|
||||
|
||||
/**
|
||||
* Notification channel and ids used by the library updater.
|
||||
@@ -91,6 +89,7 @@ object Notifications {
|
||||
"library_channel",
|
||||
"library_progress_channel",
|
||||
"updates_ext_channel",
|
||||
"downloader_cache_renewal",
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -155,12 +154,6 @@ object Notifications {
|
||||
setGroup(GROUP_DOWNLOADER)
|
||||
setShowBadge(false)
|
||||
},
|
||||
buildNotificationChannel(CHANNEL_DOWNLOADER_CACHE, IMPORTANCE_LOW) {
|
||||
setName(context.getString(R.string.channel_downloader_cache))
|
||||
setGroup(GROUP_DOWNLOADER)
|
||||
setShowBadge(false)
|
||||
setSound(null, null)
|
||||
},
|
||||
buildNotificationChannel(CHANNEL_BACKUP_RESTORE_PROGRESS, IMPORTANCE_LOW) {
|
||||
setName(context.getString(R.string.channel_progress))
|
||||
setGroup(GROUP_BACKUP_RESTORE)
|
||||
|
||||
Reference in New Issue
Block a user