Glimpse: Streamline BaseCursorAdapter cursor close-up

Change-Id: Ic4e9fb6d04c93e9286640475fc0ce1964b85ac2f
This commit is contained in:
Luca Stefani 2023-08-03 19:07:23 +02:00 committed by LuK1337
parent 209675312d
commit ac824c5598
1 changed files with 4 additions and 6 deletions

View File

@ -15,18 +15,16 @@ abstract class BaseCursorAdapter<T : RecyclerView.ViewHolder> : RecyclerView.Ada
override fun getItemCount() = cursor?.count ?: 0
fun changeCursor(cursor: Cursor?) {
val oldCursor = swapCursor(cursor)
oldCursor?.close()
swapCursor(cursor)
onChangedCursor(cursor)
}
protected open fun onChangedCursor(cursor: Cursor?) {}
@SuppressLint("NotifyDataSetChanged")
private fun swapCursor(cursor: Cursor?): Cursor? {
private fun swapCursor(cursor: Cursor?) {
if (this.cursor == cursor) {
return null
return
}
val oldCursor = this.cursor
@ -36,6 +34,6 @@ abstract class BaseCursorAdapter<T : RecyclerView.ViewHolder> : RecyclerView.Ada
notifyDataSetChanged()
}
return oldCursor
oldCursor?.close()
}
}