From cf3f2d0380e5ab70211e6aab3f45bc81da43fcf4 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 7 Jul 2023 17:57:29 -0400 Subject: [PATCH] Adjust manga FAB to only say "Start" if there's no unread chapters in unfiltered list Closes #9479 --- .../java/eu/kanade/presentation/manga/MangaScreen.kt | 8 ++++---- .../eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) 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 74d89ebc2a..c0c2b3f6aa 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt @@ -258,7 +258,7 @@ private fun MangaScreenSmallImpl( ) { val chapterListState = rememberLazyListState() - val chapters = remember(state) { state.processedChapters.toList() } + val chapters = remember(state) { state.processedChapters } val internalOnBackPressed = { if (chapters.fastAny { it.selected }) { @@ -320,7 +320,7 @@ private fun MangaScreenSmallImpl( ) { ExtendedFloatingActionButton( text = { - val id = if (chapters.fastAny { it.chapter.read }) { + val id = if (state.chapters.fastAny { it.chapter.read }) { R.string.action_resume } else { R.string.action_start @@ -485,7 +485,7 @@ fun MangaScreenLargeImpl( val layoutDirection = LocalLayoutDirection.current val density = LocalDensity.current - val chapters = remember(state) { state.processedChapters.toList() } + val chapters = remember(state) { state.processedChapters } val insetPadding = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal).asPaddingValues() var topBarHeight by remember { mutableIntStateOf(0) } @@ -555,7 +555,7 @@ fun MangaScreenLargeImpl( ) { ExtendedFloatingActionButton( text = { - val id = if (chapters.fastAny { it.chapter.read }) { + val id = if (state.chapters.fastAny { it.chapter.read }) { R.string.action_resume } else { R.string.action_start diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index a731e48a55..98e4338d3c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -119,7 +119,7 @@ class MangaInfoScreenModel( private val allChapters: List? get() = successState?.chapters - private val filteredChapters: Sequence? + private val filteredChapters: List? get() = successState?.processedChapters val chapterSwipeEndAction = libraryPreferences.swipeEndAction().get() @@ -576,7 +576,7 @@ class MangaInfoScreenModel( } private fun getUnreadChapters(): List { - val chapterItems = if (skipFiltered) filteredChapters.orEmpty().toList() else allChapters.orEmpty() + val chapterItems = if (skipFiltered) filteredChapters.orEmpty() else allChapters.orEmpty() return chapterItems .filter { (chapter, dlStatus) -> !chapter.read && dlStatus == Download.State.NOT_DOWNLOADED } .map { it.chapter } @@ -664,7 +664,7 @@ class MangaInfoScreenModel( fun markPreviousChapterRead(pointer: Chapter) { val successState = successState ?: return - val chapters = filteredChapters.orEmpty().map { it.chapter }.toList() + val chapters = filteredChapters.orEmpty().map { it.chapter } val prevChapters = if (successState.manga.sortDescending()) chapters.asReversed() else chapters val pointerPos = prevChapters.indexOf(pointer) if (pointerPos != -1) markChaptersRead(prevChapters.take(pointerPos), true) @@ -987,8 +987,9 @@ sealed class MangaScreenState { val hasPromptedToAddBefore: Boolean = false, ) : MangaScreenState() { - val processedChapters: Sequence - get() = chapters.applyFilters(manga) + val processedChapters by lazy { + chapters.applyFilters(manga).toList() + } val trackingAvailable: Boolean get() = trackItems.isNotEmpty()