From 483b204fb5b6790fb6fe59ffd80345cd484ca241 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Fri, 29 Jul 2022 18:47:09 +0700 Subject: [PATCH] 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 --- .../main/java/eu/kanade/presentation/manga/MangaScreen.kt | 5 ++++- .../main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt index 5dbc019c2a..269356de59 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt @@ -300,6 +300,7 @@ private fun MangaScreenSmallImpl( SwipeRefresh( state = rememberSwipeRefreshState(state.isRefreshingInfo || state.isRefreshingChapter), onRefresh = onRefresh, + swipeEnabled = !chapters.any { it.selected }, indicatorPadding = contentPadding, indicator = { s, trigger -> SwipeRefreshIndicator( @@ -426,11 +427,14 @@ fun MangaScreenLargeImpl( val layoutDirection = LocalLayoutDirection.current val density = LocalDensity.current + val chapters = remember(state) { state.processedChapters.toList() } + val insetPadding = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal).asPaddingValues() val (topBarHeight, onTopBarHeightChanged) = remember { mutableStateOf(0) } SwipeRefresh( state = rememberSwipeRefreshState(state.isRefreshingInfo || state.isRefreshingChapter), onRefresh = onRefresh, + swipeEnabled = !chapters.any { it.selected }, indicatorPadding = PaddingValues( start = insetPadding.calculateStartPadding(layoutDirection), top = with(density) { topBarHeight.toDp() }, @@ -445,7 +449,6 @@ fun MangaScreenLargeImpl( }, ) { val chapterListState = rememberLazyListState() - val chapters = remember(state) { state.processedChapters.toList() } val internalOnBackPressed = { if (chapters.any { it.selected }) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 2c9a0d1058..6b43533d92 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -59,6 +59,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map @@ -171,6 +172,7 @@ class MangaPresenter( } getMangaAndChapters.subscribe(mangaId) + .distinctUntilChanged() .collectLatest { (manga, chapters) -> val chapterItems = chapters.toChapterItems( context = view?.activity ?: Injekt.get(),