You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.1 KiB
65 lines
2.1 KiB
5 years ago
|
package software.jonasfranz.banking5.adapters
|
||
|
|
||
|
import android.support.v7.widget.RecyclerView
|
||
|
import android.view.LayoutInflater
|
||
|
import android.view.View
|
||
|
import android.view.ViewGroup
|
||
|
import android.widget.TextView
|
||
|
import software.jonasfranz.banking5.R
|
||
|
|
||
|
|
||
|
import software.jonasfranz.banking5.adapters.dummy.DummyContent.DummyItem
|
||
|
|
||
|
import kotlinx.android.synthetic.main.fragment_settings.view.*
|
||
|
import software.jonasfranz.banking5.adapters.dummy.DummyContent
|
||
|
|
||
|
/**
|
||
|
* [RecyclerView.Adapter] that can display a [DummyItem] and makes a call to the
|
||
|
* specified [OnListFragmentInteractionListener].
|
||
|
* TODO: Replace the implementation with code for your data type.
|
||
|
*/
|
||
|
class SettingsRecyclerViewAdapter(
|
||
|
private val mValues: List<DummyItem>,
|
||
|
private val mListener: (DummyItem) -> Unit
|
||
|
) : RecyclerView.Adapter<SettingsRecyclerViewAdapter.ViewHolder>() {
|
||
|
|
||
|
private val mOnClickListener: View.OnClickListener
|
||
|
|
||
|
init {
|
||
|
mOnClickListener = View.OnClickListener { v ->
|
||
|
val item = v.tag as DummyItem
|
||
|
// Notify the active callbacks interface (the activity, if the fragment is attached to
|
||
|
// one) that an item has been selected.
|
||
|
mListener(item)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||
|
val view = LayoutInflater.from(parent.context)
|
||
|
.inflate(R.layout.fragment_settings, parent, false)
|
||
|
return ViewHolder(view)
|
||
|
}
|
||
|
|
||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||
|
val item = mValues[position]
|
||
|
holder.mIdView.text = item.id
|
||
|
holder.mContentView.text = item.content
|
||
|
|
||
|
with(holder.mView) {
|
||
|
tag = item
|
||
|
setOnClickListener(mOnClickListener)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
override fun getItemCount(): Int = mValues.size
|
||
|
|
||
|
inner class ViewHolder(val mView: View) : RecyclerView.ViewHolder(mView) {
|
||
|
val mIdView: TextView = mView.item_number
|
||
|
val mContentView: TextView = mView.content
|
||
|
|
||
|
override fun toString(): String {
|
||
|
return super.toString() + " '" + mContentView.text + "'"
|
||
|
}
|
||
|
}
|
||
|
}
|