don't use debounce in trashy case
This commit is contained in:
+4
-6
@@ -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<SqlOfflineVideo>.toOfflineVideo(): Flow<List<OfflineVideo>> {
|
||||
return asFlow().mapToList(Dispatchers.IO)
|
||||
.flatMapLatest { items: List<SqlOfflineVideo> ->
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -56,7 +56,8 @@ class OfflineVideoInteractor(
|
||||
}
|
||||
)
|
||||
}
|
||||
} ?: emptyFlow()
|
||||
}
|
||||
?: emptyFlow()
|
||||
|
||||
suspend fun remove(video: OfflineVideo) {
|
||||
offlineStorage?.remove(video)
|
||||
|
||||
+1
-4
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user