update the current portrait photo on click
This commit is contained in:
parent
420a6459e7
commit
687b8697c8
1 changed files with 9 additions and 0 deletions
|
@ -35,6 +35,14 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>,
|
||||||
|
|
||||||
fun getCurrentPhoto() = currentSelection
|
fun getCurrentPhoto() = currentSelection
|
||||||
|
|
||||||
|
private fun setCurrentPhoto(position: Int) {
|
||||||
|
val newPhoto = photos.getOrNull(position) ?: return
|
||||||
|
if (currentSelection != newPhoto) {
|
||||||
|
currentSelection = newPhoto
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
fun bindView(photo: String, position: Int): View {
|
fun bindView(photo: String, position: Int): View {
|
||||||
itemView.apply {
|
itemView.apply {
|
||||||
|
@ -64,6 +72,7 @@ class PortraitPhotosAdapter(val context: Context, val photos: ArrayList<String>,
|
||||||
if (photo.isNotEmpty()) {
|
if (photo.isNotEmpty()) {
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
itemClick(position, x.toInt())
|
itemClick(position, x.toInt())
|
||||||
|
setCurrentPhoto(position)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setOnClickListener(null)
|
setOnClickListener(null)
|
||||||
|
|
Loading…
Reference in a new issue