Legend refactoring

feature/top10
Laurent 7 years ago
parent 250c41cde5
commit 36865f5d2f
  1. 19
      app/src/main/java/net/pokeranalytics/android/calculus/Report.kt
  2. 21
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  3. 4
      app/src/main/java/net/pokeranalytics/android/ui/adapter/ReportPagerAdapter.kt
  4. 23
      app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt
  5. 11
      app/src/main/java/net/pokeranalytics/android/ui/graph/GraphUnderlyingEntry.kt
  6. 38
      app/src/main/java/net/pokeranalytics/android/ui/view/LegendView.kt
  7. 22
      app/src/main/java/net/pokeranalytics/android/ui/view/MultiLineLegendView.kt

@ -13,7 +13,8 @@ import net.pokeranalytics.android.model.realm.SessionSet
import net.pokeranalytics.android.ui.fragment.GraphFragment
import net.pokeranalytics.android.ui.graph.GraphUnderlyingEntry
import net.pokeranalytics.android.ui.graph.PALineDataSet
import net.pokeranalytics.android.ui.view.LegendView
import net.pokeranalytics.android.ui.view.DefaultLegendValues
import net.pokeranalytics.android.ui.view.LegendContent
import net.pokeranalytics.android.util.ColorUtils
import kotlin.math.abs
@ -448,23 +449,23 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu
override fun legendValues(
stat: Stat,
entry: Entry,
legendType: GraphFragment.LegendType,
style: GraphFragment.Style,
groupName: String,
context: Context
): LegendView.Values {
): LegendContent {
when (legendType) {
when (style) {
GraphFragment.LegendType.DEFAULT_BAR -> {
GraphFragment.Style.BAR -> {
return when (stat) {
Stat.NUMBER_OF_SETS, Stat.NUMBER_OF_GAMES, Stat.WIN_RATIO -> {
val totalStatValue = stat.format(entry.y.toDouble(), currency = null)
LegendView.Values(this.entryTitle, totalStatValue)
DefaultLegendValues(this.entryTitle, totalStatValue)
}
else -> {
val entryValue = this.formattedValue(stat)
val countValue = this.computedStat(Stat.NUMBER_OF_GAMES)?.format()
LegendView.Values(this.entryTitle, entryValue, countValue)
DefaultLegendValues(this.entryTitle, entryValue, countValue)
}
}
}
@ -473,12 +474,12 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu
return when (stat) {
Stat.NUMBER_OF_SETS, Stat.NUMBER_OF_GAMES, Stat.WIN_RATIO -> {
val totalStatValue = stat.format(entry.y.toDouble(), currency = null)
LegendView.Values(this.entryTitle, totalStatValue)
DefaultLegendValues(this.entryTitle, totalStatValue)
}
else -> {
val entryValue = this.formattedValue(stat)
val totalStatValue = stat.format(entry.y.toDouble(), currency = null)
LegendView.Values(this.entryTitle, entryValue, totalStatValue)
DefaultLegendValues(this.entryTitle, entryValue, totalStatValue)
}
}

@ -28,10 +28,7 @@ import net.pokeranalytics.android.model.utils.SessionSetManager
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.UnmanagedRowRepresentableException
import net.pokeranalytics.android.ui.fragment.GraphFragment
import net.pokeranalytics.android.ui.view.LegendView
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.*
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.SeparatorRow
import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow
@ -963,19 +960,21 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
override fun legendValues(
stat: Stat,
entry: Entry,
legendType: GraphFragment.LegendType,
style: GraphFragment.Style,
groupName: String,
context: Context
) : LegendView.Values {
) : LegendContent {
when (legendType) {
GraphFragment.LegendType.MULTILINE -> {
when (style) {
GraphFragment.Style.MULTILINE -> {
val secondTitle = stat.localizedTitle(context)
val entryValue = this.formattedValue(stat)
val dateValue = TextFormat(this.entryTitle)
return LegendView.MultiLineValues(groupName, secondTitle, entryValue, dateValue)
return MultilineLegendValues(groupName, secondTitle, entryValue, dateValue)
}
else -> {
@ -992,10 +991,10 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
}
}
LegendView.Values(this.entryTitle, left, right)
DefaultLegendValues(this.entryTitle, left, right)
}
else -> {
super.legendValues(stat, entry, legendType, groupName, context)
super.legendValues(stat, entry, style, groupName, context)
}
}
}

@ -24,11 +24,11 @@ class ReportPagerAdapter(val context: Context, val fragmentManager: FragmentMana
return when (position) {
0 -> {
val dataSetList = listOf(report.barEntries(null, context))
GraphFragment.newInstance(barDataSets = dataSetList, legendType = GraphFragment.LegendType.DEFAULT_BAR)
GraphFragment.newInstance(barDataSets = dataSetList, style = GraphFragment.Style.BAR)
}
1 -> {
val dataSetList = report.multiLineEntries(context = context)
GraphFragment.newInstance(lineDataSets = dataSetList, legendType = GraphFragment.LegendType.MULTILINE)
GraphFragment.newInstance(lineDataSets = dataSetList, style = GraphFragment.Style.MULTILINE)
}
2 -> {
TableReportFragment.newInstance(report)

@ -26,9 +26,9 @@ import timber.log.Timber
class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener {
enum class LegendType {
DEFAULT,
DEFAULT_BAR,
enum class Style {
LINE,
BAR,
MULTILINE,
}
@ -37,9 +37,9 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener {
/**
* Create new instance
*/
fun newInstance(lineDataSets: List<LineDataSet>? = null, barDataSets: List<BarDataSet>? = null, legendType: LegendType = LegendType.DEFAULT): GraphFragment {
fun newInstance(lineDataSets: List<LineDataSet>? = null, barDataSets: List<BarDataSet>? = null, style: Style = Style.LINE): GraphFragment {
val fragment = GraphFragment()
fragment.legendType = legendType
fragment.style = style
fragment.lineDataSetList = lineDataSets
fragment.barDataSetList = barDataSets
val bundle = Bundle()
@ -51,7 +51,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener {
private lateinit var parentActivity: PokerAnalyticsActivity
private var legendType: LegendType = LegendType.DEFAULT
private var style: Style = Style.LINE
private lateinit var legendView: LegendView
private var lineDataSetList: List<LineDataSet>? = null
@ -103,8 +103,8 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener {
parentActivity = activity as PokerAnalyticsActivity
parentActivity.title = stat.localizedTitle(requireContext())
this.legendView = when (this.legendType) {
LegendType.MULTILINE -> MultiLineLegendView(requireContext())
this.legendView = when (this.style) {
Style.MULTILINE -> MultiLineLegendView(requireContext())
else -> LegendView(requireContext())
}
@ -132,7 +132,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener {
this.chartView = lineChart
dataSets.firstOrNull()?.let {
this.legendView.prepareWithStat(this.stat, it.entryCount, this.legendType)
this.legendView.prepareWithStat(this.stat, it.entryCount, this.style)
lastEntry = it.getEntryForIndex(it.entryCount - 1)
groupName = it.label
}
@ -141,7 +141,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener {
this.barDataSetList?.let { dataSets ->
this.legendView.prepareWithStat(this.stat, legendType = this.legendType)
this.legendView.prepareWithStat(this.stat, style = this.style)
val barChart = BarChart(context)
if (stat.showXAxisZero) {
barChart.xAxis.axisMinimum = 0.0f
@ -202,8 +202,9 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener {
is GraphUnderlyingEntry -> entry.data as GraphUnderlyingEntry?
else -> null
}
statEntry?.let {
val legendValue = it.legendValues(stat, entry, this.legendType, groupName, requireContext())
val legendValue = it.legendValues(stat, entry, this.style, groupName, requireContext())
this.legendView.setItemData(legendValue)
}
}

@ -5,7 +5,8 @@ import com.github.mikephil.charting.data.Entry
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.calculus.TextFormat
import net.pokeranalytics.android.ui.fragment.GraphFragment
import net.pokeranalytics.android.ui.view.LegendView
import net.pokeranalytics.android.ui.view.DefaultLegendValues
import net.pokeranalytics.android.ui.view.LegendContent
interface GraphUnderlyingEntry {
@ -15,20 +16,20 @@ interface GraphUnderlyingEntry {
fun legendValues(
stat: Stat,
entry: Entry,
legendType: GraphFragment.LegendType,
style: GraphFragment.Style,
groupName: String,
context: Context
): LegendView.Values {
): LegendContent {
return when (stat) {
Stat.NUMBER_OF_SETS, Stat.NUMBER_OF_GAMES, Stat.WIN_RATIO -> {
val totalStatValue = stat.format(entry.y.toDouble(), currency = null)
LegendView.Values(this.entryTitle, totalStatValue)
DefaultLegendValues(this.entryTitle, totalStatValue)
}
else -> {
val entryValue = this.formattedValue(stat)
val totalStatValue = stat.format(entry.y.toDouble(), currency = null)
LegendView.Values(this.entryTitle, entryValue, totalStatValue)
DefaultLegendValues(this.entryTitle, entryValue, totalStatValue)
}
}

@ -13,13 +13,26 @@ import net.pokeranalytics.android.calculus.TextFormat
import net.pokeranalytics.android.ui.extensions.setTextFormat
import net.pokeranalytics.android.ui.fragment.GraphFragment
interface LegendContent
data class DefaultLegendValues(
var title: String,
var leftFormat: TextFormat,
var rightFormat: TextFormat? = null
) : LegendContent
/**
* Display a row session
*/
open class LegendView : FrameLayout {
open class Values(var title: String, var leftFormat: TextFormat, var rightFormat: TextFormat? = null)
class MultiLineValues(var firstTitle: String, var secondTitle: String, leftFormat: TextFormat, rightFormat: TextFormat? = null) : Values("", leftFormat, rightFormat)
// open class Values(var title: String, var leftFormat: TextFormat, var rightFormat: TextFormat? = null)
// class MultiLineValues(
// var firstTitle: String,
// var secondTitle: String,
// leftFormat: TextFormat,
// rightFormat: TextFormat? = null
// ) : Values("", leftFormat, rightFormat)
private lateinit var legendLayout: ConstraintLayout
@ -55,15 +68,15 @@ open class LegendView : FrameLayout {
/**
* Set the stat data to the view
*/
open fun prepareWithStat(stat: Stat, counter: Int? = null, legendType: GraphFragment.LegendType) {
open fun prepareWithStat(stat: Stat, counter: Int? = null, style: GraphFragment.Style) {
when (legendType) {
GraphFragment.LegendType.DEFAULT_BAR -> {
when (style) {
GraphFragment.Style.BAR -> {
this.stat1Name.text = stat.localizedTitle(context)
this.stat2Name.text = context.getString(R.string.sessions)
this.counter.isVisible = false
}
GraphFragment.LegendType.DEFAULT -> {
GraphFragment.Style.LINE -> {
if (stat.significantIndividualValue) {
this.stat1Name.text = stat.localizedTitle(context)
this.stat2Name.text = stat.cumulativeLabelResId(context)
@ -87,15 +100,20 @@ open class LegendView : FrameLayout {
/**
*
*/
open fun setItemData(values: Values) {
open fun setItemData(content: LegendContent) {
if (content is DefaultLegendValues) {
this.title.text = values.title
this.title.text = content.title
this.stat1Value.setTextFormat(values.leftFormat, context)
values.rightFormat?.let {
this.stat1Value.setTextFormat(content.leftFormat, context)
content.rightFormat?.let {
this.stat2Value.setTextFormat(it, context)
}
}
}
}

@ -4,27 +4,35 @@ import android.content.Context
import kotlinx.android.synthetic.main.layout_legend_default.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.calculus.TextFormat
import net.pokeranalytics.android.ui.extensions.setTextFormat
import net.pokeranalytics.android.ui.fragment.GraphFragment
data class MultilineLegendValues(
var firstTitle: String,
var secondTitle: String,
var leftFormat: TextFormat,
var rightFormat: TextFormat
) : LegendContent
class MultiLineLegendView(context: Context) : LegendView(context = context) {
override fun getResourceLayout(): Int {
return R.layout.layout_legend_color
}
override fun prepareWithStat(stat: Stat, counter: Int?, legendType: GraphFragment.LegendType) {
override fun prepareWithStat(stat: Stat, counter: Int?, style: GraphFragment.Style) {
}
override fun setItemData(values: Values) {
override fun setItemData(content: LegendContent) {
if (values is MultiLineValues) {
if (content is MultilineLegendValues) {
this.stat1Name.text = values.firstTitle
this.stat2Name.text = values.secondTitle
this.stat1Name.text = content.firstTitle
this.stat2Name.text = content.secondTitle
this.stat1Value.setTextFormat(values.leftFormat, context)
this.stat2Value.text = values.title
this.stat1Value.setTextFormat(content.leftFormat, context)
this.stat2Value.setTextFormat(content.rightFormat, context)
}
}

Loading…
Cancel
Save