Fixes the color of the chart for changes in the Apps theme in settings
This commit is contained in:
+33
-20
@@ -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,26 +194,10 @@ 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(
|
||||||
val axisModel by model.axisLabels.collectAsState()
|
chartStyle = MaterialTheme.colors.chartStyle
|
||||||
val chartModel by model.chartModel.collectAsState()
|
) {
|
||||||
chartModel?.let {
|
ObserveAndShowChart(model, lineChartCount, lineChartZaps)
|
||||||
Chart(
|
|
||||||
chart = remember(lineChartCount, lineChartZaps) {
|
|
||||||
lineChartCount.plus(lineChartZaps)
|
|
||||||
},
|
|
||||||
model = it,
|
|
||||||
startAxis = startAxis(
|
|
||||||
valueFormatter = CountAxisValueFormatter()
|
|
||||||
),
|
|
||||||
endAxis = endAxis(
|
|
||||||
valueFormatter = AmountAxisValueFormatter()
|
|
||||||
),
|
|
||||||
bottomAxis = bottomAxis(
|
|
||||||
valueFormatter = LabelValueFormatter(axisModel)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
@Stable
|
||||||
class LabelValueFormatter(val axisLabels: List<String>) : AxisValueFormatter<AxisPosition.Horizontal.Bottom> {
|
class LabelValueFormatter(val axisLabels: List<String>) : AxisValueFormatter<AxisPosition.Horizontal.Bottom> {
|
||||||
override fun formatValue(
|
override fun formatValue(
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user