Fix: Fixed weather icons to show correctly.

Signed-off-by: HeCodes2Much <wayne6324@gmail.com>
This commit is contained in:
HeCodes2Much
2024-07-13 13:56:15 +01:00
parent 48313fb3b0
commit d60a935338
3 changed files with 103 additions and 23 deletions

View File

@@ -231,7 +231,7 @@ class WidgetFragment : Fragment(),
paint.typeface = weatherFont paint.typeface = weatherFont
paint.style = Paint.Style.FILL paint.style = Paint.Style.FILL
paint.color = ContextCompat.getColor(context, R.color.white) paint.color = ContextCompat.getColor(context, R.color.white)
paint.textSize = 200f paint.textSize = 170f
paint.textAlign = Paint.Align.CENTER paint.textAlign = Paint.Align.CENTER
canvas.drawText(text, 128f, 200f, paint) canvas.drawText(text, 128f, 200f, paint)
return bitmap return bitmap
@@ -257,26 +257,41 @@ class WidgetFragment : Fragment(),
val icon: String val icon: String
val idDivided = id / 100 val idDivided = id / 100
val hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY) val hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY)
if (idDivided * 100 == 800) { val isDayTime = hourOfDay in 7..19
icon = if (hourOfDay in 7..19) {
context.getString(R.string.weather_sunny) icon = when {
} else { id == 800 -> if (isDayTime) context.getString(R.string.wi_day_sunny) else context.getString(R.string.wi_night_clear)
context.getString(R.string.weather_clear_night) idDivided == 2 -> if (isDayTime) context.getString(R.string.wi_day_thunderstorm) else context.getString(R.string.wi_night_alt_thunderstorm)
idDivided == 3 -> if (isDayTime) context.getString(R.string.wi_day_sprinkle) else context.getString(R.string.wi_night_alt_sprinkle)
idDivided == 5 -> when (id) {
500 -> if (isDayTime) context.getString(R.string.wi_day_showers) else context.getString(R.string.wi_night_showers)
501 -> if (isDayTime) context.getString(R.string.wi_day_rain) else context.getString(R.string.wi_night_rain)
502 -> if (isDayTime) context.getString(R.string.wi_day_rain_wind) else context.getString(R.string.wi_night_rain_wind)
503 -> if (isDayTime) context.getString(R.string.wi_day_rain_mix) else context.getString(R.string.wi_night_rain_mix)
504 -> if (isDayTime) context.getString(R.string.wi_day_rain) else context.getString(R.string.wi_night_rain)
511 -> if (isDayTime) context.getString(R.string.wi_day_sleet) else context.getString(R.string.wi_night_sleet)
520 -> if (isDayTime) context.getString(R.string.wi_day_showers) else context.getString(R.string.wi_night_showers)
521 -> if (isDayTime) context.getString(R.string.wi_day_showers) else context.getString(R.string.wi_night_showers)
522 -> if (isDayTime) context.getString(R.string.wi_day_storm_showers) else context.getString(R.string.wi_night_storm_showers)
else -> if (isDayTime) context.getString(R.string.wi_day_rain) else context.getString(R.string.wi_night_rain)
} }
} else {
icon = when (idDivided) { idDivided == 6 -> if (isDayTime) context.getString(R.string.wi_day_snow) else context.getString(R.string.wi_night_alt_snow)
2 -> context.getString(R.string.weather_thunder) idDivided == 7 -> if (isDayTime) context.getString(R.string.wi_day_fog) else context.getString(R.string.wi_night_fog)
3 -> context.getString(R.string.weather_drizzle) idDivided == 8 -> when (id) {
7 -> context.getString(R.string.weather_foggy) 801 -> if (isDayTime) context.getString(R.string.wi_day_cloudy) else context.getString(R.string.wi_night_cloudy)
8 -> context.getString(R.string.weather_cloudy) 802 -> if (isDayTime) context.getString(R.string.wi_day_cloudy_gusts) else context.getString(R.string.wi_night_alt_cloudy_gusts)
6 -> context.getString(R.string.weather_snowy) 803 -> if (isDayTime) context.getString(R.string.wi_day_cloudy_windy) else context.getString(R.string.wi_night_alt_cloudy_windy)
5 -> context.getString(R.string.weather_rainy) 804 -> if (isDayTime) context.getString(R.string.wi_day_cloudy) else context.getString(R.string.wi_night_cloudy)
else -> "" else -> if (isDayTime) context.getString(R.string.wi_day_cloudy) else context.getString(R.string.wi_night_cloudy)
} }
else -> context.getString(R.string.wi_na)
} }
return icon return icon
} }
private fun convertTimestampToReadableDate(timestamp: Long): String { private fun convertTimestampToReadableDate(timestamp: Long): String {
// Multiply by 1000 to convert seconds to milliseconds if the timestamp is in seconds // Multiply by 1000 to convert seconds to milliseconds if the timestamp is in seconds
val date = Date(timestamp * 1000) val date = Date(timestamp * 1000)

0
app/src/main/res/font/weather.ttf Normal file → Executable file
View File

View File

@@ -8,12 +8,77 @@
<string name="sunrise_icon" translatable="false">&#xf051;</string> <string name="sunrise_icon" translatable="false">&#xf051;</string>
<string name="sunset_icon" translatable="false">&#xf052;</string> <string name="sunset_icon" translatable="false">&#xf052;</string>
<string name="weather_sunny" translatable="false">&#xf00d;</string> <!-- Daytime Icons -->
<string name="weather_clear_night" translatable="false">&#xf02e;</string> <string name="wi_day_sunny" translatable="false">&#xf00d;</string>
<string name="weather_foggy" translatable="false">&#xf014;</string> <string name="wi_day_cloudy" translatable="false">&#xf002;</string>
<string name="weather_cloudy" translatable="false">&#xf013;</string> <string name="wi_day_cloudy_gusts" translatable="false">&#xf000;</string>
<string name="weather_rainy" translatable="false">&#xf019;</string> <string name="wi_day_cloudy_windy" translatable="false">&#xf001;</string>
<string name="weather_snowy" translatable="false">&#xf01b;</string> <string name="wi_day_fog" translatable="false">&#xf003;</string>
<string name="weather_thunder" translatable="false">&#xf01e;</string> <string name="wi_day_hail" translatable="false">&#xf004;</string>
<string name="weather_drizzle" translatable="false">&#xf01a;</string> <string name="wi_day_haze" translatable="false">&#xf0b6;</string>
<string name="wi_day_lightning" translatable="false">&#xf005;</string>
<string name="wi_day_rain" translatable="false">&#xf008;</string>
<string name="wi_day_rain_mix" translatable="false">&#xf006;</string>
<string name="wi_day_rain_wind" translatable="false">&#xf007;</string>
<string name="wi_day_showers" translatable="false">&#xf009;</string>
<string name="wi_day_sleet" translatable="false">&#xf0b2;</string>
<string name="wi_day_sleet_storm" translatable="false">&#xf068;</string>
<string name="wi_day_snow" translatable="false">&#xf00a;</string>
<string name="wi_day_snow_thunderstorm" translatable="false">&#xf06b;</string>
<string name="wi_day_snow_wind" translatable="false">&#xf065;</string>
<string name="wi_day_sprinkle" translatable="false">&#xf00b;</string>
<string name="wi_day_storm_showers" translatable="false">&#xf00e;</string>
<string name="wi_day_sunny_overcast" translatable="false">&#xf00c;</string>
<string name="wi_day_thunderstorm" translatable="false">&#xf010;</string>
<string name="wi_day_windy" translatable="false">&#xf085;</string>
<string name="wi_solar_eclipse" translatable="false">&#xf06e;</string>
<string name="wi_hot" translatable="false">&#xf072;</string>
<string name="wi_day_cloudy_high" translatable="false">&#xf07d;</string>
<string name="wi_day_light_wind" translatable="false">&#xf0c4;</string>
<!-- Nighttime Icons -->
<string name="wi_night_clear" translatable="false">&#xf02e;</string>
<string name="wi_night_alt_cloudy" translatable="false">&#xf086;</string>
<string name="wi_night_alt_cloudy_gusts" translatable="false">&#xf022;</string>
<string name="wi_night_alt_cloudy_windy" translatable="false">&#xf023;</string>
<string name="wi_night_alt_hail" translatable="false">&#xf024;</string>
<string name="wi_night_alt_lightning" translatable="false">&#xf025;</string>
<string name="wi_night_alt_rain" translatable="false">&#xf028;</string>
<string name="wi_night_alt_rain_mix" translatable="false">&#xf026;</string>
<string name="wi_night_alt_rain_wind" translatable="false">&#xf027;</string>
<string name="wi_night_alt_showers" translatable="false">&#xf029;</string>
<string name="wi_night_alt_sleet" translatable="false">&#xf0b4;</string>
<string name="wi_night_alt_sleet_storm" translatable="false">&#xf06a;</string>
<string name="wi_night_alt_snow" translatable="false">&#xf02a;</string>
<string name="wi_night_alt_snow_thunderstorm" translatable="false">&#xf06d;</string>
<string name="wi_night_alt_snow_wind" translatable="false">&#xf067;</string>
<string name="wi_night_alt_sprinkle" translatable="false">&#xf02b;</string>
<string name="wi_night_alt_storm_showers" translatable="false">&#xf02c;</string>
<string name="wi_night_alt_thunderstorm" translatable="false">&#xf02d;</string>
<string name="wi_night_cloudy" translatable="false">&#xf031;</string>
<string name="wi_night_cloudy_gusts" translatable="false">&#xf02f;</string>
<string name="wi_night_cloudy_windy" translatable="false">&#xf030;</string>
<string name="wi_night_fog" translatable="false">&#xf04a;</string>
<string name="wi_night_hail" translatable="false">&#xf032;</string>
<string name="wi_night_lightning" translatable="false">&#xf033;</string>
<string name="wi_night_partly_cloudy" translatable="false">&#xf083;</string>
<string name="wi_night_rain" translatable="false">&#xf036;</string>
<string name="wi_night_rain_mix" translatable="false">&#xf034;</string>
<string name="wi_night_rain_wind" translatable="false">&#xf035;</string>
<string name="wi_night_showers" translatable="false">&#xf037;</string>
<string name="wi_night_sleet" translatable="false">&#xf0b3;</string>
<string name="wi_night_sleet_storm" translatable="false">&#xf069;</string>
<string name="wi_night_snow" translatable="false">&#xf038;</string>
<string name="wi_night_snow_thunderstorm" translatable="false">&#xf06c;</string>
<string name="wi_night_snow_wind" translatable="false">&#xf066;</string>
<string name="wi_night_sprinkle" translatable="false">&#xf039;</string>
<string name="wi_night_storm_showers" translatable="false">&#xf03a;</string>
<string name="wi_night_thunderstorm" translatable="false">&#xf03b;</string>
<string name="wi_lunar_eclipse" translatable="false">&#xf070;</string>
<string name="wi_stars" translatable="false">&#xf077;</string>
<!-- Generic Icons -->
<string name="wi_storm_showers" translatable="false">&#xf01d;</string>
<string name="wi_thunderstorm" translatable="false">&#xf01e;</string>
<string name="wi_na" translatable="false">&#xf07b;</string>
</resources> </resources>