MangaPresenter: Add distinctUntilChanged to db flow (#7629)

* MangaScreen: Disable swipe refresh on action mode

* MangaPresenter: Add distinctUntilChanged to db flow

Now will only emit update when the related entry is changed

(cherry picked from commit 483b204fb5b6790fb6fe59ffd80345cd484ca241)

# Conflicts:
#	app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt
This commit is contained in:
Ivan Iskandar 2022-07-29 18:47:09 +07:00 committed by Jobobby04
parent b592709630
commit b368a53670
2 changed files with 18 additions and 5 deletions

View File

@ -354,6 +354,7 @@ private fun MangaScreenSmallImpl(
SwipeRefresh( SwipeRefresh(
state = rememberSwipeRefreshState(state.isRefreshingInfo || state.isRefreshingChapter), state = rememberSwipeRefreshState(state.isRefreshingInfo || state.isRefreshingChapter),
onRefresh = onRefresh, onRefresh = onRefresh,
swipeEnabled = !chapters.any { it.selected },
indicatorPadding = contentPadding, indicatorPadding = contentPadding,
indicator = { s, trigger -> indicator = { s, trigger ->
SwipeRefreshIndicator( SwipeRefreshIndicator(
@ -538,6 +539,8 @@ fun MangaScreenLargeImpl(
val layoutDirection = LocalLayoutDirection.current val layoutDirection = LocalLayoutDirection.current
val density = LocalDensity.current val density = LocalDensity.current
val chapters = remember(state) { state.processedChapters.toList() }
// SY --> // SY -->
val metadataSource = remember(state.source.id) { state.source.getMainSource<MetadataSource<*, *>>() } val metadataSource = remember(state.source.id) { state.source.getMainSource<MetadataSource<*, *>>() }
// SY <-- // SY <--
@ -547,6 +550,7 @@ fun MangaScreenLargeImpl(
SwipeRefresh( SwipeRefresh(
state = rememberSwipeRefreshState(state.isRefreshingInfo || state.isRefreshingChapter), state = rememberSwipeRefreshState(state.isRefreshingInfo || state.isRefreshingChapter),
onRefresh = onRefresh, onRefresh = onRefresh,
swipeEnabled = !chapters.any { it.selected },
indicatorPadding = PaddingValues( indicatorPadding = PaddingValues(
start = insetPadding.calculateStartPadding(layoutDirection), start = insetPadding.calculateStartPadding(layoutDirection),
top = with(density) { topBarHeight.toDp() }, top = with(density) { topBarHeight.toDp() },
@ -561,7 +565,6 @@ fun MangaScreenLargeImpl(
}, },
) { ) {
val chapterListState = rememberLazyListState() val chapterListState = rememberLazyListState()
val chapters = remember(state) { state.processedChapters.toList() }
val internalOnBackPressed = { val internalOnBackPressed = {
if (chapters.any { it.selected }) { if (chapters.any { it.selected }) {

View File

@ -99,6 +99,7 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
@ -257,8 +258,12 @@ class MangaPresenter(
} }
getMangaAndChapters.subscribe(mangaId) getMangaAndChapters.subscribe(mangaId)
.distinctUntilChanged()
// SY --> // SY -->
.combine(getMergedChapterByMangaId.subscribe(mangaId)) { (manga, chapters), mergedChapters -> .combine(
getMergedChapterByMangaId.subscribe(mangaId)
.distinctUntilChanged(),
) { (manga, chapters), mergedChapters ->
if (manga.source == MERGED_SOURCE_ID) { if (manga.source == MERGED_SOURCE_ID) {
manga to mergedChapters manga to mergedChapters
} else manga to chapters } else manga to chapters
@ -287,13 +292,18 @@ class MangaPresenter(
} }
allChapterScanlators = chapters.flatMap { MdUtil.getScanlators(it.scanlator) }.distinct() allChapterScanlators = chapters.flatMap { MdUtil.getScanlators(it.scanlator) }.distinct()
} }
.combine(getFlatMetadata.subscribe(mangaId)) { pair, flatMetadata -> .combine(
getFlatMetadata.subscribe(mangaId)
.distinctUntilChanged(),
) { pair, flatMetadata ->
CombineState(pair, flatMetadata) CombineState(pair, flatMetadata)
} }
.combine( .combine(
combine( combine(
getMergedMangaById.subscribe(mangaId), getMergedMangaById.subscribe(mangaId)
getMergedReferencesById.subscribe(mangaId), .distinctUntilChanged(),
getMergedReferencesById.subscribe(mangaId)
.distinctUntilChanged(),
) { manga, references -> ) { manga, references ->
if (manga.isNotEmpty()) { if (manga.isNotEmpty()) {
val sourceManager = Injekt.get<SourceManager>() val sourceManager = Injekt.get<SourceManager>()