Added comments + refactoring

dev_raz_wip
Laurent 7 years ago
parent 6fef3aab3b
commit 7f4ca18d1c
  1. 4
      app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt
  2. 39
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  3. 30
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/RowRepresentableAdapter.kt
  4. 13
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt

@ -3,7 +3,9 @@ package net.pokeranalytics.android.calculus
import net.pokeranalytics.android.calculus.Stat.* import net.pokeranalytics.android.calculus.Stat.*
import net.pokeranalytics.android.model.realm.SessionSet import net.pokeranalytics.android.model.realm.SessionSet
/**
* The class performing stats computation
*/
class Calculator { class Calculator {
class Options { class Options {

@ -4,11 +4,10 @@ import net.pokeranalytics.android.R
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
interface AnyStat { /**
* An enum representing all the types of Session statistics
} */
enum class Stat : RowRepresentable {
enum class Stat : AnyStat, RowRepresentable {
NETRESULT, NETRESULT,
HOURLY_RATE, HOURLY_RATE,
@ -79,11 +78,9 @@ enum class Stat : AnyStat, RowRepresentable {
override val viewType: Int = RowViewType.TITLE_VALUE.ordinal override val viewType: Int = RowViewType.TITLE_VALUE.ordinal
} }
enum class CashSessionStat : AnyStat { /**
NETBB, * ComputedStat contains a [stat] and their associated [value]
AVERAGEBB */
}
class ComputedStat(stat: Stat, value: Double) { class ComputedStat(stat: Stat, value: Double) {
constructor(stat: Stat, value: Double, previousValue: Double?) : this(stat, value) { constructor(stat: Stat, value: Double, previousValue: Double?) : this(stat, value) {
@ -92,23 +89,31 @@ class ComputedStat(stat: Stat, value: Double) {
} }
} }
// The statistic type /**
* The statistic type
*/
var stat: Stat = stat var stat: Stat = stat
// The stat value /**
* The stat value
*/
var value: Double = value var value: Double = value
// The variation of the stat /**
* The variation of the stat
*/
var variation: Double? = null var variation: Double? = null
// The data points leading to the current stat value /**
// var points: List<Point> = mutableListOf() * Formats the value of the stat to be suitable for display
*/
// Formats the value of the stat to be suitable for display
fun format() : StatFormat { fun format() : StatFormat {
return StatFormat() return StatFormat()
} }
/**
* Returns a StatFormat instance for an evolution value located at the specified [index]
*/
fun evolutionValueFormat(index: Int) : StatFormat { fun evolutionValueFormat(index: Int) : StatFormat {
return StatFormat() return StatFormat()
} }

@ -3,22 +3,37 @@ package net.pokeranalytics.android.ui.adapter.components
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.DynamicHolder 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
/**
* An interface used to provide RowRepresentableAdapter content and value in the form of rows
*/
interface RowRepresentableDataSource { interface RowRepresentableDataSource {
/**
* Returns a list of rows
*/
fun adapterRows(): ArrayList<RowRepresentable> fun adapterRows(): ArrayList<RowRepresentable>
/**
* Returns a boolean for a specific row
*/
fun boolForRow(row: RowRepresentable): Boolean { fun boolForRow(row: RowRepresentable): Boolean {
return false return false
} }
/**
* Returns a string for a specific row
*/
fun stringForRow(row: RowRepresentable): String { fun stringForRow(row: RowRepresentable): String {
return "" return ""
} }
/**
* Returns an action icon identifier for a specific row
*/
fun actionIconForRow(row: RowRepresentable): Int? { fun actionIconForRow(row: RowRepresentable): Int? {
return 0 return 0
} }
@ -34,14 +49,25 @@ interface RowRepresentableDataSource {
} }
/**
* A delegate used to propagate UI actions
*/
interface RowRepresentableDelegate { interface RowRepresentableDelegate {
fun onRowSelected(row: RowRepresentable) {} fun onRowSelected(row: RowRepresentable) {}
fun onActionSelected(row: RowRepresentable) {} fun onActionSelected(row: RowRepresentable) {}
} }
/**
* An adapter capable of displaying a list of RowRepresentables
* @param rowRepresentableDataSource the datasource providing rows
* @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) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() { RecyclerView.Adapter<RecyclerView.ViewHolder>() {
/**
* The list of rows to display
*/
private var rows: ArrayList<RowRepresentable> = ArrayList() private var rows: ArrayList<RowRepresentable> = ArrayList()
init { init {
@ -72,7 +98,7 @@ class RowRepresentableAdapter(var rowRepresentableDataSource: RowRepresentableDa
rowRepresentableDelegate?.onActionSelected(dynamicRow) rowRepresentableDelegate?.onActionSelected(dynamicRow)
} }
(holder as DynamicHolder).bind(dynamicRow, this.rowRepresentableDataSource, listener, actionListener) (holder as BindableHolder).bind(dynamicRow, this.rowRepresentableDataSource, listener, actionListener)
} }
/** /**

@ -8,7 +8,10 @@ import kotlinx.android.synthetic.main.row_title_value_action.view.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.adapter.components.RowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.components.RowRepresentableDataSource
interface DynamicHolder { /**
* An interface used to factor the configuration of RecyclerView.ViewHolder
*/
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) {}
@ -22,13 +25,13 @@ enum class RowViewType {
TITLE_VALUE_ACTION; TITLE_VALUE_ACTION;
inner class FakeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), inner class FakeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
DynamicHolder { BindableHolder {
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?) {
} }
} }
inner class TitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), inner class TitleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
DynamicHolder { BindableHolder {
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)
itemView.container.setOnClickListener(listener) itemView.container.setOnClickListener(listener)
@ -36,7 +39,7 @@ enum class RowViewType {
} }
inner class TitleValueViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), inner class TitleValueViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
DynamicHolder { BindableHolder {
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)
@ -48,7 +51,7 @@ enum class RowViewType {
} }
inner class TitleValueActionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), inner class TitleValueActionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
DynamicHolder { BindableHolder {
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 ->

Loading…
Cancel
Save