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.fillMaxHeight
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.Divider import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect 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.screen.ScrollStateKeys
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
import com.vitorpamplona.amethyst.ui.theme.RoyalBlue import com.vitorpamplona.amethyst.ui.theme.RoyalBlue
import com.vitorpamplona.amethyst.ui.theme.chartStyle
import java.math.BigDecimal import java.math.BigDecimal
import java.math.RoundingMode import java.math.RoundingMode
import java.text.DecimalFormat import java.text.DecimalFormat
@@ -192,7 +194,25 @@ fun SummaryBar(model: UserReactionsViewModel) {
.padding(vertical = 10.dp, horizontal = 20.dp) .padding(vertical = 10.dp, horizontal = 20.dp)
.clickable(onClick = { showChart = !showChart }) .clickable(onClick = { showChart = !showChart })
) { ) {
ProvideChartStyle() { ProvideChartStyle(
chartStyle = MaterialTheme.colors.chartStyle
) {
ObserveAndShowChart(model, lineChartCount, lineChartZaps)
}
}
}
Divider(
thickness = 0.25.dp
)
}
@Composable
private fun ObserveAndShowChart(
model: UserReactionsViewModel,
lineChartCount: LineChart,
lineChartZaps: LineChart
) {
val axisModel by model.axisLabels.collectAsState() val axisModel by model.axisLabels.collectAsState()
val chartModel by model.chartModel.collectAsState() val chartModel by model.chartModel.collectAsState()
chartModel?.let { chartModel?.let {
@@ -212,13 +232,6 @@ fun SummaryBar(model: UserReactionsViewModel) {
) )
) )
} }
}
}
}
Divider(
thickness = 0.25.dp
)
} }
@Stable @Stable
@@ -28,6 +28,8 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.halilibo.richtext.ui.RichTextStyle import com.halilibo.richtext.ui.RichTextStyle
import com.halilibo.richtext.ui.resolveDefaults 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 import com.vitorpamplona.amethyst.ui.screen.ThemeViewModel
private val DarkColorPalette = darkColors( private val DarkColorPalette = darkColors(
@@ -302,6 +304,22 @@ val Colors.replyModifier: Modifier
val Colors.innerPostModifier: Modifier val Colors.innerPostModifier: Modifier
get() = if (isLight) LightInnerPostBorderModifier else DarkInnerPostBorderModifier 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 @Composable
fun AmethystTheme(themeViewModel: ThemeViewModel, content: @Composable () -> Unit) { fun AmethystTheme(themeViewModel: ThemeViewModel, content: @Composable () -> Unit) {
val theme = themeViewModel.theme.observeAsState() val theme = themeViewModel.theme.observeAsState()