Merge branch 'master' of gitlab.com:stax-river/poker-analytics

# Conflicts:
#	app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableAdapter.kt
feature/top10
Aurelien Hubert 7 years ago
commit c6651f2462
  1. 4
      app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt
  2. 7
      app/src/main/java/net/pokeranalytics/android/calculus/Computable.kt
  3. 83
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableAdapter.kt
  4. 84
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt
  5. 22
      app/src/main/java/net/pokeranalytics/android/ui/datasource/StatsDataSource.kt
  6. 49
      app/src/main/java/net/pokeranalytics/android/ui/fragment/StatsFragment.kt
  7. 3
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt

@ -94,6 +94,10 @@ class Calculator {
var results: ComputedResults = ComputedResults() var results: ComputedResults = ComputedResults()
if (sessions.size == 0) {
return results
}
var sum: Double = 0.0 var sum: Double = 0.0
var totalHands: Double = 0.0 var totalHands: Double = 0.0
var bbSum: Double = 0.0 var bbSum: Double = 0.0

@ -97,6 +97,13 @@ class ComputedResults() {
} }
} }
/**
* Returns the number of computed stats
*/
fun numberOfStats() : Int {
return this._computedStats.size
}
} }
class Point(x: Double, y: Double) { class Point(x: Double, y: Double) {

@ -1,99 +1,18 @@
package net.pokeranalytics.android.ui.adapter package net.pokeranalytics.android.ui.adapter
import android.content.Context
import android.view.ViewGroup import android.view.ViewGroup
import android.content.Context
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
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.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
interface RowRepresentableDataSource : DisplayableDataSource {
fun rowRepresentableForPosition(position:Int): RowRepresentable {
if (this.numberOfRows() > position) {
return this.adapterRows()[position]
} else {
throw IllegalStateException("Need to implement Data Source")
}
}
fun numberOfRows(): Int {
return this.adapterRows().size
}
fun viewTypeForPosition(position:Int): Int {
return this.rowRepresentableForPosition(position).viewType
}
fun indexForRow(row:RowRepresentable): Int {
return this.adapterRows().indexOf(row)
}
/**
* A list of [RowRepresentableEditDescriptor] object specifying the way the edition will be handled
*/
fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor> {
return ArrayList()
}
}
interface RowRepresentableDelegate { interface RowRepresentableDelegate {
fun onRowSelected(position: Int, row: RowRepresentable, fromAction:Boolean = false) {} fun onRowSelected(position: Int, row: RowRepresentable, fromAction:Boolean = false) {}
fun onRowValueChanged(value: Any?, row: RowRepresentable) {} fun onRowValueChanged(value: Any?, row: RowRepresentable) {}
} }
/**
* An interface used to provide RowRepresentableAdapter content and value in the form of rows
*/
interface DisplayableDataSource {
/**
* Returns a list of rows
*/
fun adapterRows(): ArrayList<RowRepresentable> {
return ArrayList()
}
/**
* Returns a boolean for a specific row
*/
fun boolForRow(row: RowRepresentable): Boolean {
return false
}
/**
* Returns a localized string for a specific row
*/
fun stringForRow(row: RowRepresentable, context: Context): String {
return stringForRow(row)
}
/**
* Returns a string for a specific row
*/
fun stringForRow(row: RowRepresentable): String {
return ""
}
/**
* Returns an action icon identifier for a specific row
*/
fun actionIconForRow(row: RowRepresentable): Int? {
return 0
}
/**
* Manages:
* - label (string)
* - segmented control (live/online)
* - textfield (string)
* - switch (bool)
* - static content
* */
}
/** /**
* An adapter capable of displaying a list of RowRepresentables * An adapter capable of displaying a list of RowRepresentables
* @param dataSource the datasource providing rows * @param dataSource the datasource providing rows

@ -0,0 +1,84 @@
package net.pokeranalytics.android.ui.adapter
import android.content.Context
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
interface RowRepresentableDataSource : DisplayableDataSource {
fun rowRepresentableForPosition(position:Int): RowRepresentable {
if (this.numberOfRows() > position) {
return this.adapterRows()[position]
} else {
throw IllegalStateException("Need to implement Data Source")
}
}
fun numberOfRows(): Int {
return this.adapterRows().size
}
fun viewTypeForPosition(position:Int): Int {
return this.rowRepresentableForPosition(position).viewType
}
fun indexForRow(row: RowRepresentable): Int {
return this.adapterRows().indexOf(row)
}
/**
* A list of [RowRepresentableEditDescriptor] object specifying the way the edition will be handled
*/
fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor> {
return ArrayList()
}
}
/**
* An interface used to provide RowRepresentableAdapter content and value in the form of rows
*
* Also returns the appropriate value for any RowRepresentable in the form of :
* - string
* - booleans
* - actionIcon
* to display the appropriate values in graphical components, such as labels, textfields, switchs...
*/
interface DisplayableDataSource {
/**
* Returns a list of rows
*/
fun adapterRows(): ArrayList<RowRepresentable> {
return ArrayList()
}
/**
* Returns a boolean for a specific row
*/
fun boolForRow(row: RowRepresentable): Boolean {
return false
}
/**
* Returns a localized string for a specific row
*/
fun stringForRow(row: RowRepresentable, context: Context): String {
return stringForRow(row)
}
/**
* Returns a string for a specific row
*/
fun stringForRow(row: RowRepresentable): String {
return ""
}
/**
* Returns an action icon identifier for a specific row
*/
fun actionIconForRow(row: RowRepresentable): Int? {
return 0
}
}

@ -0,0 +1,22 @@
package net.pokeranalytics.android.ui.datasource
import net.pokeranalytics.android.calculus.ComputedResults
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
class StatsDataSource(results: List<ComputedResults>) : RowRepresentableDataSource {
var results: List<ComputedResults> = results
override fun adapterRows(): ArrayList<RowRepresentable> {
return ArrayList<RowRepresentable>()
}
override fun numberOfRows(): Int {
return 0
// return this.results.fold(0) { acc, computedResults ->
// return acc + computedResults.numberOfStats()
// }
}
}

@ -5,23 +5,20 @@ 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 kotlinx.android.synthetic.main.fragment_settings.* import io.realm.Realm
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.android.synthetic.main.fragment_stats.* import kotlinx.android.synthetic.main.fragment_stats.*
import kotlinx.coroutines.runBlocking
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.Calculator import net.pokeranalytics.android.calculus.Calculator
import net.pokeranalytics.android.calculus.ComputedResults import net.pokeranalytics.android.calculus.ComputedResults
import net.pokeranalytics.android.calculus.SessionGroup import net.pokeranalytics.android.calculus.SessionGroup
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.extensions.SessionType import net.pokeranalytics.android.model.extensions.SessionType
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource import net.pokeranalytics.android.ui.datasource.StatsDataSource
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
class StatsFragment : PokerAnalyticsFragment(), RowRepresentableDataSource { class StatsFragment : PokerAnalyticsFragment() {
companion object { companion object {
@ -39,11 +36,8 @@ class StatsFragment : PokerAnalyticsFragment(), RowRepresentableDataSource {
private lateinit var statsAdapterRow: RowRepresentableAdapter private lateinit var statsAdapterRow: RowRepresentableAdapter
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_stats, container, false) return inflater.inflate(R.layout.fragment_stats, container, false)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -51,38 +45,21 @@ class StatsFragment : PokerAnalyticsFragment(), RowRepresentableDataSource {
initData() initData()
} }
override fun adapterRows(): ArrayList<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
rows.addAll(Stat.values())
return rows
}
/** /**
* Init data * Init data
*/ */
private fun initData() { private fun initData() {
this.launchStatComputation()
val viewManager = LinearLayoutManager(requireContext())
this.statsAdapterRow = RowRepresentableAdapter(
this
)
recyclerView.apply {
setHasFixedSize(true)
layoutManager = viewManager
adapter = statsAdapterRow
}
// this.launchStatComputation()
} }
private fun launchStatComputation() { private fun launchStatComputation() {
var results = listOf<ComputedResults>() var results = listOf<ComputedResults>()
GlobalScope.launch { runBlocking {
val allSessions = getRealm().where(Session::class.java).findAll() val realm = Realm.getDefaultInstance()
val allSessions = realm.where(Session::class.java).findAll()
val cgSessions = mutableListOf<Session>() val cgSessions = mutableListOf<Session>()
val tSessions = mutableListOf<Session>() val tSessions = mutableListOf<Session>()
@ -101,6 +78,16 @@ class StatsFragment : PokerAnalyticsFragment(), RowRepresentableDataSource {
results = Calculator.computeGroups(listOf(allSessionGroup, cgSessionGroup, tSessionGroup), Calculator.Options()) results = Calculator.computeGroups(listOf(allSessionGroup, cgSessionGroup, tSessionGroup), Calculator.Options())
} }
this.statsAdapterRow = RowRepresentableAdapter(StatsDataSource(results))
val viewManager = LinearLayoutManager(requireContext())
recyclerView.apply {
setHasFixedSize(true)
layoutManager = viewManager
adapter = statsAdapterRow
}
} }
} }

@ -29,6 +29,7 @@ interface BindableHolder {
} }
enum class RowViewType { enum class RowViewType {
HEADER, HEADER,
HEADER_TITLE_VALUE, HEADER_TITLE_VALUE,
@ -290,7 +291,7 @@ enum class RowViewType {
parent, parent,
false) false)
) )
else -> FakeViewHolder(parent) else -> throw Exception("Undefined RowViewType's holder")
} }
} }

Loading…
Cancel
Save