commit
deaa6e7916
@ -0,0 +1,36 @@ |
||||
package net.pokeranalytics.android.model |
||||
|
||||
import android.content.Context |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||
import net.pokeranalytics.android.ui.view.RowViewType |
||||
|
||||
class TableSize(var numberOfPlayer:Int): RowRepresentable { |
||||
companion object { |
||||
val all = Array(8, init = |
||||
{ index -> TableSize(index+2)}) |
||||
} |
||||
|
||||
override val resId: Int? |
||||
get() { |
||||
return if (this.numberOfPlayer == 2) { |
||||
R.string.heads_up |
||||
} else { |
||||
R.string.max |
||||
} |
||||
} |
||||
|
||||
override fun localizedTitle(context: Context): String { |
||||
this.resId?.let { |
||||
return if (this.numberOfPlayer == 2) { |
||||
context.getString(it) |
||||
} else { |
||||
"$this.numberOfPlayer$context.getString(it)" |
||||
} |
||||
} |
||||
return super.localizedTitle(context) |
||||
} |
||||
|
||||
override val viewType: Int |
||||
get() = RowViewType.TITLE_GRID.ordinal |
||||
} |
||||
@ -0,0 +1,19 @@ |
||||
package net.pokeranalytics.android.model.interfaces |
||||
|
||||
/** |
||||
* An interface to easily handle the validity of any object we want to save |
||||
*/ |
||||
interface Savable { |
||||
/** |
||||
* A method to define if an object is safe for saving in database |
||||
*/ |
||||
fun isValidForSave(): Boolean { |
||||
//TODO should be by default to false |
||||
return true |
||||
} |
||||
|
||||
/** |
||||
* A unique identifier getter |
||||
*/ |
||||
fun uniqueIdentifier(): String |
||||
} |
||||
@ -1,58 +0,0 @@ |
||||
package net.pokeranalytics.android.ui.adapter |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import io.realm.RealmResults |
||||
import kotlinx.android.synthetic.main.row_history_session.view.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.realm.Session |
||||
import timber.log.Timber |
||||
|
||||
class HistoryAdapter(private var sessions: RealmResults<Session>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||
|
||||
companion object { |
||||
const val ROW_SESSION: Int = 100 |
||||
const val ROW_TOURNAMENT: Int = 101 |
||||
const val ROW_HAND: Int = 102 |
||||
const val ROW_TRANSACTION: Int = 103 |
||||
} |
||||
|
||||
var onClickOnSession: ((position: Int, session: Session) -> Unit)? = null |
||||
|
||||
inner class RowSessionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||
|
||||
fun bind(session: Session?) { |
||||
session?.let { |
||||
itemView.sessionRow.setData(session) |
||||
itemView.sessionRow.setOnClickListener { |
||||
onClickOnSession?.invoke(adapterPosition, session) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||
when (viewType) { |
||||
ROW_SESSION -> return RowSessionViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_history_session, parent, false)) |
||||
else -> throw IllegalStateException("Need to implement type $viewType in HistoryAdapter") |
||||
} |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||
when (getItemViewType(position)) { |
||||
ROW_SESSION -> (holder as HistoryAdapter.RowSessionViewHolder).bind(sessions.get(position)) |
||||
} |
||||
} |
||||
|
||||
override fun getItemCount(): Int { |
||||
return sessions.size |
||||
} |
||||
|
||||
override fun getItemViewType(position: Int): Int { |
||||
return ROW_SESSION |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -1,51 +0,0 @@ |
||||
package net.pokeranalytics.android.ui.adapter |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import kotlinx.android.synthetic.main.row_bottom_sheet_grid_title.view.* |
||||
import net.pokeranalytics.android.R |
||||
|
||||
class LimitTypesAdapter(private var tableSizes: ArrayList<String>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||
|
||||
companion object { |
||||
const val ROW_LIMIT: Int = 100 |
||||
} |
||||
|
||||
var onClickOnItem: ((position: Int) -> Unit)? = null |
||||
|
||||
inner class CellSessionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||
|
||||
fun bind(tableSize: String) { |
||||
itemView.title.text = tableSize |
||||
itemView.container.setOnClickListener { |
||||
onClickOnItem?.invoke(adapterPosition) |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||
when (viewType) { |
||||
ROW_LIMIT -> return CellSessionViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_bottom_sheet_title, parent, false)) |
||||
else -> throw IllegalStateException("Need to implement type $viewType in HistoryAdapter") |
||||
} |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||
when (getItemViewType(position)) { |
||||
ROW_LIMIT -> (holder as LimitTypesAdapter.CellSessionViewHolder).bind(tableSizes[position]) |
||||
} |
||||
} |
||||
|
||||
override fun getItemCount(): Int { |
||||
return tableSizes.size |
||||
} |
||||
|
||||
override fun getItemViewType(position: Int): Int { |
||||
return ROW_LIMIT |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -1,50 +0,0 @@ |
||||
package net.pokeranalytics.android.ui.adapter |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import kotlinx.android.synthetic.main.row_bottom_sheet_grid_title.view.* |
||||
import net.pokeranalytics.android.R |
||||
|
||||
class TableSizeGridAdapter(private var tableSizes: ArrayList<String>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||
|
||||
companion object { |
||||
const val ROW_TABLE_SIZE: Int = 100 |
||||
} |
||||
|
||||
var onClickOnItem: ((position: Int) -> Unit)? = null |
||||
|
||||
inner class CellSessionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||
|
||||
fun bind(tableSize: String) { |
||||
itemView.title.text = tableSize |
||||
itemView.container.setOnClickListener { |
||||
onClickOnItem?.invoke(adapterPosition) |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||
when (viewType) { |
||||
ROW_TABLE_SIZE -> return CellSessionViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_bottom_sheet_grid_title, parent, false)) |
||||
else -> throw IllegalStateException("Need to implement type $viewType in HistoryAdapter") |
||||
} |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||
when (getItemViewType(position)) { |
||||
ROW_TABLE_SIZE -> (holder as TableSizeGridAdapter.CellSessionViewHolder).bind(tableSizes[position]) |
||||
} |
||||
} |
||||
|
||||
override fun getItemCount(): Int { |
||||
return tableSizes.size |
||||
} |
||||
|
||||
override fun getItemViewType(position: Int): Int { |
||||
return ROW_TABLE_SIZE |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -1,71 +0,0 @@ |
||||
package net.pokeranalytics.android.ui.adapter.components |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.appcompat.widget.AppCompatTextView |
||||
import androidx.constraintlayout.widget.ConstraintLayout |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.ui.view.RowViewType |
||||
|
||||
enum class LiveDataViewType { |
||||
DATA, |
||||
BOTTOM_SHEET_DATA |
||||
} |
||||
|
||||
interface LiveDataDataSource { |
||||
val title: String |
||||
} |
||||
|
||||
interface LiveDataDelegate { |
||||
fun data(position: Int) : LiveDataDataSource |
||||
fun onRowSelected(position: Int) |
||||
fun size() : Int |
||||
} |
||||
|
||||
class LiveDataAdapter(var adapterDelegate: LiveDataDelegate, var liveDataViewType: LiveDataViewType? = LiveDataViewType.DATA) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||
|
||||
inner class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||
fun bind(row: LiveDataDataSource, listener: View.OnClickListener) { |
||||
when(liveDataViewType) { |
||||
LiveDataViewType.DATA -> { |
||||
itemView.findViewById<AppCompatTextView>(R.id.rowTitle_title).text = row.title |
||||
itemView.findViewById<ConstraintLayout>(R.id.rowTitle_container).setOnClickListener(listener) |
||||
} |
||||
LiveDataViewType.BOTTOM_SHEET_DATA -> { |
||||
itemView.findViewById<AppCompatTextView>(R.id.title).text = row.title |
||||
itemView.findViewById<ConstraintLayout>(R.id.container).setOnClickListener(listener) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun getItemViewType(position: Int): Int { |
||||
return RowViewType.TITLE.ordinal |
||||
} |
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||
val layoutToInflate = when(liveDataViewType) { |
||||
LiveDataViewType.DATA -> { |
||||
R.layout.row_title |
||||
} |
||||
LiveDataViewType.BOTTOM_SHEET_DATA -> { |
||||
R.layout.row_bottom_sheet_title |
||||
} |
||||
else -> R.layout.row_title |
||||
} |
||||
return DataViewHolder(LayoutInflater.from(parent.context).inflate(layoutToInflate, parent, false)) |
||||
} |
||||
|
||||
override fun getItemCount(): Int { |
||||
return adapterDelegate.size() |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||
val listener = View.OnClickListener { |
||||
adapterDelegate.onRowSelected(position) |
||||
} |
||||
(holder as DataViewHolder).bind(this.adapterDelegate.data(position), listener) |
||||
} |
||||
} |
||||
@ -1,11 +0,0 @@ |
||||
package net.pokeranalytics.android.ui.fragment.components.bottomsheet |
||||
|
||||
import android.text.InputType |
||||
import io.realm.RealmResults |
||||
|
||||
class BottomSheetData( |
||||
var defaultValue: Any? = null, |
||||
var hint: Int? = null, |
||||
var inputType: Int? = InputType.TYPE_CLASS_TEXT, |
||||
var data: RealmResults<*>? = null |
||||
) |
||||
@ -1,8 +1,30 @@ |
||||
package net.pokeranalytics.android.ui.view |
||||
|
||||
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetData |
||||
import android.text.InputType |
||||
import io.realm.RealmResults |
||||
|
||||
/** |
||||
* An interface to describe how an object can be editable and to handle the update of the object |
||||
*/ |
||||
interface RowEditable { |
||||
fun getBottomSheetData(row: RowRepresentable): ArrayList<BottomSheetData> |
||||
/** |
||||
* A list of [RowEditableDescriptor] object specifying the way the edition will be handled |
||||
*/ |
||||
fun rowEditableDescriptors(row: RowRepresentable): ArrayList<RowEditableDescriptor> |
||||
|
||||
/** |
||||
* a method to handle the modification of the object. |
||||
* Through [RowRepresentable] the object is able to update the right variable with the new value. |
||||
*/ |
||||
fun updateValue(value: Any?, row: RowRepresentable) |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* An container class to describe the way an field of an object will be edited |
||||
*/ |
||||
class RowEditableDescriptor( |
||||
var defaultValue: Any? = null, |
||||
var hint: Int? = null, |
||||
var inputType: Int? = InputType.TYPE_CLASS_TEXT, |
||||
var data: RealmResults<*>? = null |
||||
) |
||||
Loading…
Reference in new issue