diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt index 1802a2da1..417b71c3b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt @@ -21,17 +21,15 @@ import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.debounce -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.flow.take import kotlinx.coroutines.withTimeout import logcat.LogPriority import uy.kohesive.injekt.Injekt @@ -72,10 +70,9 @@ class DownloadCache( */ private var lastRenew = 0L private var renewalJob: Job? = null - val isRenewing = changes - .map { renewalJob?.isActive ?: false } - .distinctUntilChanged() - .take(2) // We only care about initial renewal + + private val _isInitializing = MutableStateFlow(false) + val isInitializing = _isInitializing .debounce(1000L) // Don't notify if it finishes quickly enough .stateIn(scope, SharingStarted.WhileSubscribed(), false) @@ -272,6 +269,10 @@ class DownloadCache( } renewalJob = scope.launchIO { + if (lastRenew == 0L) { + _isInitializing.emit(true) + } + var sources = getSources() // Try to wait until extensions and sources have loaded @@ -326,6 +327,8 @@ class DownloadCache( } } .awaitAll() + + _isInitializing.emit(false) }.also { it.invokeOnCompletion(onCancelling = true) { exception -> if (exception != null && exception !is CancellationException) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index de78bea61..a6b45fe13 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -162,7 +162,7 @@ class MainActivity : BaseActivity() { setComposeContent { val incognito by preferences.incognitoMode().collectAsState() val downloadOnly by preferences.downloadedOnly().collectAsState() - val indexing by downloadCache.isRenewing.collectAsState() + val indexing by downloadCache.isInitializing.collectAsState() // Set statusbar color considering the top app state banner val systemUiController = rememberSystemUiController()