Glimpse: Use itemView in ThumbnailViewHolder
Also set the click listener only once we have the data binded
Change-Id: Id74c564f5f1a44f4c44b386b3e1ed57d7f3dc676
diff --git a/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailAdapter.kt b/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailAdapter.kt
index 3101f71..f2f2087 100644
--- a/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailAdapter.kt
+++ b/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailAdapter.kt
@@ -127,27 +127,25 @@
}
class ThumbnailViewHolder(
- private val view: View,
+ view: View,
private val onItemSelected: (media: Media, position: Int) -> Unit,
) : RecyclerView.ViewHolder(view) {
// Views
private val videoOverlayImageView =
- view.findViewById<ImageView>(R.id.videoOverlayImageView)!!
- private val thumbnailImageView = view.findViewById<ImageView>(R.id.thumbnailImageView)!!
+ itemView.findViewById<ImageView>(R.id.videoOverlayImageView)!!
+ private val thumbnailImageView = itemView.findViewById<ImageView>(R.id.thumbnailImageView)!!
private lateinit var media: Media
private var position = -1
- init {
- view.setOnClickListener {
- onItemSelected(media, position)
- }
- }
-
fun bind(media: Media, position: Int) {
this.media = media
this.position = position
+ itemView.setOnClickListener {
+ onItemSelected(media, position)
+ }
+
thumbnailImageView.load(media.externalContentUri) {
memoryCacheKey("thumbnail_${media.id}")
size(DisplayAwareGridLayoutManager.MAX_THUMBNAIL_SIZE)