feature/top10
Aurelien Hubert 7 years ago
parent 55f427624c
commit 29932cc92f
  1. 94
      app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.charts.BarLineChartBase
import com.github.mikephil.charting.charts.LineChart
@ -48,34 +49,19 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
}
private lateinit var parentActivity: PokerAnalyticsActivity
private lateinit var computableGroup: ComputableGroup
private lateinit var selectedReport: Report
private lateinit var legendView: LegendView
private lateinit var chartView: BarLineChartBase<*>
private var stat: Stat = Stat.NETRESULT
private var reports: MutableMap<AggregationType, Report> = hashMapOf()
lateinit private var computableGroup: ComputableGroup
lateinit private var selectedReport: Report
lateinit var legendView: LegendView
lateinit var chartView: BarLineChartBase<*>
private var aggregationTypes: List<AggregationType> = listOf()
private var displayAggregationChoices: Boolean = true
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main
companion object {
}
fun setData(stat: Stat, group: ComputableGroup, report: Report) {
this.stat = stat
this.computableGroup = group
this.aggregationTypes = stat.aggregationTypes
this.reports[this.aggregationTypes.first()] = report
this.selectedReport = report
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_evograph, container, false)
@ -86,6 +72,35 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
initUI()
}
// OnChartValueSelectedListener
override fun onNothingSelected() {
// nothing to do
}
override fun onValueSelected(e: Entry?, h: Highlight?) {
e?.let { entry ->
val statEntry = when (entry.data) {
is ObjectIdentifier -> {
val identifier = entry.data as ObjectIdentifier
getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull()
}
is StatEntry -> entry.data as StatEntry?
else -> null
}
statEntry?.let {
val formattedDate = it.entryTitle
val entryValue = it.formattedValue(this.stat, requireContext())
val totalStatValue = this.stat.format(e.y.toDouble(), currency = null, context = requireContext())
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue)
}
}
}
/**
* Init UI
*/
@ -116,6 +131,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
this.chipGroup.addView(chip)
}
this.chipGroup.isVisible = displayAggregationChoices
this.chipGroup.check(this.stat.aggregationTypes.first().ordinal)
this.chipGroup.setOnCheckedChangeListener(object : ChipGroupExtension.SingleSelectionOnCheckedListener() {
@ -209,35 +225,17 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
}
// OnChartValueSelectedListener
override fun onNothingSelected() {
// nothing to do
}
override fun onValueSelected(e: Entry?, h: Highlight?) {
e?.let { entry ->
val statEntry = when (entry.data) {
is ObjectIdentifier -> {
val identifier = entry.data as ObjectIdentifier
getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull()
}
is StatEntry -> entry.data as StatEntry?
else -> null
}
statEntry?.let {
val formattedDate = it.entryTitle
val entryValue = it.formattedValue(this.stat, requireContext())
val totalStatValue = this.stat.format(e.y.toDouble(), currency = null, context = requireContext())
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue)
}
/**
* Set data
*/
fun setData(stat: Stat, group: ComputableGroup, report: Report, displayAggregationChoices: Boolean = true) {
this.stat = stat
this.computableGroup = group
}
this.aggregationTypes = stat.aggregationTypes
this.reports[this.aggregationTypes.first()] = report
this.selectedReport = report
this.displayAggregationChoices = displayAggregationChoices
}

Loading…
Cancel
Save