diff --git a/app/src/main/java/org/lineageos/glimpse/thumbnail/AlbumThumbnailAdapter.kt b/app/src/main/java/org/lineageos/glimpse/thumbnail/AlbumThumbnailAdapter.kt index 1d5ff8e..d030a59 100644 --- a/app/src/main/java/org/lineageos/glimpse/thumbnail/AlbumThumbnailAdapter.kt +++ b/app/src/main/java/org/lineageos/glimpse/thumbnail/AlbumThumbnailAdapter.kt @@ -23,6 +23,10 @@ class AlbumThumbnailAdapter( ) : RecyclerView.Adapter() { private var albums: Array? = null + init { + setHasStableIds(true) + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AlbumViewHolder { val layoutInflater = LayoutInflater.from(parent.context) @@ -33,6 +37,8 @@ class AlbumThumbnailAdapter( override fun getItemCount() = albums?.size ?: 0 + override fun getItemId(position: Int) = (albums?.let { it[position].id } ?: 0).toLong() + override fun onBindViewHolder(holder: AlbumViewHolder, position: Int) { albums?.let { holder.bind(it[position]) 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 20bcae5..e6099c7 100644 --- a/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailAdapter.kt +++ b/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailAdapter.kt @@ -27,8 +27,14 @@ class ThumbnailAdapter( private var recyclerView: RecyclerView? = null + init { + setHasStableIds(true) + } + override fun getItemCount() = super.getItemCount() + headersPositions.size + override fun getItemId(position: Int) = getIdFromMediaStore(position) + override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { super.onAttachedToRecyclerView(recyclerView) @@ -121,6 +127,13 @@ class ThumbnailAdapter( recyclerView?.post { notifyItemInserted(newItemCount) } } + private fun getIdFromMediaStore(position: Int): Long { + val cursor = cursor ?: return 0 + val idIndex = cursor.getColumnIndex(MediaStore.Files.FileColumns._ID) + cursor.moveToPosition(getTruePosition(position)) + return cursor.getLong(idIndex) + } + private fun getMediaFromMediaStore(position: Int): Media? { val cursor = cursor ?: return null