Glimpse: Streamline BaseCursorAdapter cursor close-up
Change-Id: Ic4e9fb6d04c93e9286640475fc0ce1964b85ac2f
This commit is contained in:
parent
209675312d
commit
ac824c5598
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue