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
This commit is contained in:
Ivan Iskandar 2022-07-29 18:47:09 +07:00 committed by GitHub
parent 56028aff55
commit 483b204fb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -300,6 +300,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(
@ -426,11 +427,14 @@ 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() }
val insetPadding = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal).asPaddingValues() val insetPadding = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal).asPaddingValues()
val (topBarHeight, onTopBarHeightChanged) = remember { mutableStateOf(0) } val (topBarHeight, onTopBarHeightChanged) = remember { mutableStateOf(0) }
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() },
@ -445,7 +449,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

@ -59,6 +59,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow 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.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
@ -171,6 +172,7 @@ class MangaPresenter(
} }
getMangaAndChapters.subscribe(mangaId) getMangaAndChapters.subscribe(mangaId)
.distinctUntilChanged()
.collectLatest { (manga, chapters) -> .collectLatest { (manga, chapters) ->
val chapterItems = chapters.toChapterItems( val chapterItems = chapters.toChapterItems(
context = view?.activity ?: Injekt.get<Application>(), context = view?.activity ?: Injekt.get<Application>(),