Fixed sorting chapters not updating properly

This commit is contained in:
Jay 2020-03-29 13:31:06 -04:00
parent e43be48074
commit 362a088367
3 changed files with 24 additions and 19 deletions

View File

@ -22,6 +22,7 @@ class MangaDetailsAdapter(
var items: List<ChapterItem> = emptyList()
private var isAnimating = false
val delegate: MangaDetailsInterface = controller
val readColor = context.getResourceColor(android.R.attr.textColorHint)
@ -42,18 +43,24 @@ class MangaDetailsAdapter(
return items.indexOf(item)
}
fun indexOf(chapterId: Long): Int {
return currentItems.indexOfFirst { it is ChapterItem && it.id == chapterId }
}
fun performFilter() {
val s = getFilter(String::class.java)
if (s.isNullOrBlank()) {
updateDataSet(items, itemCount != 0)
updateDataSet(items, isAnimating)
} else {
updateDataSet(items.filter { it.name.contains(s, true) ||
it.scanlator?.contains(s, true) == true }, itemCount != 0)
it.scanlator?.contains(s, true) == true }, isAnimating)
}
isAnimating = false
}
override fun onItemSwiped(position: Int, direction: Int) {
super.onItemSwiped(position, direction)
isAnimating = true
when (direction) {
ItemTouchHelper.RIGHT -> controller.bookmarkChapter(position)
ItemTouchHelper.LEFT -> controller.toggleReadChapter(position)

View File

@ -29,6 +29,7 @@ import eu.kanade.tachiyomi.ui.manga.track.TrackItem
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
import eu.kanade.tachiyomi.util.storage.DiskUtil
import eu.kanade.tachiyomi.util.system.executeOnIO
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@ -105,9 +106,7 @@ class MangaDetailsPresenter(
}
private suspend fun getChapters() {
val chapters = withContext(Dispatchers.IO) {
db.getChapters(manga).executeAsBlocking().map { it.toModel() }
}
val chapters = db.getChapters(manga).executeOnIO().map { it.toModel() }
// Find downloaded chapters
setDownloadedChapters(chapters)
@ -472,9 +471,7 @@ class MangaDetailsPresenter(
private fun asyncUpdateMangaAndChapters(justChapters: Boolean = false) {
scope.launch {
if (!justChapters) withContext(Dispatchers.IO) {
db.updateFlags(manga).executeAsBlocking()
}
if (!justChapters) db.updateFlags(manga).executeOnIO()
updateChapters()
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
}

View File

@ -77,6 +77,7 @@ class ChapterHolder(
statuses.add(chapter.scanlator!!)
}
if (front_view.translationX == 0f) {
read.setImageDrawable(
ContextCompat.getDrawable(
read.context, if (item.read) R.drawable.eye_off
@ -89,7 +90,7 @@ class ChapterHolder(
else R.drawable.star
)
)
}
chapter_scanlator.setTextColor(if (chapter.read) adapter.readColor else adapter.unreadColor)
chapter_scanlator.text = statuses.joinToString("")
notifyStatus(