SectionedDataSource.getItem can return null

pull/1149/head
Alex Baker 5 years ago
parent a4639cb18c
commit 339b4661c7

@ -18,7 +18,7 @@ internal class DiffCallback(private val old: SectionedDataSource, private val ne
return if (isHeader) { return if (isHeader) {
old.sortMode == new.sortMode && old.getHeaderValue(oldPosition) == new.getHeaderValue(newPosition) old.sortMode == new.sortMode && old.getHeaderValue(oldPosition) == new.getHeaderValue(newPosition)
} else { } else {
old.getItem(oldPosition).id == new.getItem(newPosition).id old.getItem(oldPosition)!!.id == new.getItem(newPosition)!!.id
} }
} }
@ -26,8 +26,8 @@ internal class DiffCallback(private val old: SectionedDataSource, private val ne
if (new.isHeader(newPosition)) { if (new.isHeader(newPosition)) {
return old.getSection(oldPosition).collapsed == new.getSection(newPosition).collapsed return old.getSection(oldPosition).collapsed == new.getSection(newPosition).collapsed
} }
val oldItem = old.getItem(oldPosition) val oldItem = old.getItem(oldPosition)!!
val newItem = new.getItem(newPosition) val newItem = new.getItem(newPosition)!!
return oldItem == newItem && oldItem.getIndent() == adapter.getIndent(newItem) return oldItem == newItem && oldItem.getIndent() == adapter.getIndent(newItem)
} }
} }

@ -6,8 +6,12 @@ import org.tasks.data.TaskContainer
import org.tasks.date.DateTimeUtils import org.tasks.date.DateTimeUtils
import java.util.* import java.util.*
class SectionedDataSource constructor(tasks: List<TaskContainer>, disableHeaders: Boolean, val sortMode: Int, private val collapsed: MutableSet<Long>) { class SectionedDataSource constructor(
tasks: List<TaskContainer>,
disableHeaders: Boolean,
val sortMode: Int,
private val collapsed: MutableSet<Long>
) {
private val tasks = tasks.toMutableList() private val tasks = tasks.toMutableList()
private val sections = if (disableHeaders) { private val sections = if (disableHeaders) {
@ -16,9 +20,9 @@ class SectionedDataSource constructor(tasks: List<TaskContainer>, disableHeaders
getSections() getSections()
} }
fun getItem(position: Int): TaskContainer = tasks[sectionedPositionToPosition(position)] fun getItem(position: Int): TaskContainer? = tasks.getOrNull(sectionedPositionToPosition(position))
fun getHeaderValue(position: Int): Long = sections[position]!!.value fun getHeaderValue(position: Int): Long = getSection(position).value
fun isHeader(position: Int) = sections[position] != null fun isHeader(position: Int) = sections[position] != null

@ -89,10 +89,7 @@ internal class ScrollableViewsFactory(
return 1 return 1
} }
override fun getItemId(position: Int): Long { override fun getItemId(position: Int) = getTask(position)?.id ?: 0
val task = getTask(position)
return task?.id ?: 0
}
override fun hasStableIds(): Boolean { override fun hasStableIds(): Boolean {
return true return true
@ -208,9 +205,7 @@ internal class ScrollableViewsFactory(
return null return null
} }
private fun getTask(position: Int): TaskContainer? { private fun getTask(position: Int): TaskContainer? = tasks.getItem(position)
return if (position < tasks.size) tasks[position] else null
}
private suspend fun getQuery(filter: Filter?, subtasks: SubtaskInfo): List<String> { private suspend fun getQuery(filter: Filter?, subtasks: SubtaskInfo): List<String> {
val queries = getQuery(preferences, filter!!, subtasks) val queries = getQuery(preferences, filter!!, subtasks)

Loading…
Cancel
Save