mirror of
https://github.com/PranshulGG/WeatherMaster.git
synced 2026-10-21 18:43:03 -05:00
Glance widget text color can now be changed closes #942
This commit is contained in:
1 parent
a6dcd6bbd3
commit
cd2de7f75c
2 files changed
+54
-13
No files matched your search
@@ -6,6 +6,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.glance.GlanceId
|
||||
import androidx.glance.GlanceModifier
|
||||
import androidx.glance.GlanceTheme
|
||||
import androidx.glance.Image
|
||||
import androidx.glance.ImageProvider
|
||||
import androidx.glance.LocalContext
|
||||
@@ -36,6 +37,7 @@ import com.pranshulgg.weather_master_app.widgets.WeatherWidgetStateJson
|
||||
import com.pranshulgg.weather_master_app.widgets.model.WidgetWeather
|
||||
import com.pranshulgg.weather_master_app.widgets.params.WidgetSizePoints
|
||||
import com.pranshulgg.weather_master_app.widgets.ui.ReloadButton
|
||||
import com.pranshulgg.weather_master_app.widgets.ui.colors.WidgetColors
|
||||
import com.pranshulgg.weather_master_app.widgets.ui.views.WidgetClock
|
||||
import com.pranshulgg.weather_master_app.widgets.ui.views.WidgetDate
|
||||
import kotlinx.serialization.json.Json
|
||||
@@ -60,6 +62,7 @@ class GlanceWidget : GlanceAppWidget() {
|
||||
val size = LocalSize.current
|
||||
val widgetState = currentState<WeatherWidgetStateJson>()
|
||||
val context = LocalContext.current
|
||||
val widgetColors = WidgetColors()
|
||||
|
||||
val json = widgetState.json
|
||||
val state = json?.let {
|
||||
@@ -71,12 +74,16 @@ class GlanceWidget : GlanceAppWidget() {
|
||||
.clickable(actionStartActivity<MainActivity>())
|
||||
) {
|
||||
if (state != null) {
|
||||
val textColor = widgetColors
|
||||
.getTextColor(config.widgetTextTheme, config.widgetTheme)
|
||||
?: Pair(GlanceTheme.colors.onSurface, null)
|
||||
|
||||
Column(GlanceModifier.fillMaxWidth().padding(16.dp)) {
|
||||
if (config.showClock) {
|
||||
WidgetClock(config.clockSize, context, R.color.white)
|
||||
WidgetClock(config.clockSize, context, textColor.second)
|
||||
}
|
||||
|
||||
WidgetDate(config.dateFormat, context, size = 20f, color = R.color.white)
|
||||
WidgetDate(config.dateFormat, context, size = 20f, color = textColor.second)
|
||||
|
||||
Spacer(GlanceModifier.height(5.dp))
|
||||
Row() {
|
||||
@@ -98,9 +105,9 @@ class GlanceWidget : GlanceAppWidget() {
|
||||
Text(
|
||||
"${state.currentTemp} • ",
|
||||
style = TextStyle(
|
||||
color = ColorProvider(R.color.white),
|
||||
color = textColor.first,
|
||||
fontSize = 18.sp
|
||||
)
|
||||
),
|
||||
)
|
||||
}
|
||||
Box {
|
||||
@@ -115,7 +122,7 @@ class GlanceWidget : GlanceAppWidget() {
|
||||
Text(
|
||||
state.currentCondition,
|
||||
style = TextStyle(
|
||||
color = ColorProvider(R.color.white),
|
||||
color = textColor.first,
|
||||
fontSize = 18.sp
|
||||
)
|
||||
)
|
||||
|
||||
+42
-8
@@ -45,6 +45,8 @@ import com.pranshulgg.weather_master_app.core.ui.components.tiles.DialogOption
|
||||
import com.pranshulgg.weather_master_app.core.ui.theme.ShapeRadius
|
||||
import com.pranshulgg.weather_master_app.core.utils.formatters.toSafeDouble
|
||||
import com.pranshulgg.weather_master_app.widgets.config.WidgetConfig
|
||||
import com.pranshulgg.weather_master_app.widgets.ui.colors.WidgetTextTheme
|
||||
import com.pranshulgg.weather_master_app.widgets.ui.colors.WidgetTheme
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@@ -73,6 +75,10 @@ fun GlanceWidgetConfig(onDone: (WidgetConfig) -> Unit = {}) {
|
||||
val formatsOptions = formats.map { DialogOption(it, it) }
|
||||
val clockSizeOptions = clockSizes.map { DialogOption(it.toString(), "${it.roundToInt()}.sp") }
|
||||
|
||||
var widgetTextTheme by remember { mutableStateOf(WidgetTextTheme.WHITE) }
|
||||
val widgetTextThemeOptions =
|
||||
WidgetTextTheme.entries.filter { it != WidgetTextTheme.AUTO }
|
||||
.map { DialogOption(it.toString(), stringResource(it.label)) }
|
||||
|
||||
Scaffold(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceContainer
|
||||
@@ -90,7 +96,7 @@ fun GlanceWidgetConfig(onDone: (WidgetConfig) -> Unit = {}) {
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
) {
|
||||
GlanceWidgetPreview(clockSize, showClock, dateFormat)
|
||||
GlanceWidgetPreview(clockSize, showClock, dateFormat, widgetTextTheme)
|
||||
}
|
||||
|
||||
SettingSection(
|
||||
@@ -121,6 +127,21 @@ fun GlanceWidgetConfig(onDone: (WidgetConfig) -> Unit = {}) {
|
||||
onOptionSelected = {
|
||||
dateFormat = it
|
||||
}
|
||||
),
|
||||
SettingTile.DialogOptionTile(
|
||||
leading = { SettingsTileIcon(R.drawable.format_paint_24px) },
|
||||
title = "Widget text color",
|
||||
options = widgetTextThemeOptions,
|
||||
selectedOption = widgetTextTheme.toString(),
|
||||
onOptionSelected = {
|
||||
val selected = when (it) {
|
||||
"WHITE" -> WidgetTextTheme.WHITE
|
||||
"BLACK" -> WidgetTextTheme.BLACK
|
||||
else -> WidgetTextTheme.WHITE
|
||||
}
|
||||
|
||||
widgetTextTheme = selected
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -132,7 +153,8 @@ fun GlanceWidgetConfig(onDone: (WidgetConfig) -> Unit = {}) {
|
||||
WidgetConfig(
|
||||
clockSize = clockSize,
|
||||
showClock = showClock,
|
||||
dateFormat = dateFormat
|
||||
dateFormat = dateFormat,
|
||||
widgetTextTheme = widgetTextTheme
|
||||
)
|
||||
)
|
||||
},
|
||||
@@ -151,11 +173,21 @@ fun GlanceWidgetConfig(onDone: (WidgetConfig) -> Unit = {}) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GlanceWidgetPreview(clockSize: Float = 32f, showClock: Boolean = true, format: String) {
|
||||
private fun GlanceWidgetPreview(
|
||||
clockSize: Float = 32f,
|
||||
showClock: Boolean = true,
|
||||
format: String,
|
||||
textTheme: WidgetTextTheme
|
||||
) {
|
||||
|
||||
val textColor = when (textTheme) {
|
||||
WidgetTextTheme.BLACK -> Color.Black
|
||||
WidgetTextTheme.WHITE -> Color.White
|
||||
else -> Color.White
|
||||
}
|
||||
val style = TextStyle(
|
||||
shadow = Shadow(
|
||||
color = Color(0xFF000000).copy(alpha = 0.8f),
|
||||
color = Color.Black.copy(alpha = 0.8f),
|
||||
blurRadius = 4f,
|
||||
offset = Offset(2f, 2f)
|
||||
)
|
||||
@@ -168,12 +200,14 @@ private fun GlanceWidgetPreview(clockSize: Float = 32f, showClock: Boolean = tru
|
||||
else -> "Thu 18 Jun"
|
||||
}
|
||||
|
||||
|
||||
|
||||
Column(Modifier.padding(16.dp)) {
|
||||
if (showClock) {
|
||||
Text(
|
||||
"03:23",
|
||||
fontSize = clockSize.sp,
|
||||
color = Color(0xFFEEF0FF),
|
||||
color = textColor,
|
||||
fontWeight = FontWeight.Bold,
|
||||
style = style
|
||||
)
|
||||
@@ -181,15 +215,15 @@ private fun GlanceWidgetPreview(clockSize: Float = 32f, showClock: Boolean = tru
|
||||
Text(
|
||||
date,
|
||||
fontSize = 20.sp,
|
||||
color = Color(0xFFEEF0FF),
|
||||
color = textColor,
|
||||
style = style
|
||||
)
|
||||
Gap(5.dp)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
WeatherIconBox(R.drawable.weather_partly_cloudy_day, size = 24.dp)
|
||||
Gap(horizontal = 5.dp)
|
||||
Text("29° • ", color = Color(0xFFEEF0FF), fontSize = 18.sp, style = style)
|
||||
Text("Clear sky", color = Color(0xFFEEF0FF), fontSize = 18.sp, style = style)
|
||||
Text("29° • ", color = textColor, fontSize = 18.sp, style = style)
|
||||
Text("Clear sky", color = textColor, fontSize = 18.sp, style = style)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user