|
|
|
|
@ -3,37 +3,35 @@ package net.pokeranalytics.android.ui.adapter.components |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
|
|
|
|
|
enum class RowType { |
|
|
|
|
interface DynamicRowDelegate { |
|
|
|
|
|
|
|
|
|
fun adapterRows() : ArrayList<DynamicRowInterface> |
|
|
|
|
|
|
|
|
|
fun boolForRow(row: DynamicRowInterface) : Boolean |
|
|
|
|
fun stringForRow(row: DynamicRowInterface) : String |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Manages: |
|
|
|
|
* - label (string) |
|
|
|
|
* - segmented control (live/online) |
|
|
|
|
* - textfield (string) |
|
|
|
|
* - switch (bool) |
|
|
|
|
* - static content |
|
|
|
|
* */ |
|
|
|
|
|
|
|
|
|
//interface RowDelegate { |
|
|
|
|
// |
|
|
|
|
// fun groupedRow() : ArrayList<RowGroup>() |
|
|
|
|
// fun (row: DynamicRowInterface) : String |
|
|
|
|
//} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class DynamicListAdapter(delegate: DynamicRowDelegate) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
|
|
|
|
|
|
|
|
|
class DynamicListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
|
|
|
|
private var rows: ArrayList<DynamicRowInterface> = ArrayList<DynamicRowInterface>() |
|
|
|
|
private var delegate: DynamicRowDelegate = delegate |
|
|
|
|
|
|
|
|
|
var groupedRows = ArrayList<RowGroup>() |
|
|
|
|
init { |
|
|
|
|
this.rows = delegate.adapterRows() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun getItemViewType(position: Int): Int { |
|
|
|
|
|
|
|
|
|
var sectionIndex: Int = 0 |
|
|
|
|
var rowIndex: Int = position |
|
|
|
|
while (rowIndex >= this.groupedRows[sectionIndex].size + 1) { |
|
|
|
|
rowIndex -= (groupedRows[sectionIndex].size + 1) |
|
|
|
|
sectionIndex++ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (rowIndex == 0) { |
|
|
|
|
return this.groupedRows[sectionIndex].viewType |
|
|
|
|
} else { |
|
|
|
|
return this.groupedRows[sectionIndex].rows[rowIndex - 1].viewType |
|
|
|
|
} |
|
|
|
|
return this.rows[position].viewType |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
|
|
|
|
@ -42,17 +40,12 @@ class DynamicListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun getItemCount(): Int { |
|
|
|
|
|
|
|
|
|
return this.groupedRows.size + this.groupedRows.fold(0) { acc: Int, group: RowGroup -> |
|
|
|
|
return acc + group.size |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return this.rows.size |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
|
|
|
|
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. |
|
|
|
|
val dynamicRow = this.rows[position] |
|
|
|
|
(holder as DynamicHolder).bind(dynamicRow, this.delegate) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |