|
@@ -9,7 +9,6 @@ import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.paging.Pager
|
|
|
import androidx.paging.PagingConfig
|
|
|
-import androidx.paging.PagingData
|
|
|
import androidx.paging.cachedIn
|
|
|
import androidx.paging.map
|
|
|
import cafe.adriel.voyager.core.model.StateScreenModel
|
|
@@ -64,8 +63,9 @@ import eu.kanade.tachiyomi.util.lang.withIOContext
|
|
|
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
|
|
|
import eu.kanade.tachiyomi.util.removeCovers
|
|
|
import eu.kanade.tachiyomi.util.system.logcat
|
|
|
-import kotlinx.coroutines.flow.Flow
|
|
|
-import kotlinx.coroutines.flow.StateFlow
|
|
|
+import kotlinx.coroutines.flow.SharingStarted
|
|
|
+import kotlinx.coroutines.flow.distinctUntilChanged
|
|
|
+import kotlinx.coroutines.flow.emptyFlow
|
|
|
import kotlinx.coroutines.flow.filterNotNull
|
|
|
import kotlinx.coroutines.flow.firstOrNull
|
|
|
import kotlinx.coroutines.flow.map
|
|
@@ -114,6 +114,30 @@ class BrowseSourceScreenModel(
|
|
|
*/
|
|
|
private var filterSheet: SourceFilterSheet? = null
|
|
|
|
|
|
+ /**
|
|
|
+ * Flow of Pager flow tied to [State.currentFilter]
|
|
|
+ */
|
|
|
+ val mangaPagerFlowFlow = state.map { it.currentFilter }
|
|
|
+ .distinctUntilChanged()
|
|
|
+ .map { currentFilter ->
|
|
|
+ Pager(
|
|
|
+ PagingConfig(pageSize = 25),
|
|
|
+ ) {
|
|
|
+ getRemoteManga.subscribe(sourceId, currentFilter.query ?: "", currentFilter.filters)
|
|
|
+ }.flow
|
|
|
+ .map { pagingData ->
|
|
|
+ pagingData.map { sManga ->
|
|
|
+ val dbManga = withIOContext { networkToLocalManga.await(sManga.toDomainManga(sourceId)) }
|
|
|
+ getManga.subscribe(dbManga.url, dbManga.source)
|
|
|
+ .filterNotNull()
|
|
|
+ .onEach { initializeManga(it) }
|
|
|
+ .stateIn(coroutineScope)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .cachedIn(coroutineScope)
|
|
|
+ }
|
|
|
+ .stateIn(coroutineScope, SharingStarted.Lazily, emptyFlow())
|
|
|
+
|
|
|
init {
|
|
|
mutableState.update { it.copy(filters = source.getFilterList()) }
|
|
|
}
|
|
@@ -128,24 +152,6 @@ class BrowseSourceScreenModel(
|
|
|
return if (columns == 0) GridCells.Adaptive(128.dp) else GridCells.Fixed(columns)
|
|
|
}
|
|
|
|
|
|
- fun getMangaListFlow(currentFilter: Filter): Flow<PagingData<StateFlow<Manga>>> {
|
|
|
- return Pager(
|
|
|
- PagingConfig(pageSize = 25),
|
|
|
- ) {
|
|
|
- getRemoteManga.subscribe(sourceId, currentFilter.query ?: "", currentFilter.filters)
|
|
|
- }.flow
|
|
|
- .map { pagingData ->
|
|
|
- pagingData.map { sManga ->
|
|
|
- val dbManga = withIOContext { networkToLocalManga.await(sManga.toDomainManga(sourceId)) }
|
|
|
- getManga.subscribe(dbManga.url, dbManga.source)
|
|
|
- .filterNotNull()
|
|
|
- .onEach { initializeManga(it) }
|
|
|
- .stateIn(coroutineScope)
|
|
|
- }
|
|
|
- }
|
|
|
- .cachedIn(coroutineScope)
|
|
|
- }
|
|
|
-
|
|
|
fun reset() {
|
|
|
mutableState.update { it.copy(filters = source.getFilterList()) }
|
|
|
}
|