diff --git a/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailAdapter.kt b/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailAdapter.kt index d112435..056a323 100644 --- a/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailAdapter.kt +++ b/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailAdapter.kt @@ -28,8 +28,6 @@ class ThumbnailAdapter( ) : BaseCursorAdapter() { private val headersPositions = sortedSetOf() - 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 {