diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt index b6cfa111..de378bd6 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt @@ -9,6 +9,7 @@ import com.github.mikephil.charting.charts.BarLineChartBase import com.github.mikephil.charting.charts.LineChart import com.github.mikephil.charting.data.* import com.github.mikephil.charting.highlight.Highlight +import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet import com.github.mikephil.charting.listener.OnChartValueSelectedListener import kotlinx.android.synthetic.main.fragment_graph.* import net.pokeranalytics.android.R @@ -132,7 +133,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { this.legendView.prepareWithStat(this.stat, dataSet.entryCount, this.style) if (dataSet.entryCount > 0) { val entry = dataSet.getEntryForIndex(dataSet.entryCount - 1) - this.selectValue(entry, dataSet.label) + this.selectValue(entry, dataSet) } } @@ -184,12 +185,14 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { } } + val dataSet = this.chartView?.data?.getDataSetForEntry(e) + e?.let { entry -> - this.selectValue(entry, groupName) + this.selectValue(entry, dataSet) } } - private fun selectValue(entry: Entry, groupName: String) { + private fun selectValue(entry: Entry, dataSet: IBarLineScatterCandleBubbleDataSet? = null) { val statEntry = when (entry.data) { is ObjectIdentifier -> { @@ -201,8 +204,10 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { } statEntry?.let { + val groupName = dataSet?.label ?: "" + val color = dataSet?.color val legendValue = it.legendValues(stat, entry, this.style, groupName, requireContext()) - this.legendView.setItemData(legendValue) + this.legendView.setItemData(legendValue, color) } } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/LegendView.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/LegendView.kt index 1a46c2a0..f00f98cc 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/LegendView.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/LegendView.kt @@ -100,7 +100,7 @@ open class LegendView : FrameLayout { /** * */ - open fun setItemData(content: LegendContent) { + open fun setItemData(content: LegendContent, color: Int?) { if (content is DefaultLegendValues) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/MultiLineLegendView.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/MultiLineLegendView.kt index 79c84b2c..53bc4237 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/MultiLineLegendView.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/MultiLineLegendView.kt @@ -1,7 +1,12 @@ package net.pokeranalytics.android.ui.view import android.content.Context -import kotlinx.android.synthetic.main.layout_legend_default.view.* +import android.graphics.drawable.GradientDrawable +import kotlinx.android.synthetic.main.layout_legend_color.view.* +import kotlinx.android.synthetic.main.layout_legend_default.view.stat1Name +import kotlinx.android.synthetic.main.layout_legend_default.view.stat1Value +import kotlinx.android.synthetic.main.layout_legend_default.view.stat2Name +import kotlinx.android.synthetic.main.layout_legend_default.view.stat2Value import net.pokeranalytics.android.R import net.pokeranalytics.android.calculus.Stat import net.pokeranalytics.android.calculus.TextFormat @@ -24,7 +29,7 @@ class MultiLineLegendView(context: Context) : LegendView(context = context) { override fun prepareWithStat(stat: Stat, counter: Int?, style: GraphFragment.Style) { } - override fun setItemData(content: LegendContent) { + override fun setItemData(content: LegendContent, color: Int?) { if (content is MultilineLegendValues) { @@ -33,6 +38,16 @@ class MultiLineLegendView(context: Context) : LegendView(context = context) { this.stat1Value.setTextFormat(content.leftFormat, context) this.stat2Value.setTextFormat(content.rightFormat, context) + + color?.let { + val drawable = this.coloredCircle.background + when (drawable) { + is GradientDrawable -> { + drawable.setColor(it) + } else -> {} + } + } + } } diff --git a/app/src/main/res/layout/layout_legend_color.xml b/app/src/main/res/layout/layout_legend_color.xml index b51c93be..7fd49b54 100644 --- a/app/src/main/res/layout/layout_legend_color.xml +++ b/app/src/main/res/layout/layout_legend_color.xml @@ -55,8 +55,10 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" + android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/stat2Value" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/stat2Name" tools:text="$2000" />