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 { 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 { override fun getSectionText(context: Context, position: Int): CharSequence? {
return items[position].chapter.number.toString() val item = items.getOrNull(position) ?: return null
return item.chapter.number.toString()
} }
} }

@ -14,14 +14,14 @@ class HistoryListAdapter(
listener: MangaListListener listener: MangaListListener
) : MangaListAdapter(coil, lifecycleOwner, listener), FastScroller.SectionIndexer { ) : 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 val list = items
for (i in (0..position).reversed()) { for (i in (0..position).reversed()) {
val item = list[i] val item = list.getOrNull(i) ?: continue
if (item is DateTimeAgo) { if (item is DateTimeAgo) {
return item.format(context.resources) return item.format(context.resources)
} }
} }
return "" return null
} }
} }

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

Loading…
Cancel
Save