|
|
|
@ -4,6 +4,7 @@ import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.widget.Toast |
|
|
|
import android.widget.Toast |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
|
|
|
import io.realm.Realm.init |
|
|
|
|
|
|
|
|
|
|
|
interface EditableDataDelegate : DynamicRowDelegate { |
|
|
|
interface EditableDataDelegate : DynamicRowDelegate { |
|
|
|
fun setValue(value: Any, row: DynamicRowInterface) |
|
|
|
fun setValue(value: Any, row: DynamicRowInterface) |
|
|
|
@ -27,16 +28,13 @@ interface DynamicRowDelegate { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface DynamicRowCallback { |
|
|
|
interface DynamicRowCallback { |
|
|
|
fun onRowSelected(row: DynamicRowInterface) |
|
|
|
fun onRowSelected(row: DynamicRowInterface) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class DynamicListAdapter(delegate: DynamicRowDelegate) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
|
|
|
class DynamicListAdapter(var delegate: DynamicRowDelegate, var callBackDelegate: DynamicRowCallback? = null) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
|
|
|
|
|
|
|
|
|
|
|
private var rows: ArrayList<DynamicRowInterface> = ArrayList() |
|
|
|
private var rows: ArrayList<DynamicRowInterface> = ArrayList() |
|
|
|
private var delegate: DynamicRowDelegate = delegate |
|
|
|
|
|
|
|
var callback: ((row: DynamicRowInterface) -> Unit)? = null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
this.rows = delegate.adapterRows() |
|
|
|
this.rows = delegate.adapterRows() |
|
|
|
@ -58,7 +56,7 @@ class DynamicListAdapter(delegate: DynamicRowDelegate) : RecyclerView.Adapter<Re |
|
|
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
|
|
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
|
|
|
val dynamicRow = this.rows[position] |
|
|
|
val dynamicRow = this.rows[position] |
|
|
|
val listener = View.OnClickListener { |
|
|
|
val listener = View.OnClickListener { |
|
|
|
callback?.invoke(dynamicRow) |
|
|
|
callBackDelegate?.onRowSelected(dynamicRow) |
|
|
|
} |
|
|
|
} |
|
|
|
(holder as DynamicHolder).bind(dynamicRow, this.delegate, listener) |
|
|
|
(holder as DynamicHolder).bind(dynamicRow, this.delegate, listener) |
|
|
|
} |
|
|
|
} |
|
|
|
|