diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt index 0ef6f99b8..26bd98f8b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt @@ -585,8 +585,7 @@ class DetailsActivity : private fun openReader(isIncognitoMode: Boolean) { val manga = viewModel.manga.value ?: return - val chapterId = viewModel.historyInfo.value.history?.chapterId - if (chapterId != null && manga.chapters?.none { x -> x.id == chapterId } == true) { + if (viewModel.historyInfo.value.isChapterMissing) { Snackbar.make(viewBinding.scrollView, R.string.chapter_is_missing, Snackbar.LENGTH_SHORT) .show() } else { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChaptersAdapter.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChaptersAdapter.kt index 8015787e2..5035401c2 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChaptersAdapter.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChaptersAdapter.kt @@ -1,25 +1,39 @@ package org.koitharu.kotatsu.details.ui.adapter import android.content.Context +import org.koitharu.kotatsu.core.model.formatNumber import org.koitharu.kotatsu.core.ui.BaseListAdapter import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.ui.list.fastscroll.FastScroller import org.koitharu.kotatsu.details.ui.model.ChapterListItem import org.koitharu.kotatsu.list.ui.adapter.ListItemType import org.koitharu.kotatsu.list.ui.adapter.listHeaderAD +import org.koitharu.kotatsu.list.ui.model.ListHeader import org.koitharu.kotatsu.list.ui.model.ListModel class ChaptersAdapter( private val onItemClickListener: OnListItemClickListener, ) : BaseListAdapter(), FastScroller.SectionIndexer { + private var hasVolumes = false + init { addDelegate(ListItemType.HEADER, listHeaderAD(null)) addDelegate(ListItemType.CHAPTER_LIST, chapterListItemAD(onItemClickListener)) addDelegate(ListItemType.CHAPTER_GRID, chapterGridItemAD(onItemClickListener)) } + override suspend fun emit(value: List?) { + super.emit(value) + hasVolumes = value != null && value.any { it is ListHeader } + } + 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 + } } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/HistoryInfo.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/HistoryInfo.kt index 2944168ec..079431a10 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/HistoryInfo.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/model/HistoryInfo.kt @@ -1,10 +1,7 @@ package org.koitharu.kotatsu.details.ui.model 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.parsers.model.Manga data class HistoryInfo( val totalChapters: Int, @@ -17,8 +14,8 @@ data class HistoryInfo( val isValid: Boolean get() = totalChapters >= 0 - val canContinue: Boolean - get() = history != null && !isChapterMissing + val canContinue + get() = currentChapter >= 0 } fun HistoryInfo( @@ -38,7 +35,7 @@ fun HistoryInfo( currentChapter = currentChapter, history = history, isIncognitoMode = isIncognitoMode, - isChapterMissing = currentChapter == -1, + isChapterMissing = history != null && manga?.isLoaded == true && manga.allChapters.none { it.id == history.chapterId }, canDownload = manga?.isLocal == false, ) }