Fix checking downloads banner showing up incorrectly
This commit is contained in:
parent
58ebf14691
commit
5b5eb92184
@ -21,17 +21,15 @@ import kotlinx.coroutines.async
|
|||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.flow.receiveAsFlow
|
import kotlinx.coroutines.flow.receiveAsFlow
|
||||||
import kotlinx.coroutines.flow.shareIn
|
import kotlinx.coroutines.flow.shareIn
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.flow.take
|
|
||||||
import kotlinx.coroutines.withTimeout
|
import kotlinx.coroutines.withTimeout
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
@ -72,10 +70,9 @@ class DownloadCache(
|
|||||||
*/
|
*/
|
||||||
private var lastRenew = 0L
|
private var lastRenew = 0L
|
||||||
private var renewalJob: Job? = null
|
private var renewalJob: Job? = null
|
||||||
val isRenewing = changes
|
|
||||||
.map { renewalJob?.isActive ?: false }
|
private val _isInitializing = MutableStateFlow(false)
|
||||||
.distinctUntilChanged()
|
val isInitializing = _isInitializing
|
||||||
.take(2) // We only care about initial renewal
|
|
||||||
.debounce(1000L) // Don't notify if it finishes quickly enough
|
.debounce(1000L) // Don't notify if it finishes quickly enough
|
||||||
.stateIn(scope, SharingStarted.WhileSubscribed(), false)
|
.stateIn(scope, SharingStarted.WhileSubscribed(), false)
|
||||||
|
|
||||||
@ -272,6 +269,10 @@ class DownloadCache(
|
|||||||
}
|
}
|
||||||
|
|
||||||
renewalJob = scope.launchIO {
|
renewalJob = scope.launchIO {
|
||||||
|
if (lastRenew == 0L) {
|
||||||
|
_isInitializing.emit(true)
|
||||||
|
}
|
||||||
|
|
||||||
var sources = getSources()
|
var sources = getSources()
|
||||||
|
|
||||||
// Try to wait until extensions and sources have loaded
|
// Try to wait until extensions and sources have loaded
|
||||||
@ -326,6 +327,8 @@ class DownloadCache(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.awaitAll()
|
.awaitAll()
|
||||||
|
|
||||||
|
_isInitializing.emit(false)
|
||||||
}.also {
|
}.also {
|
||||||
it.invokeOnCompletion(onCancelling = true) { exception ->
|
it.invokeOnCompletion(onCancelling = true) { exception ->
|
||||||
if (exception != null && exception !is CancellationException) {
|
if (exception != null && exception !is CancellationException) {
|
||||||
|
@ -162,7 +162,7 @@ class MainActivity : BaseActivity() {
|
|||||||
setComposeContent {
|
setComposeContent {
|
||||||
val incognito by preferences.incognitoMode().collectAsState()
|
val incognito by preferences.incognitoMode().collectAsState()
|
||||||
val downloadOnly by preferences.downloadedOnly().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
|
// Set statusbar color considering the top app state banner
|
||||||
val systemUiController = rememberSystemUiController()
|
val systemUiController = rememberSystemUiController()
|
||||||
|
Loading…
Reference in New Issue
Block a user