Fix fast scroller NPE

This commit is contained in:
Koitharu
2023-01-04 13:26:18 +02:00
parent 656a707b4c
commit 571b85dfd8
4 changed files with 13 additions and 12 deletions

View File

@@ -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?
} }
} }

View File

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

View File

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

View File

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