|
|
|
|
@ -18,6 +18,7 @@ import net.pokeranalytics.android.databinding.FragmentGraphBinding |
|
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.ObjectIdentifier |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
|
|
|
|
import net.pokeranalytics.android.ui.graph.Graph |
|
|
|
|
import net.pokeranalytics.android.ui.graph.GraphUnderlyingEntry |
|
|
|
|
import net.pokeranalytics.android.ui.graph.setStyle |
|
|
|
|
import net.pokeranalytics.android.ui.view.LegendView |
|
|
|
|
@ -37,18 +38,12 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener { |
|
|
|
|
return this.graphDataProvider.stat |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum class Style { |
|
|
|
|
LINE, |
|
|
|
|
BAR, |
|
|
|
|
MULTILINE, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create new instance |
|
|
|
|
*/ |
|
|
|
|
fun newInstance(style: Style): GraphFragment { |
|
|
|
|
fun newInstance(style: Graph.Style): GraphFragment { |
|
|
|
|
val fragment = GraphFragment() |
|
|
|
|
val bundle = Bundle() |
|
|
|
|
bundle.putSerializable(BundleKey.STYLE.value, style.ordinal) |
|
|
|
|
@ -58,7 +53,7 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private var style: Style = Style.LINE |
|
|
|
|
private var style: Graph.Style = Graph.Style.LINE |
|
|
|
|
|
|
|
|
|
private lateinit var legendView: LegendView |
|
|
|
|
|
|
|
|
|
@ -69,7 +64,7 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener { |
|
|
|
|
|
|
|
|
|
// Life Cycle |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { |
|
|
|
|
super.onCreateView(inflater, container, savedInstanceState) |
|
|
|
|
_binding = FragmentGraphBinding.inflate(inflater, container, false) |
|
|
|
|
return binding.root |
|
|
|
|
@ -89,7 +84,7 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener { |
|
|
|
|
|
|
|
|
|
private fun initData() { |
|
|
|
|
val styleOrdinal = this.arguments?.getInt(BundleKey.STYLE.value) ?: throw PAIllegalStateException("Missing style key in bundle") |
|
|
|
|
this.style = Style.values()[styleOrdinal] |
|
|
|
|
this.style = Graph.Style.values()[styleOrdinal] |
|
|
|
|
|
|
|
|
|
this.graphDataProvider = (requireActivity() as ViewModelHolder).model as GraphDataProvider |
|
|
|
|
} |
|
|
|
|
@ -100,14 +95,14 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener { |
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
this.legendView = when (this.style) { |
|
|
|
|
Style.MULTILINE -> MultiLineLegendView(requireContext()) |
|
|
|
|
Graph.Style.MULTILINE -> MultiLineLegendView(requireContext()) |
|
|
|
|
else -> LegendView(requireContext()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.binding.legendContainer.addView(this.legendView) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun reload(style: Style) { |
|
|
|
|
fun reload(style: Graph.Style) { |
|
|
|
|
this.style = style |
|
|
|
|
if (isAdded && !isDetached) { |
|
|
|
|
loadGraph() |
|
|
|
|
@ -122,11 +117,11 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener { |
|
|
|
|
this.binding.chartContainer.removeAllViews() |
|
|
|
|
|
|
|
|
|
this.chartView = when (this.style) { |
|
|
|
|
Style.LINE, Style.MULTILINE -> { |
|
|
|
|
Graph.Style.LINE, Graph.Style.MULTILINE -> { |
|
|
|
|
|
|
|
|
|
val dataSets = when (this.style) { |
|
|
|
|
Style.LINE -> listOf(this.graphDataProvider.lineDataSet(requireContext())) |
|
|
|
|
Style.MULTILINE -> this.graphDataProvider.multiLineDataSet(requireContext()) |
|
|
|
|
Graph.Style.LINE -> listOf(this.graphDataProvider.lineDataSet(requireContext())) |
|
|
|
|
Graph.Style.MULTILINE -> this.graphDataProvider.multiLineDataSet(requireContext()) |
|
|
|
|
else -> throw PAIllegalStateException("Cannot happen") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -146,7 +141,7 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener { |
|
|
|
|
|
|
|
|
|
lineChart |
|
|
|
|
} |
|
|
|
|
Style.BAR -> { |
|
|
|
|
Graph.Style.BAR -> { |
|
|
|
|
|
|
|
|
|
val dataSets = listOf(this.graphDataProvider.barDataSet(requireContext())) |
|
|
|
|
|
|
|
|
|
@ -209,7 +204,7 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener { |
|
|
|
|
|
|
|
|
|
val groupName = dataSet?.label ?: "" |
|
|
|
|
val color = dataSet?.color |
|
|
|
|
val legendValue = statEntry.legendValues(stat, entry, this.style, groupName, requireContext()) |
|
|
|
|
val legendValue = statEntry.legendValues(stat, entry.y.toDouble(), this.style, groupName, requireContext()) |
|
|
|
|
this.legendView.setItemData(legendValue, color) |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|