Fixes the color of the chart for changes in the Apps theme in settings

This commit is contained in:
Vitor Pamplona
2023-08-16 21:03:50 -04:00
parent 6721c83266
commit c49f89f711
2 changed files with 51 additions and 20 deletions
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
@@ -56,6 +57,7 @@ import com.vitorpamplona.amethyst.ui.screen.RefresheableCardView
import com.vitorpamplona.amethyst.ui.screen.ScrollStateKeys
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
import com.vitorpamplona.amethyst.ui.theme.RoyalBlue
import com.vitorpamplona.amethyst.ui.theme.chartStyle
import java.math.BigDecimal
import java.math.RoundingMode
import java.text.DecimalFormat
@@ -192,26 +194,10 @@ fun SummaryBar(model: UserReactionsViewModel) {
.padding(vertical = 10.dp, horizontal = 20.dp)
.clickable(onClick = { showChart = !showChart })
) {
ProvideChartStyle() {
val axisModel by model.axisLabels.collectAsState()
val chartModel by model.chartModel.collectAsState()
chartModel?.let {
Chart(
chart = remember(lineChartCount, lineChartZaps) {
lineChartCount.plus(lineChartZaps)
},
model = it,
startAxis = startAxis(
valueFormatter = CountAxisValueFormatter()
),
endAxis = endAxis(
valueFormatter = AmountAxisValueFormatter()
),
bottomAxis = bottomAxis(
valueFormatter = LabelValueFormatter(axisModel)
)
)
}
ProvideChartStyle(
chartStyle = MaterialTheme.colors.chartStyle
) {
ObserveAndShowChart(model, lineChartCount, lineChartZaps)
}
}
}
@@ -221,6 +207,33 @@ fun SummaryBar(model: UserReactionsViewModel) {
)
}
@Composable
private fun ObserveAndShowChart(
model: UserReactionsViewModel,
lineChartCount: LineChart,
lineChartZaps: LineChart
) {
val axisModel by model.axisLabels.collectAsState()
val chartModel by model.chartModel.collectAsState()
chartModel?.let {
Chart(
chart = remember(lineChartCount, lineChartZaps) {
lineChartCount.plus(lineChartZaps)
},
model = it,
startAxis = startAxis(
valueFormatter = CountAxisValueFormatter()
),
endAxis = endAxis(
valueFormatter = AmountAxisValueFormatter()
),
bottomAxis = bottomAxis(
valueFormatter = LabelValueFormatter(axisModel)
)
)
}
}
@Stable
class LabelValueFormatter(val axisLabels: List<String>) : AxisValueFormatter<AxisPosition.Horizontal.Bottom> {
override fun formatValue(
@@ -28,6 +28,8 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp
import com.halilibo.richtext.ui.RichTextStyle
import com.halilibo.richtext.ui.resolveDefaults
import com.patrykandpatrick.vico.compose.style.ChartStyle
import com.patrykandpatrick.vico.core.DefaultColors
import com.vitorpamplona.amethyst.ui.screen.ThemeViewModel
private val DarkColorPalette = darkColors(
@@ -302,6 +304,22 @@ val Colors.replyModifier: Modifier
val Colors.innerPostModifier: Modifier
get() = if (isLight) LightInnerPostBorderModifier else DarkInnerPostBorderModifier
val Colors.chartStyle: ChartStyle
get() {
val defaultColors = if (isLight) DefaultColors.Light else DefaultColors.Dark
return ChartStyle.fromColors(
axisLabelColor = Color(defaultColors.axisLabelColor),
axisGuidelineColor = Color(defaultColors.axisGuidelineColor),
axisLineColor = Color(defaultColors.axisLineColor),
entityColors = listOf(
defaultColors.entity1Color,
defaultColors.entity2Color,
defaultColors.entity3Color
).map(::Color),
elevationOverlayColor = Color(defaultColors.elevationOverlayColor)
)
}
@Composable
fun AmethystTheme(themeViewModel: ThemeViewModel, content: @Composable () -> Unit) {
val theme = themeViewModel.theme.observeAsState()