Fix details read/continue state
parent
4f82495cfc
commit
e42aeb857f
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue