app/app/src/main/java/com/danilafe/fencelessgrazing/ui/components/CollarViewHolder.kt

39 lines
1.4 KiB
Kotlin

package com.danilafe.fencelessgrazing.ui.components
import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.danilafe.fencelessgrazing.R
import com.danilafe.fencelessgrazing.model.CollarSummary
/**
* A [RecyclerView.ViewHolder] used to render [CollarSummary] item entries.
*/
class CollarViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
/**
* The [TextView] that holds the name of a collar.
*/
private val nameView: TextView = itemView.findViewById(R.id.collarSummaryName)
/**
* The [TextView] that holds the position of the collar.
*/
private val positionView: TextView = itemView.findViewById(R.id.collarSummaryPos)
/**
* Called by the [CollarSummaryAdapter] to update the contents of the view this
* class holds.
*
* @param summary the collar summary whose data should be extracted and placed into the views.
* @param collarClickListener the action that should be called when a summary is clicked.
*/
fun bindData(summary: CollarSummary, collarClickListener: CollarClickListener) {
nameView.text = summary.name
positionView.text = itemView.resources.getString(
R.string.collarSummaryLocation,
summary.pos.longitude.toDouble(), summary.pos.latitude.toDouble())
itemView.setOnClickListener {
collarClickListener.onCollarClick(summary)
}
}
}