diff --git a/apps/vbox/client/shared/src/androidMain/kotlin/ru/shadowsparky/vbox/shared/data/AndroidOfflineStorage.kt b/apps/vbox/client/shared/src/androidMain/kotlin/ru/shadowsparky/vbox/shared/data/AndroidOfflineStorage.kt index e00d624..7968ce9 100644 --- a/apps/vbox/client/shared/src/androidMain/kotlin/ru/shadowsparky/vbox/shared/data/AndroidOfflineStorage.kt +++ b/apps/vbox/client/shared/src/androidMain/kotlin/ru/shadowsparky/vbox/shared/data/AndroidOfflineStorage.kt @@ -13,10 +13,10 @@ import kotlinx.coroutines.flow.emitAll import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapNotNull -import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.withContext import org.koin.core.annotation.Factory import ru.shadowsparky.vbox.domain.OfflineVideoQueries @@ -44,15 +44,13 @@ class AndroidOfflineStorage( private fun Query.toOfflineVideo(): Flow> { return asFlow().mapToList(Dispatchers.IO) .flatMapLatest { items: List -> + if (items.isEmpty()) return@flatMapLatest flowOf(emptyList()) combine( items.map { item -> downloader.query(item.download_id) - .mapNotNull { state -> - if (state == null) remove(item.id) - item.toDomain(state) - } + .mapNotNull { state -> item.toDomain(state) } } - ) { it.toList() }.onStart { emit(emptyList()) } + ) { it.toList() } }.flowOn(Dispatchers.IO) } diff --git a/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/domain/OfflineVideoInteractor.kt b/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/domain/OfflineVideoInteractor.kt index 65b4241..120453a 100644 --- a/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/domain/OfflineVideoInteractor.kt +++ b/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/domain/OfflineVideoInteractor.kt @@ -56,7 +56,8 @@ class OfflineVideoInteractor( } ) } - } ?: emptyFlow() + } + ?: emptyFlow() suspend fun remove(video: OfflineVideo) { offlineStorage?.remove(video) diff --git a/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/presentation/offline/OfflineVideoComponent.kt b/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/presentation/offline/OfflineVideoComponent.kt index cfa1a9b..1cf4aab 100644 --- a/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/presentation/offline/OfflineVideoComponent.kt +++ b/apps/vbox/client/shared/src/commonMain/kotlin/ru/shadowsparky/vbox/shared/presentation/offline/OfflineVideoComponent.kt @@ -1,8 +1,6 @@ package ru.shadowsparky.vbox.shared.presentation.offline import com.arkivanov.decompose.ComponentContext -import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.launch import org.koin.core.annotation.Factory import org.koin.core.annotation.Named @@ -22,8 +20,7 @@ class OfflineVideoComponent( private val showPlayer: (Route.Overview.Player) -> Unit, val onBack: () -> Unit ) : ComponentContext by context { - @OptIn(FlowPreview::class) - val info = interactor.info.debounce(300) + val info = interactor.info private val componentScope = createComponentScope() fun play(item: OfflineVideo) {