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 74d89ebc2..c0c2b3f6a 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 a731e48a5..98e4338d3 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()