Ver Fonte

Adjust manga FAB to only say "Start" if there's no unread chapters in unfiltered list

Closes #9479
arkon há 1 ano atrás
pai
commit
cf3f2d0380

+ 4 - 4
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

+ 6 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt

@@ -119,7 +119,7 @@ class MangaInfoScreenModel(
     private val allChapters: List<ChapterItem>?
         get() = successState?.chapters
 
-    private val filteredChapters: Sequence<ChapterItem>?
+    private val filteredChapters: List<ChapterItem>?
         get() = successState?.processedChapters
 
     val chapterSwipeEndAction = libraryPreferences.swipeEndAction().get()
@@ -576,7 +576,7 @@ class MangaInfoScreenModel(
     }
 
     private fun getUnreadChapters(): List<Chapter> {
-        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<ChapterItem>
-            get() = chapters.applyFilters(manga)
+        val processedChapters by lazy {
+            chapters.applyFilters(manga).toList()
+        }
 
         val trackingAvailable: Boolean
             get() = trackItems.isNotEmpty()