Fix fast scroller NPE
This commit is contained in:
@@ -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>() {
|
||||
|
||||
Reference in New Issue
Block a user