parent
05b9ae094d
commit
5adcd4363d
@ -0,0 +1,58 @@ |
|||||||
|
package net.pokeranalytics.android.ui.adapter.components |
||||||
|
|
||||||
|
import android.view.ViewGroup |
||||||
|
import androidx.recyclerview.widget.RecyclerView |
||||||
|
|
||||||
|
enum class RowType { |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
//interface RowDelegate { |
||||||
|
// |
||||||
|
// fun groupedRow() : ArrayList<RowGroup>() |
||||||
|
// fun (row: DynamicRowInterface) : String |
||||||
|
//} |
||||||
|
|
||||||
|
|
||||||
|
class DynamicListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||||
|
|
||||||
|
var groupedRows = ArrayList<RowGroup>() |
||||||
|
|
||||||
|
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 |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||||
|
val rowViewType: RowViewType = RowViewType.values()[viewType] |
||||||
|
return rowViewType.viewHolder(parent) |
||||||
|
} |
||||||
|
|
||||||
|
override fun getItemCount(): Int { |
||||||
|
|
||||||
|
return this.groupedRows.size + this.groupedRows.fold(0) { acc: Int, group: RowGroup -> |
||||||
|
return acc + group.size |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||||
|
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,67 @@ |
|||||||
|
package net.pokeranalytics.android.ui.adapter.components |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
|
||||||
|
|
||||||
|
class RowGroup(stringRes: Int?, rows: ArrayList<DynamicRowInterface>) : DynamicRowInterface { |
||||||
|
|
||||||
|
var stringRes: Int? = stringRes |
||||||
|
var rows: ArrayList<DynamicRowInterface> = rows |
||||||
|
|
||||||
|
var size: Int = 0 |
||||||
|
get() { |
||||||
|
return this.rows.size |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
override fun localizedTitle(context: Context): String? { |
||||||
|
stringRes?.let { |
||||||
|
return context.getString(it) |
||||||
|
} |
||||||
|
return null |
||||||
|
} |
||||||
|
|
||||||
|
override var viewType: Int = 0 |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
interface DynamicRowInterface { |
||||||
|
|
||||||
|
fun localizedTitle(context: Context): String? |
||||||
|
var viewType: Int |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
enum class SessionRow(val resId: Int) : DynamicRowInterface { |
||||||
|
BLINDS(R.string.app_name), |
||||||
|
GAME(R.string.app_name), |
||||||
|
DATE(R.string.app_name); |
||||||
|
|
||||||
|
override fun localizedTitle(context: Context): String? { |
||||||
|
return context.getString(this.resId) |
||||||
|
} |
||||||
|
|
||||||
|
override var viewType: Int = RowViewType.HEADER.ordinal |
||||||
|
get() { |
||||||
|
return when (this) { |
||||||
|
BLINDS -> 1 |
||||||
|
GAME -> 2 |
||||||
|
DATE -> 1 |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
enum class BankrollRow(val resId: Int) : DynamicRowInterface { |
||||||
|
NAME(R.string.app_name), |
||||||
|
LIVE(R.string.app_name), |
||||||
|
CURRENCY(R.string.app_name); |
||||||
|
|
||||||
|
override fun localizedTitle(context: Context): String? { |
||||||
|
return context.getString(this.resId) |
||||||
|
} |
||||||
|
|
||||||
|
override var viewType: Int = 1 |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
package net.pokeranalytics.android.ui.adapter.components |
||||||
|
|
||||||
|
import android.view.View |
||||||
|
import android.view.ViewGroup |
||||||
|
import androidx.recyclerview.widget.RecyclerView |
||||||
|
|
||||||
|
enum class RowViewType { |
||||||
|
HEADER, |
||||||
|
TEXTFIELD; |
||||||
|
|
||||||
|
inner class PlaceholderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
fun viewHolder(parent: ViewGroup) : RecyclerView.ViewHolder { |
||||||
|
return PlaceholderViewHolder(parent) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,10 @@ |
|||||||
|
package net.pokeranalytics.android.ui.fragment.components |
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView |
||||||
|
import net.pokeranalytics.android.util.PokerAnalyticsFragment |
||||||
|
|
||||||
|
open class DynamicListFragment : PokerAnalyticsFragment() { |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue