Fix details read/continue state

This commit is contained in:
Koitharu
2024-05-08 14:23:04 +03:00
parent 4f82495cfc
commit e42aeb857f
3 changed files with 19 additions and 9 deletions

View File

@@ -585,8 +585,7 @@ class DetailsActivity :
private fun openReader(isIncognitoMode: Boolean) { private fun openReader(isIncognitoMode: Boolean) {
val manga = viewModel.manga.value ?: return val manga = viewModel.manga.value ?: return
val chapterId = viewModel.historyInfo.value.history?.chapterId if (viewModel.historyInfo.value.isChapterMissing) {
if (chapterId != null && manga.chapters?.none { x -> x.id == chapterId } == true) {
Snackbar.make(viewBinding.scrollView, R.string.chapter_is_missing, Snackbar.LENGTH_SHORT) Snackbar.make(viewBinding.scrollView, R.string.chapter_is_missing, Snackbar.LENGTH_SHORT)
.show() .show()
} else { } else {

View File

@@ -1,25 +1,39 @@
package org.koitharu.kotatsu.details.ui.adapter package org.koitharu.kotatsu.details.ui.adapter
import android.content.Context import android.content.Context
import org.koitharu.kotatsu.core.model.formatNumber
import org.koitharu.kotatsu.core.ui.BaseListAdapter import org.koitharu.kotatsu.core.ui.BaseListAdapter
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
import org.koitharu.kotatsu.core.ui.list.fastscroll.FastScroller import org.koitharu.kotatsu.core.ui.list.fastscroll.FastScroller
import org.koitharu.kotatsu.details.ui.model.ChapterListItem import org.koitharu.kotatsu.details.ui.model.ChapterListItem
import org.koitharu.kotatsu.list.ui.adapter.ListItemType import org.koitharu.kotatsu.list.ui.adapter.ListItemType
import org.koitharu.kotatsu.list.ui.adapter.listHeaderAD import org.koitharu.kotatsu.list.ui.adapter.listHeaderAD
import org.koitharu.kotatsu.list.ui.model.ListHeader
import org.koitharu.kotatsu.list.ui.model.ListModel import org.koitharu.kotatsu.list.ui.model.ListModel
class ChaptersAdapter( class ChaptersAdapter(
private val onItemClickListener: OnListItemClickListener<ChapterListItem>, private val onItemClickListener: OnListItemClickListener<ChapterListItem>,
) : BaseListAdapter<ListModel>(), FastScroller.SectionIndexer { ) : BaseListAdapter<ListModel>(), FastScroller.SectionIndexer {
private var hasVolumes = false
init { init {
addDelegate(ListItemType.HEADER, listHeaderAD(null)) addDelegate(ListItemType.HEADER, listHeaderAD(null))
addDelegate(ListItemType.CHAPTER_LIST, chapterListItemAD(onItemClickListener)) addDelegate(ListItemType.CHAPTER_LIST, chapterListItemAD(onItemClickListener))
addDelegate(ListItemType.CHAPTER_GRID, chapterGridItemAD(onItemClickListener)) addDelegate(ListItemType.CHAPTER_GRID, chapterGridItemAD(onItemClickListener))
} }
override suspend fun emit(value: List<ListModel>?) {
super.emit(value)
hasVolumes = value != null && value.any { it is ListHeader }
}
override fun getSectionText(context: Context, position: Int): CharSequence? { override fun getSectionText(context: Context, position: Int): CharSequence? {
return findHeader(position)?.getText(context) return if (hasVolumes) {
findHeader(position)?.getText(context)
} else {
val chapter = (items.getOrNull(position) as? ChapterListItem)?.chapter ?: return null
if (chapter.number > 0) chapter.formatNumber() else null
}
} }
} }

View File

@@ -1,10 +1,7 @@
package org.koitharu.kotatsu.details.ui.model package org.koitharu.kotatsu.details.ui.model
import org.koitharu.kotatsu.core.model.MangaHistory import org.koitharu.kotatsu.core.model.MangaHistory
import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.core.model.isLocal
import org.koitharu.kotatsu.details.data.MangaDetails import org.koitharu.kotatsu.details.data.MangaDetails
import org.koitharu.kotatsu.parsers.model.Manga
data class HistoryInfo( data class HistoryInfo(
val totalChapters: Int, val totalChapters: Int,
@@ -17,8 +14,8 @@ data class HistoryInfo(
val isValid: Boolean val isValid: Boolean
get() = totalChapters >= 0 get() = totalChapters >= 0
val canContinue: Boolean val canContinue
get() = history != null && !isChapterMissing get() = currentChapter >= 0
} }
fun HistoryInfo( fun HistoryInfo(
@@ -38,7 +35,7 @@ fun HistoryInfo(
currentChapter = currentChapter, currentChapter = currentChapter,
history = history, history = history,
isIncognitoMode = isIncognitoMode, isIncognitoMode = isIncognitoMode,
isChapterMissing = currentChapter == -1, isChapterMissing = history != null && manga?.isLoaded == true && manga.allChapters.none { it.id == history.chapterId },
canDownload = manga?.isLocal == false, canDownload = manga?.isLocal == false,
) )
} }