Glimpse: Always take into account we'll have 1 header in ThumbnailAdapter
Otherwise the recycler view won't call us enough times since we know we'll always need at least one header. Once an header item has been added we start using that has the count of the items. Change-Id: Ibee23f8bc14cacca125647335725e566475985c7
This commit is contained in:
parent
75d8906c4a
commit
336a869299
|
@ -28,8 +28,6 @@ class ThumbnailAdapter(
|
|||
) : BaseCursorAdapter<RecyclerView.ViewHolder>() {
|
||||
private val headersPositions = sortedSetOf<Int>()
|
||||
|
||||
private var recyclerView: RecyclerView? = null
|
||||
|
||||
// Cursor indexes
|
||||
private var idIndex = -1
|
||||
private var isFavoriteIndex = -1
|
||||
|
@ -41,22 +39,13 @@ class ThumbnailAdapter(
|
|||
setHasStableIds(true)
|
||||
}
|
||||
|
||||
override fun getItemCount() = super.getItemCount() + headersPositions.size
|
||||
override fun getItemCount() =
|
||||
super.getItemCount().takeIf { it > 0 }
|
||||
?.let { it + (headersPositions.size.takeIf { headerCount -> headerCount > 0 } ?: 1) }
|
||||
?: 0
|
||||
|
||||
override fun getItemId(position: Int) = getIdFromMediaStore(position)
|
||||
|
||||
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView)
|
||||
|
||||
this.recyclerView = recyclerView
|
||||
}
|
||||
|
||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
||||
super.onDetachedFromRecyclerView(recyclerView)
|
||||
|
||||
this.recyclerView = null
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
LayoutInflater.from(parent.context).let { layoutInflater ->
|
||||
when (viewType) {
|
||||
|
@ -148,8 +137,6 @@ class ThumbnailAdapter(
|
|||
|
||||
private fun addHeaderOffset(position: Int) {
|
||||
headersPositions.add(position)
|
||||
val newItemCount = itemCount
|
||||
recyclerView?.post { notifyItemInserted(newItemCount) }
|
||||
}
|
||||
|
||||
private fun getIdFromMediaStore(position: Int): Long {
|
||||
|
|
Loading…
Reference in New Issue