diff --git a/app/src/main/java/org/tasks/tasklist/DiffCallback.kt b/app/src/main/java/org/tasks/tasklist/DiffCallback.kt index 62e651366..50b6284be 100644 --- a/app/src/main/java/org/tasks/tasklist/DiffCallback.kt +++ b/app/src/main/java/org/tasks/tasklist/DiffCallback.kt @@ -18,7 +18,7 @@ internal class DiffCallback(private val old: SectionedDataSource, private val ne return if (isHeader) { old.sortMode == new.sortMode && old.getHeaderValue(oldPosition) == new.getHeaderValue(newPosition) } 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)) { return old.getSection(oldPosition).collapsed == new.getSection(newPosition).collapsed } - val oldItem = old.getItem(oldPosition) - val newItem = new.getItem(newPosition) + val oldItem = old.getItem(oldPosition)!! + val newItem = new.getItem(newPosition)!! return oldItem == newItem && oldItem.getIndent() == adapter.getIndent(newItem) } } \ No newline at end of file diff --git a/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt b/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt index c62295789..95b0af6d9 100644 --- a/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt +++ b/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt @@ -6,8 +6,12 @@ import org.tasks.data.TaskContainer import org.tasks.date.DateTimeUtils import java.util.* -class SectionedDataSource constructor(tasks: List, disableHeaders: Boolean, val sortMode: Int, private val collapsed: MutableSet) { - +class SectionedDataSource constructor( + tasks: List, + disableHeaders: Boolean, + val sortMode: Int, + private val collapsed: MutableSet +) { private val tasks = tasks.toMutableList() private val sections = if (disableHeaders) { @@ -16,9 +20,9 @@ class SectionedDataSource constructor(tasks: List, disableHeaders 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 diff --git a/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt b/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt index d49c95ed1..cd9499e08 100644 --- a/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt +++ b/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt @@ -89,10 +89,7 @@ internal class ScrollableViewsFactory( return 1 } - override fun getItemId(position: Int): Long { - val task = getTask(position) - return task?.id ?: 0 - } + override fun getItemId(position: Int) = getTask(position)?.id ?: 0 override fun hasStableIds(): Boolean { return true @@ -208,9 +205,7 @@ internal class ScrollableViewsFactory( return null } - private fun getTask(position: Int): TaskContainer? { - return if (position < tasks.size) tasks[position] else null - } + private fun getTask(position: Int): TaskContainer? = tasks.getItem(position) private suspend fun getQuery(filter: Filter?, subtasks: SubtaskInfo): List { val queries = getQuery(preferences, filter!!, subtasks)