Correct weather info for weatherbit.io, weather.gov and yr.no.
This commit is contained in:
parent
d3b623cf13
commit
ef2e89b6ff
@ -322,78 +322,78 @@ object WeatherHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getWeatherGovIcon(iconString: String, isDaytime: Boolean): String = when {
|
fun getWeatherGovIcon(iconString: String, isDaytime: Boolean): String = when (iconString.substringBefore('?').substringAfterLast('/')) {
|
||||||
iconString.contains("skc") -> "01"
|
"skc" -> "01"
|
||||||
iconString.contains("few") -> "02"
|
"few" -> "02"
|
||||||
iconString.contains("sct") -> "03"
|
"sct" -> "03"
|
||||||
iconString.contains("bkn") -> "04"
|
"bkn" -> "04"
|
||||||
iconString.contains("ovc") -> "04"
|
"ovc" -> "04"
|
||||||
iconString.contains("wind_skc") -> "01"
|
"wind_skc" -> "01"
|
||||||
iconString.contains("wind_few") -> "02"
|
"wind_few" -> "02"
|
||||||
iconString.contains("wind_sct") -> "03"
|
"wind_sct" -> "03"
|
||||||
iconString.contains("wind_bkn") -> "04"
|
"wind_bkn" -> "04"
|
||||||
iconString.contains("wind_ovc") -> "04"
|
"wind_ovc" -> "04"
|
||||||
iconString.contains("snow") -> "13"
|
"snow" -> "13"
|
||||||
iconString.contains("rain_snow") -> "81"
|
"rain_snow" -> "81"
|
||||||
iconString.contains("rain_sleet") -> "81"
|
"rain_sleet" -> "81"
|
||||||
iconString.contains("snow_sleet") -> "81"
|
"snow_sleet" -> "81"
|
||||||
iconString.contains("fzra") -> "81"
|
"fzra" -> "81"
|
||||||
iconString.contains("rain_fzra") -> "81"
|
"rain_fzra" -> "81"
|
||||||
iconString.contains("snow_fzra") -> "81"
|
"snow_fzra" -> "81"
|
||||||
iconString.contains("sleet") -> "81"
|
"sleet" -> "81"
|
||||||
iconString.contains("rain") -> "10"
|
"rain" -> "10"
|
||||||
iconString.contains("rain_showers") -> "10"
|
"rain_showers" -> "10"
|
||||||
iconString.contains("rain_showers_hi") -> "10"
|
"rain_showers_hi" -> "10"
|
||||||
iconString.contains("tsra") -> "82"
|
"tsra" -> "82"
|
||||||
iconString.contains("tsra_sct") -> "82"
|
"tsra_sct" -> "82"
|
||||||
iconString.contains("tsra_hi") -> "82"
|
"tsra_hi" -> "82"
|
||||||
iconString.contains("tornado") -> "80"
|
"tornado" -> "80"
|
||||||
iconString.contains("hurricane") -> "80"
|
"hurricane" -> "80"
|
||||||
iconString.contains("tropical_storm") -> "09"
|
"tropical_storm" -> "09"
|
||||||
iconString.contains("dust") -> "Dust"
|
"dust" -> "Dust"
|
||||||
iconString.contains("smoke") -> "Smoke"
|
"smoke" -> "Smoke"
|
||||||
iconString.contains("haze") -> "50"
|
"haze" -> "50"
|
||||||
iconString.contains("hot") -> "01"
|
"hot" -> "01"
|
||||||
iconString.contains("cold") -> "13"
|
"cold" -> "13"
|
||||||
iconString.contains("blizzard") -> "80"
|
"blizzard" -> "80"
|
||||||
iconString.contains("fog") -> "82"
|
"fog" -> "82"
|
||||||
else -> ""
|
else -> ""
|
||||||
} + if (isDaytime) "d" else "n"
|
} + if (isDaytime) "d" else "n"
|
||||||
|
|
||||||
fun getWeatherBitIcon(iconString: String): String = when {
|
fun getWeatherBitIcon(iconString: String): String = when (iconString.substring(0, 3)) {
|
||||||
iconString.contains("t01") -> "11"
|
"t01" -> "11"
|
||||||
iconString.contains("t02") -> "09"
|
"t02" -> "09"
|
||||||
iconString.contains("t03") -> "09"
|
"t03" -> "09"
|
||||||
iconString.contains("t04") -> "09"
|
"t04" -> "09"
|
||||||
iconString.contains("t05") -> "09"
|
"t05" -> "09"
|
||||||
iconString.contains("d01") -> "10"
|
"d01" -> "10"
|
||||||
iconString.contains("d02") -> "10"
|
"d02" -> "10"
|
||||||
iconString.contains("d03") -> "10"
|
"d03" -> "10"
|
||||||
iconString.contains("r01") -> "10"
|
"r01" -> "10"
|
||||||
iconString.contains("r02") -> "10"
|
"r02" -> "10"
|
||||||
iconString.contains("r03") -> "10"
|
"r03" -> "10"
|
||||||
iconString.contains("f01") -> "10"
|
"f01" -> "10"
|
||||||
iconString.contains("r04") -> "10"
|
"r04" -> "10"
|
||||||
iconString.contains("r05") -> "10"
|
"r05" -> "10"
|
||||||
iconString.contains("r06") -> "10"
|
"r06" -> "10"
|
||||||
iconString.contains("s01") -> "13"
|
"s01" -> "13"
|
||||||
iconString.contains("s02") -> "13"
|
"s02" -> "13"
|
||||||
iconString.contains("s03") -> "13"
|
"s03" -> "13"
|
||||||
iconString.contains("s04") -> "81"
|
"s04" -> "81"
|
||||||
iconString.contains("s05") -> "90"
|
"s05" -> "90"
|
||||||
iconString.contains("s06") -> "13"
|
"s06" -> "13"
|
||||||
iconString.contains("a01") -> "82"
|
"a01" -> "82"
|
||||||
iconString.contains("a02") -> "82"
|
"a02" -> "82"
|
||||||
iconString.contains("a03") -> "82"
|
"a03" -> "82"
|
||||||
iconString.contains("a04") -> "82"
|
"a04" -> "82"
|
||||||
iconString.contains("a05") -> "82"
|
"a05" -> "82"
|
||||||
iconString.contains("a06") -> "82"
|
"a06" -> "82"
|
||||||
iconString.contains("c01") -> "01"
|
"c01" -> "01"
|
||||||
iconString.contains("c02") -> "02"
|
"c02" -> "02"
|
||||||
iconString.contains("c03") -> "04"
|
"c03" -> "04"
|
||||||
iconString.contains("c04") -> "04"
|
"c04" -> "04"
|
||||||
else -> ""
|
else -> ""
|
||||||
} + if (iconString.contains("d")) "d" else "n"
|
} + iconString.substring(3)
|
||||||
|
|
||||||
fun getWeatherApiIcon(icon: Int, isDaytime: Boolean): String = when(icon) {
|
fun getWeatherApiIcon(icon: Int, isDaytime: Boolean): String = when(icon) {
|
||||||
1000 -> "01"
|
1000 -> "01"
|
||||||
@ -447,49 +447,49 @@ object WeatherHelper {
|
|||||||
else -> ""
|
else -> ""
|
||||||
} + if (isDaytime) "d" else "n"
|
} + if (isDaytime) "d" else "n"
|
||||||
|
|
||||||
fun getYRIcon(iconCode: String, isDaytime: Boolean): String = when {
|
fun getYRIcon(iconCode: String): String = when (iconCode.substringBefore('_')) {
|
||||||
iconCode.contains("clearsky") -> "01"
|
"clearsky" -> "01"
|
||||||
iconCode.contains("cloudy") -> "04"
|
"cloudy" -> "04"
|
||||||
iconCode.contains("fair") -> "02"
|
"fair" -> "02"
|
||||||
iconCode.contains("fog") -> "82"
|
"fog" -> "82"
|
||||||
iconCode.contains("heavyrain") -> "10"
|
"heavyrain" -> "10"
|
||||||
iconCode.contains("heavyrainandthunder") -> "11"
|
"heavyrainandthunder" -> "11"
|
||||||
iconCode.contains("heavyrainshowers") -> "10"
|
"heavyrainshowers" -> "10"
|
||||||
iconCode.contains("heavyrainshowersandthunder") -> "11"
|
"heavyrainshowersandthunder" -> "11"
|
||||||
iconCode.contains("heavysleet") -> "10"
|
"heavysleet" -> "10"
|
||||||
iconCode.contains("heavysleetandthunder") -> "11"
|
"heavysleetandthunder" -> "11"
|
||||||
iconCode.contains("heavysleetshowers") -> "10"
|
"heavysleetshowers" -> "10"
|
||||||
iconCode.contains("heavysleetshowersandthunder") -> "11"
|
"heavysleetshowersandthunder" -> "11"
|
||||||
iconCode.contains("heavysnow") -> "13"
|
"heavysnow" -> "13"
|
||||||
iconCode.contains("heavysnowandthunder") -> "13"
|
"heavysnowandthunder" -> "13"
|
||||||
iconCode.contains("heavysnowshowers") -> "13"
|
"heavysnowshowers" -> "13"
|
||||||
iconCode.contains("heavysnowshowersandthunder") -> "13"
|
"heavysnowshowersandthunder" -> "13"
|
||||||
iconCode.contains("lightrain") -> "10"
|
"lightrain" -> "10"
|
||||||
iconCode.contains("lightrainandthunder") -> "11"
|
"lightrainandthunder" -> "11"
|
||||||
iconCode.contains("lightrainshowers") -> "10"
|
"lightrainshowers" -> "10"
|
||||||
iconCode.contains("lightrainshowersandthunder") -> "11"
|
"lightrainshowersandthunder" -> "11"
|
||||||
iconCode.contains("lightsleet") -> "10"
|
"lightsleet" -> "10"
|
||||||
iconCode.contains("lightsleetandthunder") -> "11"
|
"lightsleetandthunder" -> "11"
|
||||||
iconCode.contains("lightsleetshowers") -> "10"
|
"lightsleetshowers" -> "10"
|
||||||
iconCode.contains("lightsnow") -> "13"
|
"lightsnow" -> "13"
|
||||||
iconCode.contains("lightsnowandthunder") -> "13"
|
"lightsnowandthunder" -> "13"
|
||||||
iconCode.contains("lightsnowshowers") -> "13"
|
"lightsnowshowers" -> "13"
|
||||||
iconCode.contains("lightssleetshowersandthunder") -> "81"
|
"lightssleetshowersandthunder" -> "81"
|
||||||
iconCode.contains("lightssnowshowersandthunder") -> "81"
|
"lightssnowshowersandthunder" -> "81"
|
||||||
iconCode.contains("partlycloudy") -> "03"
|
"partlycloudy" -> "03"
|
||||||
iconCode.contains("rain") -> "10"
|
"rain" -> "10"
|
||||||
iconCode.contains("rainandthunder") -> "11"
|
"rainandthunder" -> "11"
|
||||||
iconCode.contains("rainshowers") -> "10"
|
"rainshowers" -> "10"
|
||||||
iconCode.contains("rainshowersandthunder") -> "11"
|
"rainshowersandthunder" -> "11"
|
||||||
iconCode.contains("sleet") -> "10"
|
"sleet" -> "10"
|
||||||
iconCode.contains("sleetandthunder") -> "11"
|
"sleetandthunder" -> "11"
|
||||||
iconCode.contains("sleetshowers") -> "10"
|
"sleetshowers" -> "10"
|
||||||
iconCode.contains("sleetshowersandthunder") -> "11"
|
"sleetshowersandthunder" -> "11"
|
||||||
iconCode.contains("snow") -> "13"
|
"snow" -> "13"
|
||||||
iconCode.contains("snowandthunder") -> "13"
|
"snowandthunder" -> "13"
|
||||||
iconCode.contains("snowshowers") -> "13"
|
"snowshowers" -> "13"
|
||||||
iconCode.contains("snowshowersandthunder") -> "13"
|
"snowshowersandthunder" -> "13"
|
||||||
else -> ""
|
else -> ""
|
||||||
} + if (isDaytime) "d" else "n"
|
} + if (iconCode.substringAfter('_', "day") == "day") "d" else "n"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -395,7 +395,7 @@ class WeatherNetworkApi(val context: Context) {
|
|||||||
val pp = response.body["properties"] as LinkedTreeMap<*, *>
|
val pp = response.body["properties"] as LinkedTreeMap<*, *>
|
||||||
val data = pp["timeseries"] as List<LinkedTreeMap<String, Any>>?
|
val data = pp["timeseries"] as List<LinkedTreeMap<String, Any>>?
|
||||||
data?.let {
|
data?.let {
|
||||||
val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").apply { timeZone = TimeZone.getTimeZone("UTC") }
|
||||||
for (item in data) {
|
for (item in data) {
|
||||||
val time = Calendar.getInstance().apply { time = format.parse(item["time"] as String)!! }
|
val time = Calendar.getInstance().apply { time = format.parse(item["time"] as String)!! }
|
||||||
val now = Calendar.getInstance()
|
val now = Calendar.getInstance()
|
||||||
@ -411,7 +411,7 @@ class WeatherNetworkApi(val context: Context) {
|
|||||||
val iconCode = summary["symbol_code"] as String
|
val iconCode = summary["symbol_code"] as String
|
||||||
|
|
||||||
Preferences.weatherTemp = temp.toFloat()
|
Preferences.weatherTemp = temp.toFloat()
|
||||||
Preferences.weatherIcon = WeatherHelper.getYRIcon(iconCode, now.get(Calendar.HOUR_OF_DAY) >= 22 || now.get(Calendar.HOUR_OF_DAY) <= 8)
|
Preferences.weatherIcon = WeatherHelper.getYRIcon(iconCode)
|
||||||
Preferences.weatherTempUnit = "C"
|
Preferences.weatherTempUnit = "C"
|
||||||
Preferences.weatherRealTempUnit = Preferences.weatherTempUnit
|
Preferences.weatherRealTempUnit = Preferences.weatherTempUnit
|
||||||
MainWidget.updateWidget(context)
|
MainWidget.updateWidget(context)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user