merge interface wip

dev_raz_wip
Razmig Sarkissian 7 years ago
parent 73c5f27a19
commit 757da5623a
  1. 5
      app/src/main/java/net/pokeranalytics/android/model/LiveData.kt
  2. 26
      app/src/main/java/net/pokeranalytics/android/model/realm/Bankroll.kt
  3. 20
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  4. 20
      app/src/main/java/net/pokeranalytics/android/model/realm/Location.kt
  5. 20
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  6. 20
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentFeature.kt
  7. 20
      app/src/main/java/net/pokeranalytics/android/model/realm/TransactionType.kt
  8. 2
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/LiveDataAdapter.kt
  9. 73
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/RowRepresentableAdapter.kt
  10. 25
      app/src/main/java/net/pokeranalytics/android/ui/fragment/DataListFragment.kt
  11. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/EditableDataFragment.kt
  12. 31
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetListFragment.kt
  13. 74
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetTableSizeGridFragment.kt
  14. 33
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt

@ -13,6 +13,7 @@ import net.pokeranalytics.android.ui.view.Localizable
* An interface to easily handle the validity of any object we want to save * An interface to easily handle the validity of any object we want to save
*/ */
interface ObjectSavable { interface ObjectSavable {
fun uniqueIdentifier(): String
fun isValidForSave(): Boolean { fun isValidForSave(): Boolean {
return true return true
} }
@ -64,8 +65,8 @@ enum class LiveData : Localizable {
} }
} }
fun deleteData(realm:Realm, data:LiveDataDataSource) { fun deleteData(realm:Realm, data:ObjectSavable) {
realm.where(this.relatedEntity).equalTo("id", data.primaryKey).findAll().deleteAllFromRealm() realm.where(this.relatedEntity).equalTo("id", data.uniqueIdentifier()).findAll().deleteAllFromRealm()
} }
fun updateOrCreate(realm:Realm, primaryKey:String?): RealmObject { fun updateOrCreate(realm:Realm, primaryKey:String?): RealmObject {

@ -1,6 +1,7 @@
package net.pokeranalytics.android.model.realm package net.pokeranalytics.android.model.realm
import android.text.InputType import android.text.InputType
import io.realm.Realm
import io.realm.RealmList import io.realm.RealmList
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
@ -15,7 +16,7 @@ import net.pokeranalytics.android.ui.view.SimpleRow
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class Bankroll(name: String = "") : RealmObject(), RowRepresentableDataSource, LiveDataDataSource, open class Bankroll(name: String = "") : RealmObject(), RowRepresentableDataSource,
RowEditable, ObjectSavable { RowEditable, ObjectSavable {
companion object { companion object {
@ -42,16 +43,18 @@ open class Bankroll(name: String = "") : RealmObject(), RowRepresentableDataSour
// @todo rate management // @todo rate management
override val title: String get() = this.name override fun uniqueIdentifier(): String {
override val primaryKey: String get() = this.id return this.id
override fun adapterRows(): ArrayList<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(BankrollRow.values())
return rows
} }
override val adapterRows: ArrayList<RowRepresentable>
get() {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(BankrollRow.values())
return rows
}
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return when (row) { return when (row) {
SimpleRow.NAME -> this.name SimpleRow.NAME -> this.name
@ -83,6 +86,11 @@ open class Bankroll(name: String = "") : RealmObject(), RowRepresentableDataSour
} }
override fun isValidForSave(): Boolean { override fun isValidForSave(): Boolean {
val realm = Realm.getDefaultInstance()
return (realm.where(Bankroll::class.java)
.notEqualTo("id", this.id)
.equalTo("name", this.name)
.findAll().size == 0)
return this.name.isNotEmpty() return this.name.isNotEmpty()
} }
} }

@ -13,7 +13,7 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.SimpleRow import net.pokeranalytics.android.ui.view.SimpleRow
import java.util.* import java.util.*
open class Game : RealmObject(), RowRepresentableDataSource, LiveDataDataSource, RowEditable, ObjectSavable { open class Game : RealmObject(), RowRepresentableDataSource, RowEditable, ObjectSavable {
@PrimaryKey @PrimaryKey
var id = UUID.randomUUID().toString() var id = UUID.randomUUID().toString()
@ -24,16 +24,18 @@ open class Game : RealmObject(), RowRepresentableDataSource, LiveDataDataSource,
// A shorter name for the game // A shorter name for the game
var shortName: String? = null var shortName: String? = null
override val title: String get() = this.name override fun uniqueIdentifier(): String {
override val primaryKey: String get() = this.id return this.id
override fun adapterRows(): ArrayList<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(GameRow.values())
return rows
} }
override val adapterRows: ArrayList<RowRepresentable>
get() {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(GameRow.values())
return rows
}
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return when (row) { return when (row) {
SimpleRow.NAME -> this.name SimpleRow.NAME -> this.name

@ -13,7 +13,7 @@ import net.pokeranalytics.android.ui.view.SimpleRow
import java.util.* import java.util.*
open class Location : RealmObject(), RowRepresentableDataSource, LiveDataDataSource, RowEditable, ObjectSavable { open class Location : RealmObject(), RowRepresentableDataSource, RowEditable, ObjectSavable {
@PrimaryKey @PrimaryKey
var id = UUID.randomUUID().toString() var id = UUID.randomUUID().toString()
@ -27,16 +27,18 @@ open class Location : RealmObject(), RowRepresentableDataSource, LiveDataDataSou
// the latitude of the location // the latitude of the location
var latitude: Double? = null var latitude: Double? = null
override val title: String get() = this.name override fun uniqueIdentifier(): String {
override val primaryKey: String get() = this.id return this.id
override fun adapterRows(): ArrayList<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(LocationRow.values())
return rows
} }
override val adapterRows: ArrayList<RowRepresentable>
get() {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(LocationRow.values())
return rows
}
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return when (row) { return when (row) {
SimpleRow.NAME -> this.name SimpleRow.NAME -> this.name

@ -7,6 +7,7 @@ import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.SessionInterface import net.pokeranalytics.android.calculus.SessionInterface
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.ObjectSavable
import net.pokeranalytics.android.model.extensions.SessionState import net.pokeranalytics.android.model.extensions.SessionState
import net.pokeranalytics.android.model.extensions.getState import net.pokeranalytics.android.model.extensions.getState
import net.pokeranalytics.android.ui.adapter.components.LiveDataDataSource import net.pokeranalytics.android.ui.adapter.components.LiveDataDataSource
@ -21,7 +22,7 @@ import net.pokeranalytics.android.util.toCurrency
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource, LiveDataDataSource, open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource, ObjectSavable,
RowEditable { RowEditable {
@PrimaryKey @PrimaryKey
@ -232,11 +233,12 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
return 0.0 return 0.0
} }
override fun adapterRows(): ArrayList<RowRepresentable> { override val adapterRows: ArrayList<RowRepresentable>
val rows = ArrayList<RowRepresentable>() get() {
rows.addAll(SessionRow.getRowsForState(getState())) val rows = ArrayList<RowRepresentable>()
return rows rows.addAll(SessionRow.getRowsForState(getState()))
} return rows
}
override fun boolForRow(row: RowRepresentable): Boolean { override fun boolForRow(row: RowRepresentable): Boolean {
return false return false
@ -266,9 +268,9 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
} }
} }
override fun uniqueIdentifier(): String {
override var title: String = "Change that: $creationDate" return this.id
override val primaryKey: String get() = this.id }
override fun getBottomSheetData(row: RowRepresentable): ArrayList<BottomSheetData> { override fun getBottomSheetData(row: RowRepresentable): ArrayList<BottomSheetData> {

@ -12,7 +12,7 @@ import net.pokeranalytics.android.ui.view.SimpleRow
import net.pokeranalytics.android.ui.view.TournamentFeatureRow import net.pokeranalytics.android.ui.view.TournamentFeatureRow
import java.util.* import java.util.*
open class TournamentFeature : RealmObject(), RowRepresentableDataSource, LiveDataDataSource, RowEditable, ObjectSavable { open class TournamentFeature : RealmObject(), RowRepresentableDataSource, RowEditable, ObjectSavable {
@PrimaryKey @PrimaryKey
var id = UUID.randomUUID().toString() var id = UUID.randomUUID().toString()
@ -20,16 +20,18 @@ open class TournamentFeature : RealmObject(), RowRepresentableDataSource, LiveDa
// The name of the feature // The name of the feature
var name: String = "" var name: String = ""
override val title: String get() = this.name override fun uniqueIdentifier(): String {
override val primaryKey: String get() = this.id return this.id
override fun adapterRows(): ArrayList<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TournamentFeatureRow.values())
return rows
} }
override val adapterRows: ArrayList<RowRepresentable>
get() {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TournamentFeatureRow.values())
return rows
}
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return when (row) { return when (row) {
SimpleRow.NAME -> this.name SimpleRow.NAME -> this.name

@ -13,7 +13,7 @@ import net.pokeranalytics.android.ui.view.TransactionTypeRow
import java.util.* import java.util.*
open class TransactionType : RealmObject(), RowRepresentableDataSource, LiveDataDataSource, RowEditable, ObjectSavable { open class TransactionType : RealmObject(), RowRepresentableDataSource, RowEditable, ObjectSavable {
@PrimaryKey @PrimaryKey
var id = UUID.randomUUID().toString() var id = UUID.randomUUID().toString()
@ -30,16 +30,18 @@ open class TransactionType : RealmObject(), RowRepresentableDataSource, LiveData
// The predefined kind, if necessary, like: Withdrawal, deposit, or tips // The predefined kind, if necessary, like: Withdrawal, deposit, or tips
var kind: Int? = null var kind: Int? = null
override val title: String get() = this.name override fun uniqueIdentifier(): String {
override val primaryKey: String get() = this.id return this.id
override fun adapterRows(): ArrayList<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TransactionTypeRow.values())
return rows
} }
override val adapterRows: ArrayList<RowRepresentable>
get() {
val rows = ArrayList<RowRepresentable>()
rows.add(SimpleRow.NAME)
rows.addAll(TransactionTypeRow.values())
return rows
}
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return when (row) { return when (row) {
SimpleRow.NAME -> this.name SimpleRow.NAME -> this.name

@ -11,7 +11,6 @@ import net.pokeranalytics.android.ui.view.RowViewType
interface LiveDataDataSource { interface LiveDataDataSource {
val title: String val title: String
val primaryKey: String
} }
interface LiveDataDelegate { interface LiveDataDelegate {
@ -30,7 +29,6 @@ class LiveDataAdapter(var adapterDelegate: LiveDataDelegate, var layout: Int? =
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
} }
} }
} }

@ -1,11 +1,13 @@
package net.pokeranalytics.android.ui.adapter.components package net.pokeranalytics.android.ui.adapter.components
import android.content.Context
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import net.pokeranalytics.android.ui.view.BindableHolder import net.pokeranalytics.android.ui.view.BindableHolder
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.SimpleRow
/** /**
* An interface used to provide RowRepresentableAdapter content and value in the form of rows * An interface used to provide RowRepresentableAdapter content and value in the form of rows
@ -15,7 +17,21 @@ interface RowRepresentableDataSource {
/** /**
* Returns a list of rows * Returns a list of rows
*/ */
fun adapterRows(): ArrayList<RowRepresentable> val adapterRows: ArrayList<RowRepresentable>?
get() {
return null
}
fun dataForPosition(position: Int): RowRepresentableDataSource? {
return null
}
fun size(): Int {
this.adapterRows?.let {
return it.size
}
return 0
}
/** /**
* Returns a boolean for a specific row * Returns a boolean for a specific row
@ -55,6 +71,7 @@ interface RowRepresentableDataSource {
interface RowRepresentableDelegate { interface RowRepresentableDelegate {
fun onRowSelected(row: RowRepresentable) {} fun onRowSelected(row: RowRepresentable) {}
fun onActionSelected(row: RowRepresentable) {} fun onActionSelected(row: RowRepresentable) {}
fun dataSelected(data: RowRepresentableDataSource) {}
} }
/** /**
@ -62,52 +79,59 @@ interface RowRepresentableDelegate {
* @param rowRepresentableDataSource the datasource providing rows * @param rowRepresentableDataSource the datasource providing rows
* @param rowRepresentableDelegate the delegate, notified of UI actions * @param rowRepresentableDelegate the delegate, notified of UI actions
*/ */
class RowRepresentableAdapter(var rowRepresentableDataSource: RowRepresentableDataSource, var rowRepresentableDelegate: RowRepresentableDelegate? = null) : class RowRepresentableAdapter(var rowRepresentableDataSource: RowRepresentableDataSource, var rowRepresentableDelegate: RowRepresentableDelegate? = null, var layout: Int? = null) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() { RecyclerView.Adapter<RecyclerView.ViewHolder>() {
/** /**
* The list of rows to display * The list of rows to display
*/ */
private var rows: ArrayList<RowRepresentable> = ArrayList()
init {
this.rows = rowRepresentableDataSource.adapterRows()
}
override fun getItemViewType(position: Int): Int { override fun getItemViewType(position: Int): Int {
return this.rows[position].viewType this.rowRepresentableDataSource.adapterRows?.let {
return it[position].viewType
} ?: run {
return RowViewType.DATA.ordinal
}
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val rowViewType: RowViewType = RowViewType.values()[viewType] val rowViewType: RowViewType = RowViewType.values()[viewType]
return rowViewType.viewHolder(parent) return rowViewType.viewHolder(parent, layout)
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {
return this.rows.size return this.rowRepresentableDataSource.size()
} }
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val dynamicRow = this.rows[position] this.rowRepresentableDataSource.adapterRows?.let {rows ->
val listener = View.OnClickListener {
val listener = View.OnClickListener { rowRepresentableDelegate?.onRowSelected(rows[position])
rowRepresentableDelegate?.onRowSelected(dynamicRow) }
val actionListener = View.OnClickListener {
rowRepresentableDelegate?.onActionSelected(rows[position])
}
(holder as BindableHolder).bind(rows[position], this.rowRepresentableDataSource, listener, actionListener)
} ?: run {
this.rowRepresentableDataSource.dataForPosition(position)?.let { dataSource ->
val listener = View.OnClickListener {
rowRepresentableDelegate?.dataSelected(dataSource)
}
(holder as BindableHolder).bind(SimpleRow.NAME, dataSource, listener, null)
}
} }
val actionListener = View.OnClickListener {
rowRepresentableDelegate?.onActionSelected(dynamicRow)
}
(holder as BindableHolder).bind(dynamicRow, this.rowRepresentableDataSource, listener, actionListener)
} }
/** /**
* Refresh the row in the adapter * Refresh the row in the adapter
*/ */
fun refreshRow(row: RowRepresentable) { fun refreshRow(row: RowRepresentable) {
val index = rows.indexOf(row) this.rowRepresentableDataSource.adapterRows?.let {rows ->
if (index >= 0) { val index = rows.indexOf(row)
notifyItemChanged(index) if (index >= 0) {
notifyItemChanged(index)
}
} }
} }
@ -115,7 +139,6 @@ class RowRepresentableAdapter(var rowRepresentableDataSource: RowRepresentableDa
* Refresh all adapter rows * Refresh all adapter rows
*/ */
fun refreshAllRows() { fun refreshAllRows() {
this.rows = rowRepresentableDataSource.adapterRows()
notifyDataSetChanged() notifyDataSetChanged()
} }

@ -5,17 +5,21 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.realm.ObjectChangeSet
import io.realm.Realm import io.realm.Realm
import io.realm.RealmResults import io.realm.RealmResults
import kotlinx.android.synthetic.main.fragment_data_list.* import kotlinx.android.synthetic.main.fragment_data_list.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.ObjectSavable
import net.pokeranalytics.android.ui.activity.EditableDataActivity import net.pokeranalytics.android.ui.activity.EditableDataActivity
import net.pokeranalytics.android.ui.adapter.components.* import net.pokeranalytics.android.ui.adapter.components.*
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.SettingRow import net.pokeranalytics.android.ui.view.SettingRow
import net.pokeranalytics.android.ui.view.SimpleRow
import timber.log.Timber import timber.log.Timber
class DataListFragment : PokerAnalyticsFragment(), LiveDataDelegate { class DataListFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, RowRepresentableDelegate {
private lateinit var dataType: SettingRow private lateinit var dataType: SettingRow
@ -31,20 +35,21 @@ class DataListFragment : PokerAnalyticsFragment(), LiveDataDelegate {
initUI() initUI()
} }
override fun data(position: Int): LiveDataDataSource {
return (items[position] as LiveDataDataSource) override fun dataForPosition(position: Int): RowRepresentableDataSource? {
return this.items[position] as RowRepresentableDataSource
}
override fun size(): Int {
return this.items.size
} }
override fun onRowSelected(position: Int) { override fun dataSelected(data: RowRepresentableDataSource) {
this.dataType.relatedResultsRepresentable?.let { this.dataType.relatedResultsRepresentable?.let {
EditableDataActivity.newInstance(requireContext(), it.ordinal, this.data(position).primaryKey) EditableDataActivity.newInstance(requireContext(), it.ordinal, (data as ObjectSavable).uniqueIdentifier())
} }
} }
override fun size(): Int {
return items.size
}
private fun initData() { private fun initData() {
} }
@ -54,7 +59,7 @@ class DataListFragment : PokerAnalyticsFragment(), LiveDataDelegate {
private fun initUI() { private fun initUI() {
val viewManager = LinearLayoutManager(requireContext()) val viewManager = LinearLayoutManager(requireContext())
val dataListAdapter = LiveDataAdapter(this) val dataListAdapter = RowRepresentableAdapter(this, this)
recyclerView.apply { recyclerView.apply {
setHasFixedSize(true) setHasFixedSize(true)

@ -112,7 +112,7 @@ class EditableDataFragment : PokerAnalyticsFragment(), RowRepresentableDelegate,
Toast.makeText(requireContext(), "isManaged", Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), "isManaged", Toast.LENGTH_SHORT).show()
Timber.d("is managed") Timber.d("is managed")
this.getRealm().executeTransaction { this.getRealm().executeTransaction {
this.liveDataType.deleteData(it, (this.item as LiveDataDataSource)) this.liveDataType.deleteData(it, (this.item as ObjectSavable))
} }
} else { } else {
Toast.makeText(requireContext(), "isNotManaged", Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), "isNotManaged", Toast.LENGTH_SHORT).show()

@ -9,14 +9,13 @@ import kotlinx.android.synthetic.main.bottom_sheet_list.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.* import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Game import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.ui.adapter.components.LiveDataAdapter import net.pokeranalytics.android.ui.adapter.components.*
import net.pokeranalytics.android.ui.adapter.components.LiveDataDataSource import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.adapter.components.LiveDataDelegate
class BottomSheetListFragment : BottomSheetFragment(), LiveDataDelegate { class BottomSheetListFragment : BottomSheetFragment(), RowRepresentableDelegate, RowRepresentableDataSource {
private var realmData: RealmResults<*>? = null private var realmData: RealmResults<*>? = null
private lateinit var dataAdapter: LiveDataAdapter private lateinit var dataAdapter: RowRepresentableAdapter
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
@ -29,22 +28,16 @@ class BottomSheetListFragment : BottomSheetFragment(), LiveDataDelegate {
dataAdapter.notifyDataSetChanged() dataAdapter.notifyDataSetChanged()
} }
override fun data(position: Int): LiveDataDataSource { override fun dataForPosition(position: Int): RowRepresentableDataSource? {
realmData?.let { return this.realmData?.let {
return it[position] as LiveDataDataSource it[position] as RowRepresentableDataSource
} }
//TODO: Change that return null
return Game()
} }
override fun onRowSelected(position: Int) { override fun dataSelected(data: RowRepresentableDataSource) {
realmData?.let { bottomSheetDelegate.setValue(data, row)
val selectedData = it[position] dismiss()
selectedData?.let {data ->
bottomSheetDelegate.setValue(data, row)
dismiss()
}
}
} }
override fun size(): Int { override fun size(): Int {
@ -70,7 +63,7 @@ class BottomSheetListFragment : BottomSheetFragment(), LiveDataDelegate {
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_list, view?.bottomSheetContainer, true) LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_list, view?.bottomSheetContainer, true)
val viewManager = LinearLayoutManager(requireContext()) val viewManager = LinearLayoutManager(requireContext())
dataAdapter = LiveDataAdapter(this, R.layout.row_bottom_sheet_title) dataAdapter = RowRepresentableAdapter(this, this, R.layout.row_bottom_sheet_title)
reyclerView.apply { reyclerView.apply {
setHasFixedSize(true) setHasFixedSize(true)

@ -1,20 +1,52 @@
package net.pokeranalytics.android.ui.fragment.components.bottomsheet package net.pokeranalytics.android.ui.fragment.components.bottomsheet
import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import kotlinx.android.synthetic.main.bottom_sheet_grid.* import kotlinx.android.synthetic.main.bottom_sheet_grid.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.* import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.ui.adapter.TableSizeGridAdapter import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.adapter.components.*
import net.pokeranalytics.android.ui.view.GridSpacingItemDecoration import net.pokeranalytics.android.ui.view.GridSpacingItemDecoration
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.px import net.pokeranalytics.android.util.px
class TableSize(private 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.GRID_TITLE.ordinal
}
class BottomSheetTableSizeGridFragment : BottomSheetFragment() { class BottomSheetTableSizeGridFragment : BottomSheetFragment(), RowRepresentableDataSource, RowRepresentableDelegate {
private var dataList: ArrayList<String> = ArrayList() private lateinit var dataAdapter: RowRepresentableAdapter
private lateinit var dataAdapter: TableSizeGridAdapter
private var defaultSize: Int? = null private var defaultSize: Int? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -41,12 +73,6 @@ class BottomSheetTableSizeGridFragment : BottomSheetFragment() {
if (bottomSheetData.isNotEmpty() && bottomSheetData.first().defaultValue != null) { if (bottomSheetData.isNotEmpty() && bottomSheetData.first().defaultValue != null) {
defaultSize = bottomSheetData.first().defaultValue as Int? defaultSize = bottomSheetData.first().defaultValue as Int?
} }
dataList.add(getString(net.pokeranalytics.android.R.string.heads_up))
for (i in 3..10) {
dataList.add("$i-max")
}
} }
/** /**
@ -60,11 +86,7 @@ class BottomSheetTableSizeGridFragment : BottomSheetFragment() {
.inflate(net.pokeranalytics.android.R.layout.bottom_sheet_grid, view?.bottomSheetContainer, true) .inflate(net.pokeranalytics.android.R.layout.bottom_sheet_grid, view?.bottomSheetContainer, true)
val viewManager = GridLayoutManager(requireContext(), 3) val viewManager = GridLayoutManager(requireContext(), 3)
dataAdapter = TableSizeGridAdapter(dataList) dataAdapter = RowRepresentableAdapter(this, this)
dataAdapter.onClickOnItem = { position ->
bottomSheetDelegate.setValue(position + 2, row)
dismiss()
}
val spanCount = 3 val spanCount = 3
val spacing = 2.px val spacing = 2.px
@ -76,7 +98,29 @@ class BottomSheetTableSizeGridFragment : BottomSheetFragment() {
adapter = dataAdapter adapter = dataAdapter
addItemDecoration(GridSpacingItemDecoration(spanCount, spacing, includeEdge)) addItemDecoration(GridSpacingItemDecoration(spanCount, spacing, includeEdge))
} }
}
override fun rowRepresentableForPosition(position: Int): RowRepresentable? {
return TableSize.all[position]
}
override fun positionForRowRepresentable(rowRepresentable: RowRepresentable): Int? {
return TableSize.all.indexOf(rowRepresentable)
}
override fun size(): Int {
return TableSize.all.size
}
override fun onRowSelected(row: RowRepresentable) {
bottomSheetDelegate.setValue(null, this.row)
dismiss()
} }
override fun stringForRow(row: RowRepresentable): String {
this.context?.let {
return row.localizedTitle(it)
}
return "UNKNOWN CONTEXT FOR ROW $row"
}
} }

@ -3,6 +3,8 @@ package net.pokeranalytics.android.ui.view
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatTextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.row_title_value_action.view.* import kotlinx.android.synthetic.main.row_title_value_action.view.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
@ -12,9 +14,7 @@ import net.pokeranalytics.android.ui.adapter.components.RowRepresentableDataSour
* An interface used to factor the configuration of RecyclerView.ViewHolder * An interface used to factor the configuration of RecyclerView.ViewHolder
*/ */
interface BindableHolder { interface BindableHolder {
fun bind(row: RowRepresentable, rowRepresentableDataSource: RowRepresentableDataSource? = null, listener: View.OnClickListener, actionListener: View.OnClickListener? = null) {} fun bind(row: RowRepresentable, rowRepresentableDataSource: RowRepresentableDataSource? = null, listener: View.OnClickListener, actionListener: View.OnClickListener? = null) {}
} }
enum class RowViewType { enum class RowViewType {
@ -22,7 +22,9 @@ enum class RowViewType {
EDIT_TEXT, EDIT_TEXT,
TITLE, TITLE,
TITLE_VALUE, TITLE_VALUE,
TITLE_VALUE_ACTION; TITLE_VALUE_ACTION,
DATA,
GRID_TITLE;
inner class FakeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), inner class FakeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
BindableHolder { BindableHolder {
@ -55,7 +57,6 @@ enum class RowViewType {
override fun bind(row: RowRepresentable, rowRepresentableDataSource: RowRepresentableDataSource?, listener: View.OnClickListener, actionListener: View.OnClickListener?) { override fun bind(row: RowRepresentable, rowRepresentableDataSource: RowRepresentableDataSource?, listener: View.OnClickListener, actionListener: View.OnClickListener?) {
itemView.title.text = row.localizedTitle(itemView.context) itemView.title.text = row.localizedTitle(itemView.context)
rowRepresentableDataSource?.let { rowDelegate -> rowRepresentableDataSource?.let { rowDelegate ->
val value = rowDelegate.stringForRow(row) val value = rowDelegate.stringForRow(row)
itemView.value.text = value itemView.value.text = value
itemView.action.visibility = if (value == "--") View.GONE else View.VISIBLE itemView.action.visibility = if (value == "--") View.GONE else View.VISIBLE
@ -68,8 +69,25 @@ enum class RowViewType {
} }
} }
inner class CellSessionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
override fun bind(row: RowRepresentable, rowRepresentableDataSource: RowRepresentableDataSource?, listener: View.OnClickListener, actionListener: View.OnClickListener?) {
itemView.title.text = row.localizedTitle(itemView.context)
itemView.container.setOnClickListener(listener)
}
}
inner class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
override fun bind(row: RowRepresentable, rowRepresentableDataSource: RowRepresentableDataSource?, listener: View.OnClickListener, actionListener: View.OnClickListener?) {
try {
itemView.findViewById<AppCompatTextView>(R.id.title).text = rowRepresentableDataSource?.stringForRow(SimpleRow.NAME)
itemView.findViewById<ConstraintLayout>(R.id.container).setOnClickListener(listener)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
fun viewHolder(parent: ViewGroup): RecyclerView.ViewHolder { fun viewHolder(parent: ViewGroup, layout: Int? = null): RecyclerView.ViewHolder {
return when (this) { return when (this) {
TITLE -> TitleViewHolder( TITLE -> TitleViewHolder(
LayoutInflater.from(parent.context).inflate( LayoutInflater.from(parent.context).inflate(
@ -92,7 +110,12 @@ enum class RowViewType {
false false
) )
) )
GRID_TITLE -> return CellSessionViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_bottom_sheet_grid_title, parent, false))
DATA -> {
val layoutToInflate = layout ?: R.layout.row_title
return DataViewHolder(LayoutInflater.from(parent.context).inflate(layoutToInflate, parent, false))
}
else -> FakeViewHolder(parent) else -> FakeViewHolder(parent)
} }
} }

Loading…
Cancel
Save