don't use debounce in trashy case

This commit is contained in:
2026-06-23 20:11:48 +03:00
parent 16a78e8f6f
commit 11f0db9c0a
3 changed files with 7 additions and 11 deletions
@@ -13,10 +13,10 @@ import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.koin.core.annotation.Factory import org.koin.core.annotation.Factory
import ru.shadowsparky.vbox.domain.OfflineVideoQueries import ru.shadowsparky.vbox.domain.OfflineVideoQueries
@@ -44,15 +44,13 @@ class AndroidOfflineStorage(
private fun Query<SqlOfflineVideo>.toOfflineVideo(): Flow<List<OfflineVideo>> { private fun Query<SqlOfflineVideo>.toOfflineVideo(): Flow<List<OfflineVideo>> {
return asFlow().mapToList(Dispatchers.IO) return asFlow().mapToList(Dispatchers.IO)
.flatMapLatest { items: List<SqlOfflineVideo> -> .flatMapLatest { items: List<SqlOfflineVideo> ->
if (items.isEmpty()) return@flatMapLatest flowOf(emptyList())
combine( combine(
items.map { item -> items.map { item ->
downloader.query(item.download_id) downloader.query(item.download_id)
.mapNotNull { state -> .mapNotNull { state -> item.toDomain(state) }
if (state == null) remove(item.id)
item.toDomain(state)
} }
} ) { it.toList() }
) { it.toList() }.onStart { emit(emptyList()) }
}.flowOn(Dispatchers.IO) }.flowOn(Dispatchers.IO)
} }
@@ -56,7 +56,8 @@ class OfflineVideoInteractor(
} }
) )
} }
} ?: emptyFlow() }
?: emptyFlow()
suspend fun remove(video: OfflineVideo) { suspend fun remove(video: OfflineVideo) {
offlineStorage?.remove(video) offlineStorage?.remove(video)
@@ -1,8 +1,6 @@
package ru.shadowsparky.vbox.shared.presentation.offline package ru.shadowsparky.vbox.shared.presentation.offline
import com.arkivanov.decompose.ComponentContext import com.arkivanov.decompose.ComponentContext
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.koin.core.annotation.Factory import org.koin.core.annotation.Factory
import org.koin.core.annotation.Named import org.koin.core.annotation.Named
@@ -22,8 +20,7 @@ class OfflineVideoComponent(
private val showPlayer: (Route.Overview.Player) -> Unit, private val showPlayer: (Route.Overview.Player) -> Unit,
val onBack: () -> Unit val onBack: () -> Unit
) : ComponentContext by context { ) : ComponentContext by context {
@OptIn(FlowPreview::class) val info = interactor.info
val info = interactor.info.debounce(300)
private val componentScope = createComponentScope() private val componentScope = createComponentScope()
fun play(item: OfflineVideo) { fun play(item: OfflineVideo) {