|
|
|
@ -4,6 +4,7 @@ import android.os.Bundle |
|
|
|
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.core.view.isVisible |
|
|
|
import com.github.mikephil.charting.charts.BarChart |
|
|
|
import com.github.mikephil.charting.charts.BarChart |
|
|
|
import com.github.mikephil.charting.charts.BarLineChartBase |
|
|
|
import com.github.mikephil.charting.charts.BarLineChartBase |
|
|
|
import com.github.mikephil.charting.charts.LineChart |
|
|
|
import com.github.mikephil.charting.charts.LineChart |
|
|
|
@ -14,7 +15,7 @@ import com.github.mikephil.charting.listener.OnChartValueSelectedListener |
|
|
|
import com.google.android.material.chip.Chip |
|
|
|
import com.google.android.material.chip.Chip |
|
|
|
import com.google.android.material.chip.ChipGroup |
|
|
|
import com.google.android.material.chip.ChipGroup |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.Realm |
|
|
|
import kotlinx.android.synthetic.main.fragment_evograph.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_graph.* |
|
|
|
import kotlinx.coroutines.* |
|
|
|
import kotlinx.coroutines.* |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.calculus.* |
|
|
|
import net.pokeranalytics.android.calculus.* |
|
|
|
@ -40,39 +41,46 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
|
|
|
|
|
|
|
|
private var stat: Stat = Stat.NETRESULT |
|
|
|
private var stat: Stat = Stat.NETRESULT |
|
|
|
private var reports: MutableMap<AggregationType, Report> = hashMapOf() |
|
|
|
private var reports: MutableMap<AggregationType, Report> = hashMapOf() |
|
|
|
lateinit private var computableGroup: ComputableGroup |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lateinit private var selectedReport: Report |
|
|
|
private lateinit var computableGroup: ComputableGroup |
|
|
|
|
|
|
|
private lateinit var selectedReport: Report |
|
|
|
lateinit var legendView: LegendView |
|
|
|
private lateinit var legendView: LegendView |
|
|
|
lateinit var chartView: BarLineChartBase<*> |
|
|
|
private lateinit var chartView: BarLineChartBase<*> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var displayAggregationChoices: Boolean = true |
|
|
|
private var aggregationTypes: List<AggregationType> = listOf() |
|
|
|
private var aggregationTypes: List<AggregationType> = listOf() |
|
|
|
|
|
|
|
|
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
get() = Dispatchers.Main |
|
|
|
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? { |
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
return inflater.inflate(R.layout.fragment_evograph, container, false) |
|
|
|
return inflater.inflate(R.layout.fragment_graph, container, false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
initUI() |
|
|
|
initUI() |
|
|
|
|
|
|
|
loadGraph(selectedReport) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// OnChartValueSelectedListener |
|
|
|
|
|
|
|
override fun onNothingSelected() { |
|
|
|
|
|
|
|
// nothing to do |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onValueSelected(e: Entry?, h: Highlight?) { |
|
|
|
|
|
|
|
e?.let { entry -> |
|
|
|
|
|
|
|
val identifier = entry.data as ObjectIdentifier |
|
|
|
|
|
|
|
val item = getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull() |
|
|
|
|
|
|
|
item?.let { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val formattedDate = DateFormat.getDateInstance(DateFormat.SHORT).format(it.startDate()) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -86,8 +94,6 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
this.legendView = LegendView(requireContext()) |
|
|
|
this.legendView = LegendView(requireContext()) |
|
|
|
this.legendContainer.addView(this.legendView) |
|
|
|
this.legendContainer.addView(this.legendView) |
|
|
|
|
|
|
|
|
|
|
|
this.loadGraph(this.selectedReport) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.aggregationTypes.forEach { type -> |
|
|
|
this.aggregationTypes.forEach { type -> |
|
|
|
val chip = Chip(requireContext()) |
|
|
|
val chip = Chip(requireContext()) |
|
|
|
chip.id = type.ordinal |
|
|
|
chip.id = type.ordinal |
|
|
|
@ -97,6 +103,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
this.chipGroup.addView(chip) |
|
|
|
this.chipGroup.addView(chip) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.chipGroup.isVisible = displayAggregationChoices |
|
|
|
this.chipGroup.check(this.stat.aggregationTypes.first().ordinal) |
|
|
|
this.chipGroup.check(this.stat.aggregationTypes.first().ordinal) |
|
|
|
|
|
|
|
|
|
|
|
this.chipGroup.setOnCheckedChangeListener(object : ChipGroupExtension.SingleSelectionOnCheckedListener() { |
|
|
|
this.chipGroup.setOnCheckedChangeListener(object : ChipGroupExtension.SingleSelectionOnCheckedListener() { |
|
|
|
@ -147,8 +154,10 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
fun loadGraph(report: Report) { |
|
|
|
* Load graph |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private fun loadGraph(report: Report) { |
|
|
|
|
|
|
|
|
|
|
|
report.results.firstOrNull()?.defaultStatEntries(stat)?.let { entries -> |
|
|
|
report.results.firstOrNull()?.defaultStatEntries(stat)?.let { entries -> |
|
|
|
|
|
|
|
|
|
|
|
@ -183,29 +192,17 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// OnChartValueSelectedListener |
|
|
|
/** |
|
|
|
|
|
|
|
* Set data |
|
|
|
override fun onNothingSelected() { |
|
|
|
*/ |
|
|
|
// nothing to do |
|
|
|
fun setData(stat: Stat, group: ComputableGroup, report: Report, displayAggregationChoices: Boolean) { |
|
|
|
} |
|
|
|
this.stat = stat |
|
|
|
|
|
|
|
this.computableGroup = group |
|
|
|
override fun onValueSelected(e: Entry?, h: Highlight?) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e?.let { entry -> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val identifier = entry.data as ObjectIdentifier |
|
|
|
|
|
|
|
val item = getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull() |
|
|
|
|
|
|
|
item?.let { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val formattedDate = DateFormat.getDateInstance(DateFormat.SHORT).format(it.startDate()) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.aggregationTypes = stat.aggregationTypes |
|
|
|
|
|
|
|
this.reports[this.aggregationTypes.first()] = report |
|
|
|
|
|
|
|
this.selectedReport = report |
|
|
|
|
|
|
|
this.displayAggregationChoices = displayAggregationChoices |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |