Fix BrowseSourceScreen list/grid unnecessary reloads (#8661)
(cherry picked from commit 7be9b49143d4634478e42e245f927226ea762237) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt
This commit is contained in:
parent
988e2d5343
commit
b89c2f76a1
@ -64,9 +64,7 @@ data class SourceSearchScreen(
|
||||
},
|
||||
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
||||
) { paddingValues ->
|
||||
val mangaList = remember(state.currentFilter) {
|
||||
screenModel.getMangaListFlow(state.currentFilter)
|
||||
}.collectAsLazyPagingItems()
|
||||
val pagingFlow by screenModel.mangaPagerFlowFlow.collectAsState()
|
||||
val openMigrateDialog: (Manga) -> Unit = {
|
||||
// SY -->
|
||||
navigator.items
|
||||
@ -78,7 +76,7 @@ data class SourceSearchScreen(
|
||||
}
|
||||
BrowseSourceContent(
|
||||
source = screenModel.source,
|
||||
mangaList = mangaList,
|
||||
mangaList = pagingFlow.collectAsLazyPagingItems(),
|
||||
columns = screenModel.getColumnsPreference(LocalConfiguration.current.orientation),
|
||||
// SY -->
|
||||
ehentaiBrowseDisplayMode = screenModel.ehentaiBrowseDisplayMode,
|
||||
|
@ -203,13 +203,11 @@ data class BrowseSourceScreen(
|
||||
},
|
||||
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
||||
) { paddingValues ->
|
||||
val mangaList = remember(state.currentFilter) {
|
||||
screenModel.getMangaListFlow(state.currentFilter)
|
||||
}.collectAsLazyPagingItems()
|
||||
val pagingFlow by screenModel.mangaPagerFlowFlow.collectAsState()
|
||||
|
||||
BrowseSourceContent(
|
||||
source = screenModel.source,
|
||||
mangaList = mangaList,
|
||||
mangaList = pagingFlow.collectAsLazyPagingItems(),
|
||||
columns = screenModel.getColumnsPreference(LocalConfiguration.current.orientation),
|
||||
// SY -->
|
||||
ehentaiBrowseDisplayMode = screenModel.ehentaiBrowseDisplayMode,
|
||||
|
@ -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
|
||||
@ -83,8 +82,10 @@ import exh.savedsearches.models.SavedSearch
|
||||
import exh.source.getMainSource
|
||||
import exh.util.nullIfBlank
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@ -152,6 +153,35 @@ open 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),
|
||||
) {
|
||||
// SY -->
|
||||
createSourcePagingSource(currentFilter.query ?: "", currentFilter.filters)
|
||||
// SY <--
|
||||
}.flow
|
||||
.map { pagingData ->
|
||||
pagingData.map { (sManga, metadata) ->
|
||||
val dbManga = withIOContext { networkToLocalManga.await(sManga.toDomainManga(sourceId)) }
|
||||
getManga.subscribe(dbManga.url, dbManga.source)
|
||||
.filterNotNull()
|
||||
.onEach { initializeManga(it) }
|
||||
// SY -->
|
||||
.combineMetadata(dbManga, metadata)
|
||||
// SY <--
|
||||
.stateIn(coroutineScope)
|
||||
}
|
||||
}
|
||||
.cachedIn(coroutineScope)
|
||||
}
|
||||
.stateIn(coroutineScope, SharingStarted.Lazily, emptyFlow())
|
||||
|
||||
// SY -->
|
||||
val ehentaiBrowseDisplayMode by unsortedPreferences.enhancedEHentaiView().asState(coroutineScope)
|
||||
|
||||
@ -198,29 +228,6 @@ open class BrowseSourceScreenModel(
|
||||
return if (columns == 0) GridCells.Adaptive(128.dp) else GridCells.Fixed(columns)
|
||||
}
|
||||
|
||||
fun getMangaListFlow(currentFilter: Filter): Flow<PagingData<StateFlow</* SY --> */Pair<Manga, RaisedSearchMetadata?>/* SY <-- */>>> {
|
||||
return Pager(
|
||||
PagingConfig(pageSize = 25),
|
||||
) {
|
||||
// SY -->
|
||||
createSourcePagingSource(currentFilter.query ?: "", currentFilter.filters)
|
||||
// SY <--
|
||||
}.flow
|
||||
.map { pagingData ->
|
||||
pagingData.map { (sManga, metadata) ->
|
||||
val dbManga = withIOContext { networkToLocalManga.await(sManga.toDomainManga(sourceId)) }
|
||||
getManga.subscribe(dbManga.url, dbManga.source)
|
||||
.filterNotNull()
|
||||
.onEach { initializeManga(it) }
|
||||
// SY -->
|
||||
.combineMetadata(dbManga, metadata)
|
||||
// SY <--
|
||||
.stateIn(coroutineScope)
|
||||
}
|
||||
}
|
||||
.cachedIn(coroutineScope)
|
||||
}
|
||||
|
||||
// SY -->
|
||||
open fun Flow<Manga>.combineMetadata(dbManga: Manga, metadata: RaisedSearchMetadata?): Flow<Pair<Manga, RaisedSearchMetadata?>> {
|
||||
val metadataSource = source.getMainSource<MetadataSource<*, *>>()
|
||||
|
@ -54,13 +54,11 @@ class MangaDexFollowsScreen(private val sourceId: Long) : Screen {
|
||||
SnackbarHost(hostState = snackbarHostState)
|
||||
},
|
||||
) { paddingValues ->
|
||||
val mangaList = remember(state.currentFilter) {
|
||||
screenModel.getMangaListFlow(state.currentFilter)
|
||||
}.collectAsLazyPagingItems()
|
||||
val pagingFlow by screenModel.mangaPagerFlowFlow.collectAsState()
|
||||
|
||||
BrowseSourceContent(
|
||||
source = screenModel.source,
|
||||
mangaList = mangaList,
|
||||
mangaList = pagingFlow.collectAsLazyPagingItems(),
|
||||
columns = screenModel.getColumnsPreference(LocalConfiguration.current.orientation),
|
||||
// SY -->
|
||||
ehentaiBrowseDisplayMode = screenModel.ehentaiBrowseDisplayMode,
|
||||
|
@ -46,13 +46,11 @@ class MangaDexSimilarScreen(val mangaId: Long, val sourceId: Long) : Screen {
|
||||
},
|
||||
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
||||
) { paddingValues ->
|
||||
val mangaList = remember(state.currentFilter) {
|
||||
screenModel.getMangaListFlow(state.currentFilter)
|
||||
}.collectAsLazyPagingItems()
|
||||
val pagingFlow by screenModel.mangaPagerFlowFlow.collectAsState()
|
||||
|
||||
BrowseSourceContent(
|
||||
source = screenModel.source,
|
||||
mangaList = mangaList,
|
||||
mangaList = pagingFlow.collectAsLazyPagingItems(),
|
||||
columns = screenModel.getColumnsPreference(LocalConfiguration.current.orientation),
|
||||
// SY -->
|
||||
ehentaiBrowseDisplayMode = false,
|
||||
|
@ -45,13 +45,11 @@ class RecommendsScreen(val mangaId: Long, val sourceId: Long) : Screen {
|
||||
},
|
||||
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
||||
) { paddingValues ->
|
||||
val mangaList = remember(state.currentFilter) {
|
||||
screenModel.getMangaListFlow(state.currentFilter)
|
||||
}.collectAsLazyPagingItems()
|
||||
val pagingFlow by screenModel.mangaPagerFlowFlow.collectAsState()
|
||||
|
||||
BrowseSourceContent(
|
||||
source = screenModel.source,
|
||||
mangaList = mangaList,
|
||||
mangaList = pagingFlow.collectAsLazyPagingItems(),
|
||||
columns = screenModel.getColumnsPreference(LocalConfiguration.current.orientation),
|
||||
// SY -->
|
||||
ehentaiBrowseDisplayMode = false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user