mirror of
https://github.com/PranshulGG/WeatherMaster.git
synced 2026-10-23 03:24:11 -05:00
add option to config Weather 4 widget date format closes #1018
This commit is contained in:
1 parent
afc91ad4d3
commit
dc246bae8d
8 files changed
+134
-91
No files matched your search
+66
-66
@@ -41,46 +41,46 @@ class WidgetConfigActivity : ComponentActivity() {
|
||||
initPrefs(this)
|
||||
enableEdgeToEdge()
|
||||
|
||||
val widgetId =
|
||||
intent.getIntExtra(
|
||||
AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
AppWidgetManager.INVALID_APPWIDGET_ID
|
||||
)
|
||||
|
||||
if (widgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
val provider =
|
||||
AppWidgetManager
|
||||
.getInstance(this)
|
||||
.getAppWidgetInfo(widgetId)
|
||||
?.provider
|
||||
setResult(RESULT_CANCELED)
|
||||
|
||||
val updater = WeatherWidgetUpdater(this)
|
||||
// val widgetId =
|
||||
// intent.getIntExtra(
|
||||
// AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
// AppWidgetManager.INVALID_APPWIDGET_ID
|
||||
// )
|
||||
//
|
||||
// if (widgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
// finish()
|
||||
// return
|
||||
// }
|
||||
// val provider =
|
||||
// AppWidgetManager
|
||||
// .getInstance(this)
|
||||
// .getAppWidgetInfo(widgetId)
|
||||
// ?.provider
|
||||
// setResult(RESULT_CANCELED)
|
||||
//
|
||||
// val updater = WeatherWidgetUpdater(this)
|
||||
|
||||
val onDone: (WidgetConfig) -> Unit = {
|
||||
lifecycleScope.launch {
|
||||
|
||||
updater.saveWidgetConfig(
|
||||
context = this@WidgetConfigActivity,
|
||||
widgetId,
|
||||
it
|
||||
)
|
||||
|
||||
setResult(
|
||||
RESULT_OK,
|
||||
Intent().apply {
|
||||
putExtra(
|
||||
AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
widgetId
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
finish()
|
||||
}
|
||||
// lifecycleScope.launch {
|
||||
//
|
||||
// updater.saveWidgetConfig(
|
||||
// context = this@WidgetConfigActivity,
|
||||
// widgetId,
|
||||
// it
|
||||
// )
|
||||
//
|
||||
// setResult(
|
||||
// RESULT_OK,
|
||||
// Intent().apply {
|
||||
// putExtra(
|
||||
// AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
// widgetId
|
||||
// )
|
||||
// }
|
||||
// )
|
||||
//
|
||||
// finish()
|
||||
// }
|
||||
}
|
||||
val theme = PreferencesHelper.getString("app_theme") ?: "Dark"
|
||||
|
||||
@@ -110,35 +110,35 @@ class WidgetConfigActivity : ComponentActivity() {
|
||||
dynamicTheme = true,
|
||||
themeVariantType = ThemeVariantType.EXPRESSIVE,
|
||||
) {
|
||||
when (provider?.className) {
|
||||
GlanceWidgetReceiver::class.java.name -> {
|
||||
GlanceWidgetConfig(onDone = { onDone(it) })
|
||||
}
|
||||
// when (provider?.className) {
|
||||
// GlanceWidgetReceiver::class.java.name -> {
|
||||
// GlanceWidgetConfig(onDone = { onDone(it) })
|
||||
// }
|
||||
//
|
||||
// ClockDailyWidgetReceiver::class.java.name -> {
|
||||
// ClockDailyWidgetConfig(onDone = { onDone(it) })
|
||||
// }
|
||||
//
|
||||
// WeatherWidgetReceiver::class.java.name -> {
|
||||
// WeatherWidgetConfig(onDone = { onDone(it) })
|
||||
// }
|
||||
//
|
||||
// WeatherHorizontalWidgetReceiver::class.java.name -> {
|
||||
// WeatherHorizontalConfig(onDone = { onDone(it) })
|
||||
// }
|
||||
//
|
||||
// Weather4WidgerReceiver::class.java.name -> {
|
||||
Weather4Config { onDone(it) }
|
||||
// }
|
||||
|
||||
ClockDailyWidgetReceiver::class.java.name -> {
|
||||
ClockDailyWidgetConfig(onDone = { onDone(it) })
|
||||
}
|
||||
|
||||
WeatherWidgetReceiver::class.java.name -> {
|
||||
WeatherWidgetConfig(onDone = { onDone(it) })
|
||||
}
|
||||
|
||||
WeatherHorizontalWidgetReceiver::class.java.name -> {
|
||||
WeatherHorizontalConfig(onDone = { onDone(it) })
|
||||
}
|
||||
|
||||
Weather4WidgerReceiver::class.java.name -> {
|
||||
Weather4Config { onDone(it) }
|
||||
}
|
||||
|
||||
WidgetHourlyReceiver::class.java.name -> {
|
||||
HourlyWidgetConfig { onDone(it) }
|
||||
}
|
||||
|
||||
UvIndexWidgetReceiver::class.java.name -> {
|
||||
UvIndexWidgetConfig { onDone(it) }
|
||||
}
|
||||
}
|
||||
// WidgetHourlyReceiver::class.java.name -> {
|
||||
// HourlyWidgetConfig { onDone(it) }
|
||||
// }
|
||||
//
|
||||
// UvIndexWidgetReceiver::class.java.name -> {
|
||||
// UvIndexWidgetConfig { onDone(it) }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+62
-19
@@ -74,6 +74,13 @@ fun Weather4Config(onDone: (WidgetConfig) -> Unit = {}) {
|
||||
it != WidgetVariant.LARGE && it != WidgetVariant.COMPACT && it != WidgetVariant.SMALL
|
||||
}
|
||||
|
||||
val formats = when (selectedVariant) {
|
||||
WidgetVariant.DATE_PILL -> listOf("EEE d MMMM", "EEE, MMMM d", "EEE MMM-dd")
|
||||
else -> listOf("EEEE, d MMMM", "EEEE, MMMM d", "EEEE MM-dd")
|
||||
}
|
||||
|
||||
var dateFormat by remember(selectedVariant) { mutableStateOf(if (selectedVariant == WidgetVariant.DATE_PILL) "EEE, MMMM d" else "EEEE, MMMM d") }
|
||||
val formatsOptions = formats.map { DialogOption(it, it) }
|
||||
var widgetTextTheme by remember { mutableStateOf(WidgetTextTheme.WHITE) }
|
||||
val widgetTextThemeOptions =
|
||||
WidgetTextTheme.entries.filter { it != WidgetTextTheme.AUTO }
|
||||
@@ -103,7 +110,8 @@ fun Weather4Config(onDone: (WidgetConfig) -> Unit = {}) {
|
||||
selectedVariant,
|
||||
widgetTextTheme,
|
||||
selectedFontSize,
|
||||
selectedIconSize, showDaily
|
||||
selectedIconSize, showDaily,
|
||||
dateFormat
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -144,6 +152,15 @@ fun Weather4Config(onDone: (WidgetConfig) -> Unit = {}) {
|
||||
SettingSection(
|
||||
title = stringResource(R.string.setting_appearance),
|
||||
tiles = listOf(
|
||||
SettingTile.DialogOptionTile(
|
||||
leading = { SettingsTileIcon(R.drawable.date_range_24px) },
|
||||
title = stringResource(R.string.settings_date_format),
|
||||
options = formatsOptions,
|
||||
selectedOption = dateFormat,
|
||||
onOptionSelected = {
|
||||
dateFormat = it
|
||||
}
|
||||
),
|
||||
SettingTile.SwitchTile(
|
||||
title = stringResource(R.string.settings_widget_show_daily_weather),
|
||||
description = stringResource(R.string.settings_widget_show_daily_weather_secondary),
|
||||
@@ -209,7 +226,8 @@ fun Weather4Config(onDone: (WidgetConfig) -> Unit = {}) {
|
||||
fontSize = selectedFontSize,
|
||||
iconSize = selectedIconSize,
|
||||
widgetTextTheme = widgetTextTheme,
|
||||
showDailyInsteadOfCurrent = showDaily
|
||||
showDailyInsteadOfCurrent = showDaily,
|
||||
dateFormat = dateFormat
|
||||
)
|
||||
)
|
||||
},
|
||||
@@ -235,7 +253,8 @@ private fun WidgetPreviews(
|
||||
widgetTextTheme: WidgetTextTheme,
|
||||
fontSize: Float,
|
||||
iconSize: Float,
|
||||
showDaily: Boolean
|
||||
showDaily: Boolean,
|
||||
format: String
|
||||
) {
|
||||
|
||||
val textColor = when (widgetTextTheme) {
|
||||
@@ -243,25 +262,41 @@ private fun WidgetPreviews(
|
||||
WidgetTextTheme.WHITE -> Color.White
|
||||
else -> Color.White
|
||||
}
|
||||
val date = when (format) {
|
||||
"EEE, d MMMM" -> "Wed, 18 June"
|
||||
"EEE, MMMM d" -> "Wed, June 18"
|
||||
"EEE MM-dd" -> "Wed 06-18"
|
||||
"EEEE, d MMMM" -> "Wednesday, 9 July"
|
||||
"EEEE, MMMM d" -> "Wednesday, July 9"
|
||||
"EEEE MM-dd" -> "Wednesday 05-29"
|
||||
else -> "Thu 18 Jun"
|
||||
}
|
||||
|
||||
when (variant) {
|
||||
WidgetVariant.DATE -> DateWidgetPreview(textColor, fontSize, iconSize, showDaily)
|
||||
WidgetVariant.DATE_PILL -> DatePillWidgetPreview(fontSize, iconSize, showDaily)
|
||||
WidgetVariant.CLOCK_DATE -> ClockDateWidgetPreview(textColor, fontSize, iconSize, showDaily)
|
||||
WidgetVariant.DATE -> DateWidgetPreview(textColor, fontSize, iconSize, showDaily, date)
|
||||
WidgetVariant.DATE_PILL -> DatePillWidgetPreview(fontSize, iconSize, showDaily, date)
|
||||
WidgetVariant.CLOCK_DATE -> ClockDateWidgetPreview(
|
||||
textColor,
|
||||
fontSize,
|
||||
iconSize,
|
||||
showDaily,
|
||||
date
|
||||
)
|
||||
|
||||
WidgetVariant.CLOCK_VERTICAL -> ClockVerticalWidgetPreview(
|
||||
textColor,
|
||||
fontSize,
|
||||
iconSize,
|
||||
showDaily
|
||||
showDaily, date
|
||||
)
|
||||
|
||||
WidgetVariant.CLOCK_HORIZONTAL -> ClockHorizontalWidgetPreview(
|
||||
textColor,
|
||||
fontSize,
|
||||
iconSize, showDaily
|
||||
iconSize, showDaily, date
|
||||
)
|
||||
|
||||
else -> DateWidgetPreview(textColor, fontSize, iconSize, showDaily)
|
||||
else -> DateWidgetPreview(textColor, fontSize, iconSize, showDaily, date)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +304,8 @@ private fun WidgetPreviews(
|
||||
private fun DateWidgetPreview(
|
||||
textColor: Color, fontSize: Float,
|
||||
iconSize: Float,
|
||||
showDaily: Boolean
|
||||
showDaily: Boolean,
|
||||
date: String
|
||||
) {
|
||||
|
||||
val icon = if (showDaily) R.drawable.rain_with_clear else R.drawable.weather_mostly_clear_day
|
||||
@@ -278,9 +314,11 @@ private fun DateWidgetPreview(
|
||||
val textSize = 20 * fontSize
|
||||
val temp = if (showDaily) "28°" else "24°"
|
||||
|
||||
|
||||
|
||||
Row(Modifier.height(120.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
"Wednesday, July 9 | ",
|
||||
"$date | ",
|
||||
fontSize = textSize.sp,
|
||||
color = textColor,
|
||||
fontWeight = FontWeight.Medium
|
||||
@@ -295,7 +333,8 @@ private fun DateWidgetPreview(
|
||||
private fun DatePillWidgetPreview(
|
||||
fontSize: Float,
|
||||
iconSize: Float,
|
||||
showDaily: Boolean
|
||||
showDaily: Boolean,
|
||||
date: String
|
||||
) {
|
||||
val icon = if (showDaily) R.drawable.rain_with_clear else R.drawable.weather_mostly_clear_day
|
||||
val condition = if (showDaily) "Rain with clear" else "Mostly clear"
|
||||
@@ -304,6 +343,7 @@ private fun DatePillWidgetPreview(
|
||||
val textSize = 16 * fontSize
|
||||
val temp = if (showDaily) "28°" else "24°"
|
||||
|
||||
|
||||
Row(Modifier.height(120.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Surface(
|
||||
Modifier.height(90.dp),
|
||||
@@ -318,7 +358,7 @@ private fun DatePillWidgetPreview(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
"Wed, July 8",
|
||||
date,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = textSize.sp,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
@@ -349,7 +389,8 @@ private fun DatePillWidgetPreview(
|
||||
private fun ClockDateWidgetPreview(
|
||||
textColor: Color, fontSize: Float,
|
||||
iconSize: Float,
|
||||
showDaily: Boolean
|
||||
showDaily: Boolean,
|
||||
date: String
|
||||
) {
|
||||
|
||||
val icon = if (showDaily) R.drawable.rain_with_clear else R.drawable.weather_mostly_clear_day
|
||||
@@ -378,7 +419,7 @@ private fun ClockDateWidgetPreview(
|
||||
)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
"Monday, April 19 • ",
|
||||
"$date • ",
|
||||
fontSize = textSize.sp,
|
||||
color = textColor,
|
||||
fontWeight = FontWeight.Medium
|
||||
@@ -394,7 +435,8 @@ private fun ClockDateWidgetPreview(
|
||||
private fun ClockVerticalWidgetPreview(
|
||||
textColor: Color, fontSize: Float,
|
||||
iconSize: Float,
|
||||
showDaily: Boolean
|
||||
showDaily: Boolean,
|
||||
date: String
|
||||
) {
|
||||
|
||||
val iconSize = 20 * iconSize
|
||||
@@ -442,7 +484,7 @@ private fun ClockVerticalWidgetPreview(
|
||||
)
|
||||
|
||||
Text(
|
||||
"Monday, April 19",
|
||||
date,
|
||||
fontSize = textSize.sp,
|
||||
color = textColor,
|
||||
fontWeight = FontWeight.Medium
|
||||
@@ -471,7 +513,8 @@ private fun ClockVerticalWidgetPreview(
|
||||
private fun ClockHorizontalWidgetPreview(
|
||||
textColor: Color, fontSize: Float,
|
||||
iconSize: Float,
|
||||
showDaily: Boolean
|
||||
showDaily: Boolean,
|
||||
date: String
|
||||
) {
|
||||
|
||||
val iconSize = 24 * iconSize
|
||||
@@ -512,7 +555,7 @@ private fun ClockHorizontalWidgetPreview(
|
||||
)
|
||||
}
|
||||
Text(
|
||||
"Monday, April 19",
|
||||
date,
|
||||
fontSize = textSize.sp,
|
||||
color = textColor,
|
||||
fontWeight = FontWeight.Medium
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ fun Weather4ClockDate(
|
||||
modifier = GlanceModifier.wrapContentSize()
|
||||
) {
|
||||
WidgetDate(
|
||||
"EEE, MMM d",
|
||||
config.dateFormat,
|
||||
color = textColor.second,
|
||||
context = context,
|
||||
size = textSize,
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ fun Weather4ClockHorizontal(
|
||||
modifier = GlanceModifier.wrapContentSize()
|
||||
) {
|
||||
WidgetDate(
|
||||
"EEEE, MMM d",
|
||||
config.dateFormat,
|
||||
color = textColor.second,
|
||||
context = context,
|
||||
size = textSize,
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ fun Weather4ClockVerticalDate(
|
||||
modifier = GlanceModifier.wrapContentSize()
|
||||
) {
|
||||
WidgetDate(
|
||||
"EEEE, MMM d",
|
||||
config.dateFormat,
|
||||
color = textColor.second,
|
||||
context = context,
|
||||
size = textSize,
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ fun Weather4Date(
|
||||
modifier = GlanceModifier.wrapContentSize()
|
||||
) {
|
||||
WidgetDate(
|
||||
"EEEE, MMMM d",
|
||||
config.dateFormat,
|
||||
color = textColor.second,
|
||||
context = context,
|
||||
size = textSize,
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ fun Weather4DatePill(
|
||||
modifier = GlanceModifier.wrapContentSize()
|
||||
) {
|
||||
WidgetDate(
|
||||
"EEE, MMM d",
|
||||
config.dateFormat,
|
||||
color = textColor.second,
|
||||
context = context,
|
||||
size = textSize,
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ fun ClockDailyWidgetConfig(onDone: (WidgetConfig) -> Unit = {}) {
|
||||
tiles = listOf(
|
||||
SettingTile.DialogOptionTile(
|
||||
leading = { SettingsTileIcon(R.drawable.date_range_24px) },
|
||||
title = "Date format",
|
||||
title = stringResource(R.string.settings_date_format),
|
||||
options = formatsOptions,
|
||||
selectedOption = dateFormat,
|
||||
onOptionSelected = {
|
||||
|
||||
Reference in new issue
Block a user