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) {
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 {

View File

@@ -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<ChapterListItem>,
) : BaseListAdapter<ListModel>(), 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<ListModel>?) {
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
}
}
}

View File

@@ -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,
)
}