Fix fast scroller NPE

pull/293/head
Koitharu 3 years ago
parent 656a707b4c
commit 571b85dfd8
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -516,6 +516,6 @@ class FastScroller @JvmOverloads constructor(
interface SectionIndexer {
fun getSectionText(context: Context, position: Int): CharSequence
fun getSectionText(context: Context, position: Int): CharSequence?
}
}
}

@ -42,7 +42,8 @@ class ChaptersAdapter(
}
}
override fun getSectionText(context: Context, position: Int): CharSequence {
return items[position].chapter.number.toString()
override fun getSectionText(context: Context, position: Int): CharSequence? {
val item = items.getOrNull(position) ?: return null
return item.chapter.number.toString()
}
}
}

@ -14,14 +14,14 @@ class HistoryListAdapter(
listener: MangaListListener
) : MangaListAdapter(coil, lifecycleOwner, listener), FastScroller.SectionIndexer {
override fun getSectionText(context: Context, position: Int): CharSequence {
override fun getSectionText(context: Context, position: Int): CharSequence? {
val list = items
for (i in (0..position).reversed()) {
val item = list[i]
val item = list.getOrNull(i) ?: continue
if (item is DateTimeAgo) {
return item.format(context.resources)
}
}
return ""
return null
}
}
}

@ -46,9 +46,9 @@ class ShelfAdapter(
.addDelegate(errorStateListAD(listener))
}
override fun getSectionText(context: Context, position: Int): CharSequence {
val item = items.getOrNull(position) as? ShelfSectionModel
return item?.getTitle(context.resources) ?: ""
override fun getSectionText(context: Context, position: Int): CharSequence? {
val item = items.getOrNull(position) as? ShelfSectionModel ?: return null
return item.getTitle(context.resources)
}
private class DiffCallback : DiffUtil.ItemCallback<ListModel>() {

Loading…
Cancel
Save