Merge branch 'patch-1' into patch-develop
This commit is contained in:
commit
32c580bac7
@ -342,13 +342,13 @@ object WeatherHelper {
|
||||
fun getWeatherGovIcon(iconString: String, isDaytime: Boolean): String = when (iconString.substringBefore('?').substringAfterLast('/')) {
|
||||
"skc" -> "01"
|
||||
"few" -> "02"
|
||||
"sct" -> "03"
|
||||
"bkn" -> "04"
|
||||
"sct" -> "02"
|
||||
"bkn" -> "03"
|
||||
"ovc" -> "04"
|
||||
"wind_skc" -> "01"
|
||||
"wind_few" -> "02"
|
||||
"wind_sct" -> "03"
|
||||
"wind_bkn" -> "04"
|
||||
"wind_sct" -> "02"
|
||||
"wind_bkn" -> "03"
|
||||
"wind_ovc" -> "04"
|
||||
"snow" -> "13"
|
||||
"rain_snow" -> "81"
|
||||
@ -361,28 +361,28 @@ object WeatherHelper {
|
||||
"rain" -> "10"
|
||||
"rain_showers" -> "10"
|
||||
"rain_showers_hi" -> "10"
|
||||
"tsra" -> "82"
|
||||
"tsra_sct" -> "82"
|
||||
"tsra_hi" -> "82"
|
||||
"tsra" -> "09"
|
||||
"tsra_sct" -> "11"
|
||||
"tsra_hi" -> "11"
|
||||
"tornado" -> "80"
|
||||
"hurricane" -> "80"
|
||||
"tropical_storm" -> "09"
|
||||
"dust" -> "Dust"
|
||||
"smoke" -> "Smoke"
|
||||
"dust" -> "50"
|
||||
"smoke" -> "50"
|
||||
"haze" -> "50"
|
||||
"hot" -> "01"
|
||||
"cold" -> "13"
|
||||
"blizzard" -> "80"
|
||||
"blizzard" -> "13"
|
||||
"fog" -> "82"
|
||||
else -> ""
|
||||
} + if (isDaytime) "d" else "n"
|
||||
|
||||
fun getWeatherBitIcon(iconString: String): String = when (iconString.substring(0, 3)) {
|
||||
"t01" -> "11"
|
||||
"t02" -> "09"
|
||||
"t02" -> "11"
|
||||
"t03" -> "09"
|
||||
"t04" -> "09"
|
||||
"t05" -> "09"
|
||||
"t04" -> "11"
|
||||
"t05" -> "11"
|
||||
"d01" -> "10"
|
||||
"d02" -> "10"
|
||||
"d03" -> "10"
|
||||
@ -397,17 +397,17 @@ object WeatherHelper {
|
||||
"s02" -> "13"
|
||||
"s03" -> "13"
|
||||
"s04" -> "81"
|
||||
"s05" -> "90"
|
||||
"s05" -> "81"
|
||||
"s06" -> "13"
|
||||
"a01" -> "82"
|
||||
"a02" -> "82"
|
||||
"a03" -> "82"
|
||||
"a04" -> "82"
|
||||
"a01" -> "50"
|
||||
"a02" -> "50"
|
||||
"a03" -> "50"
|
||||
"a04" -> "50"
|
||||
"a05" -> "82"
|
||||
"a06" -> "82"
|
||||
"c01" -> "01"
|
||||
"c02" -> "02"
|
||||
"c03" -> "04"
|
||||
"c03" -> "03"
|
||||
"c04" -> "04"
|
||||
else -> ""
|
||||
} + iconString.substring(3)
|
||||
@ -417,14 +417,14 @@ object WeatherHelper {
|
||||
1003 -> "02"
|
||||
1006 -> "03"
|
||||
1009 -> "04"
|
||||
1030 -> "82"
|
||||
1030 -> "50"
|
||||
1063 -> "10"
|
||||
1066 -> "10"
|
||||
1069 -> "10"
|
||||
1066 -> "13"
|
||||
1069 -> "81"
|
||||
1072 -> "81"
|
||||
1087 -> "11"
|
||||
1114 -> "13"
|
||||
1117 -> "09"
|
||||
1117 -> "13"
|
||||
1135 -> "82"
|
||||
1147 -> "82"
|
||||
1150 -> "10"
|
||||
@ -439,8 +439,8 @@ object WeatherHelper {
|
||||
1195 -> "10"
|
||||
1198 -> "81"
|
||||
1201 -> "81"
|
||||
1204 -> "13"
|
||||
1207 -> "13"
|
||||
1204 -> "81"
|
||||
1207 -> "81"
|
||||
1210 -> "13"
|
||||
1213 -> "13"
|
||||
1216 -> "13"
|
||||
@ -451,13 +451,13 @@ object WeatherHelper {
|
||||
1240 -> "10"
|
||||
1243 -> "10"
|
||||
1246 -> "10"
|
||||
1249 -> "13"
|
||||
1252 -> "13"
|
||||
1249 -> "81"
|
||||
1252 -> "81"
|
||||
1255 -> "13"
|
||||
1258 -> "13"
|
||||
1261 -> "13"
|
||||
1264 -> "13"
|
||||
1273 -> "09"
|
||||
1273 -> "11"
|
||||
1276 -> "09"
|
||||
1279 -> "13"
|
||||
1282 -> "13"
|
||||
@ -470,13 +470,13 @@ object WeatherHelper {
|
||||
"fair" -> "02"
|
||||
"fog" -> "82"
|
||||
"heavyrain" -> "10"
|
||||
"heavyrainandthunder" -> "11"
|
||||
"heavyrainandthunder" -> "09"
|
||||
"heavyrainshowers" -> "10"
|
||||
"heavyrainshowersandthunder" -> "11"
|
||||
"heavysleet" -> "10"
|
||||
"heavysleetandthunder" -> "11"
|
||||
"heavysleetshowers" -> "10"
|
||||
"heavysleetshowersandthunder" -> "11"
|
||||
"heavyrainshowersandthunder" -> "09"
|
||||
"heavysleet" -> "81"
|
||||
"heavysleetandthunder" -> "81"
|
||||
"heavysleetshowers" -> "81"
|
||||
"heavysleetshowersandthunder" -> "81"
|
||||
"heavysnow" -> "13"
|
||||
"heavysnowandthunder" -> "13"
|
||||
"heavysnowshowers" -> "13"
|
||||
@ -485,9 +485,9 @@ object WeatherHelper {
|
||||
"lightrainandthunder" -> "11"
|
||||
"lightrainshowers" -> "10"
|
||||
"lightrainshowersandthunder" -> "11"
|
||||
"lightsleet" -> "10"
|
||||
"lightsleetandthunder" -> "11"
|
||||
"lightsleetshowers" -> "10"
|
||||
"lightsleet" -> "81"
|
||||
"lightsleetandthunder" -> "81"
|
||||
"lightsleetshowers" -> "81"
|
||||
"lightsnow" -> "13"
|
||||
"lightsnowandthunder" -> "13"
|
||||
"lightsnowshowers" -> "13"
|
||||
@ -498,10 +498,10 @@ object WeatherHelper {
|
||||
"rainandthunder" -> "11"
|
||||
"rainshowers" -> "10"
|
||||
"rainshowersandthunder" -> "11"
|
||||
"sleet" -> "10"
|
||||
"sleetandthunder" -> "11"
|
||||
"sleetshowers" -> "10"
|
||||
"sleetshowersandthunder" -> "11"
|
||||
"sleet" -> "81"
|
||||
"sleetandthunder" -> "81"
|
||||
"sleetshowers" -> "81"
|
||||
"sleetshowersandthunder" -> "81"
|
||||
"snow" -> "13"
|
||||
"snowandthunder" -> "13"
|
||||
"snowshowers" -> "13"
|
||||
|
@ -26,9 +26,7 @@ class TimeZonesApi(val context: Context) {
|
||||
when (val response = repository.getTimeZone(lat, long)) {
|
||||
is NetworkResponse.Success -> {
|
||||
try {
|
||||
Log.d("ciao", response.body.toString())
|
||||
id = response.body["timezoneId"] as String
|
||||
|
||||
} catch(ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
@ -37,4 +35,4 @@ class TimeZonesApi(val context: Context) {
|
||||
|
||||
return id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,25 +121,34 @@ class WeatherNetworkApi(val context: Context) {
|
||||
val props =
|
||||
weatherResponse.body["properties"] as LinkedTreeMap<*, *>
|
||||
val periods = props["periods"] as List<*>
|
||||
val now = periods[0] as LinkedTreeMap<*, *>
|
||||
@android.annotation.SuppressLint("SimpleDateFormat")
|
||||
val format = SimpleDateFormat(
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
|
||||
"yyyy-MM-dd'T'HH:mm:ssXXX"
|
||||
else
|
||||
"yyyy-MM-dd'T'HH:mm:ssZ"
|
||||
)
|
||||
for (period in periods) {
|
||||
val now = period as LinkedTreeMap<*, *>
|
||||
val endTime = format.parse(now["endTime"] as String)!!
|
||||
if (endTime.time > System.currentTimeMillis()) {
|
||||
val temp = now["temperature"] as Double
|
||||
val fullIcon = now["icon"] as String
|
||||
val isDaytime = now["isDaytime"] as Boolean
|
||||
|
||||
val temp = now["temperature"] as Double
|
||||
val fullIcon = now["icon"] as String
|
||||
val isDaytime = now["isDaytime"] as Boolean
|
||||
Preferences.weatherTemp = temp.toFloat()
|
||||
Preferences.weatherIcon = WeatherHelper.getWeatherGovIcon(fullIcon, isDaytime)
|
||||
Preferences.weatherRealTempUnit = Preferences.weatherTempUnit
|
||||
MainWidget.updateWidget(context)
|
||||
|
||||
Preferences.weatherTemp = temp.toFloat()
|
||||
Preferences.weatherIcon = WeatherHelper.getWeatherGovIcon(fullIcon, isDaytime)
|
||||
Preferences.weatherRealTempUnit = Preferences.weatherTempUnit
|
||||
|
||||
Preferences.weatherProviderError = ""
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
|
||||
MainWidget.updateWidget(context)
|
||||
Preferences.weatherProviderError = ""
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
break
|
||||
}
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
} finally {
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@ -155,14 +164,16 @@ class WeatherNetworkApi(val context: Context) {
|
||||
}
|
||||
}
|
||||
is NetworkResponse.ServerError -> {
|
||||
if (pointsResponse.body?.containsKey("status") == true && (pointsResponse.body?.get("status") as Double).toInt() == 404) {
|
||||
Preferences.weatherProviderError = ""
|
||||
Preferences.weatherProviderLocationError = context.getString(R.string.weather_provider_error_wrong_location)
|
||||
} else {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
when (pointsResponse.code) {
|
||||
404 -> {
|
||||
Preferences.weatherProviderError = ""
|
||||
Preferences.weatherProviderLocationError = context.getString(R.string.weather_provider_error_wrong_location)
|
||||
}
|
||||
else -> {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
}
|
||||
}
|
||||
|
||||
WeatherHelper.removeWeather(
|
||||
context
|
||||
)
|
||||
@ -183,7 +194,18 @@ class WeatherNetworkApi(val context: Context) {
|
||||
when (val response = repository.getWeather()) {
|
||||
is NetworkResponse.Success -> {
|
||||
try {
|
||||
Log.d("ciao - here", response.body.toString())
|
||||
val observations = response.body["observations"] as LinkedTreeMap<*, *>
|
||||
val location = (observations["location"] as List<*>).first() as LinkedTreeMap<*, *>
|
||||
val observation = (location["observation"] as List<*>).first() as LinkedTreeMap<*, *>
|
||||
val iconName = observation["iconName"] as String
|
||||
val daylight = observation["daylight"] as String
|
||||
val temperature = observation["temperature"] as String
|
||||
|
||||
Preferences.weatherTemp = temperature.toFloat()
|
||||
Preferences.weatherIcon = repository.getWeatherIcon(iconName, daylight != "N")
|
||||
Preferences.weatherRealTempUnit = Preferences.weatherTempUnit
|
||||
MainWidget.updateWidget(context)
|
||||
|
||||
Preferences.weatherProviderError = ""
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
} catch(ex: Exception) {
|
||||
@ -194,8 +216,16 @@ class WeatherNetworkApi(val context: Context) {
|
||||
}
|
||||
}
|
||||
is NetworkResponse.ServerError -> {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
when (response.code) {
|
||||
401 -> {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_invalid_key)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
}
|
||||
else -> {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
}
|
||||
}
|
||||
WeatherHelper.removeWeather(
|
||||
context
|
||||
)
|
||||
@ -225,10 +255,10 @@ class WeatherNetworkApi(val context: Context) {
|
||||
when (val response = repository.getWeather()) {
|
||||
is NetworkResponse.Success -> {
|
||||
try {
|
||||
val data = response.body["data"] as List<LinkedTreeMap<String, Any>>?
|
||||
data?.first()?.let {
|
||||
val data = response.body["data"] as List<*>?
|
||||
data?.first()?.let { it as LinkedTreeMap<*, *>
|
||||
val temp = it["temp"] as Double
|
||||
val weatherInfo = it["weather"] as LinkedTreeMap<String, Any>
|
||||
val weatherInfo = it["weather"] as LinkedTreeMap<*, *>
|
||||
val iconCode = weatherInfo["icon"] as String
|
||||
|
||||
Preferences.weatherTemp = temp.toFloat()
|
||||
@ -238,8 +268,6 @@ class WeatherNetworkApi(val context: Context) {
|
||||
|
||||
Preferences.weatherProviderError = ""
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
}
|
||||
} catch(ex: Exception) {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
@ -288,12 +316,12 @@ class WeatherNetworkApi(val context: Context) {
|
||||
when (val response = repository.getWeather()) {
|
||||
is NetworkResponse.Success -> {
|
||||
try {
|
||||
val current = response.body["current"] as LinkedTreeMap<String, Any>?
|
||||
val current = response.body["current"] as LinkedTreeMap<*, *>?
|
||||
current?.let {
|
||||
val tempC = current["temp_c"] as Double
|
||||
val tempF = current["temp_f"] as Double
|
||||
val isDay = current["is_day"] as Double
|
||||
val condition = current["condition"] as LinkedTreeMap<String, Any>
|
||||
val condition = current["condition"] as LinkedTreeMap<*, *>
|
||||
val iconCode = condition["code"] as Double
|
||||
|
||||
Preferences.weatherTemp = if (Preferences.weatherTempUnit == "F") tempF.toFloat() else tempC.toFloat()
|
||||
@ -303,8 +331,6 @@ class WeatherNetworkApi(val context: Context) {
|
||||
|
||||
Preferences.weatherProviderError = ""
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
}
|
||||
} catch(ex: Exception) {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
@ -353,28 +379,74 @@ class WeatherNetworkApi(val context: Context) {
|
||||
|
||||
private suspend fun useAccuweatherProvider(context: Context) {
|
||||
if (Preferences.weatherProviderApiAccuweather != "") {
|
||||
// val repository = AccuweatherRepository()
|
||||
val repository = AccuweatherRepository()
|
||||
|
||||
// when (val response = repository.getWeather()) {
|
||||
// is NetworkResponse.Success -> {
|
||||
// try {
|
||||
// Log.d("ciao", response.body.toString())
|
||||
// } catch(ex: Exception) {
|
||||
//
|
||||
// Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_missing_key)
|
||||
// Preferences.weatherProviderLocationError = ""
|
||||
// }
|
||||
// }
|
||||
// is NetworkResponse.ServerError -> {
|
||||
// WeatherHelper.removeWeather(
|
||||
// context
|
||||
// )
|
||||
// }
|
||||
// Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_missing_key)
|
||||
// Preferences.weatherProviderLocationError = ""
|
||||
// EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
// }
|
||||
when (val locationResponse = repository.getLocation()) {
|
||||
is NetworkResponse.Success -> {
|
||||
try {
|
||||
val key = locationResponse.body["Key"] as String
|
||||
|
||||
when (val weatherResponse = repository.getWeather(key)) {
|
||||
is NetworkResponse.Success -> {
|
||||
try {
|
||||
weatherResponse.body.first().let {
|
||||
val temp = it["Temperature"] as LinkedTreeMap<*, *>
|
||||
val tempC = (temp["Metric"] as LinkedTreeMap<*, *>)["Value"] as Double
|
||||
val tempF = (temp["Imperial"] as LinkedTreeMap<*, *>)["Value"] as Double
|
||||
val isDay = it["IsDayTime"] as Boolean
|
||||
val icon = it["WeatherIcon"] as Double
|
||||
|
||||
Preferences.weatherTemp = if (Preferences.weatherTempUnit == "F") tempF.toFloat() else tempC.toFloat()
|
||||
Preferences.weatherIcon = repository.getWeatherIcon(icon.toInt(), isDay)
|
||||
Preferences.weatherRealTempUnit = Preferences.weatherTempUnit
|
||||
MainWidget.updateWidget(context)
|
||||
}
|
||||
|
||||
Preferences.weatherProviderError = ""
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
} catch (ex: Exception) {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_connection)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
}
|
||||
}
|
||||
} catch(ex: Exception) {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
} finally {
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
}
|
||||
}
|
||||
is NetworkResponse.ServerError -> {
|
||||
when (locationResponse.code) {
|
||||
401 -> {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_invalid_key)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
}
|
||||
503 -> {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_expired_key)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
}
|
||||
else -> {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
}
|
||||
}
|
||||
WeatherHelper.removeWeather(
|
||||
context
|
||||
)
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
}
|
||||
else -> {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_connection)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_missing_key)
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
@ -393,38 +465,27 @@ class WeatherNetworkApi(val context: Context) {
|
||||
is NetworkResponse.Success -> {
|
||||
try {
|
||||
val pp = response.body["properties"] as LinkedTreeMap<*, *>
|
||||
val data = pp["timeseries"] as List<LinkedTreeMap<String, Any>>?
|
||||
data?.let {
|
||||
val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").apply { timeZone = TimeZone.getTimeZone("UTC") }
|
||||
for (item in data) {
|
||||
val time = Calendar.getInstance().apply { time = format.parse(item["time"] as String)!! }
|
||||
val now = Calendar.getInstance()
|
||||
if (time.timeInMillis >= now.timeInMillis) {
|
||||
val dd = item["data"] as LinkedTreeMap<*, *>
|
||||
val instant = dd["instant"] as LinkedTreeMap<*, *>
|
||||
val next = dd["next_1_hours"] as LinkedTreeMap<*, *>
|
||||
val data = pp["timeseries"] as List<*>?
|
||||
data?.first()?.let { it as LinkedTreeMap<*, *>
|
||||
val dd = it["data"] as LinkedTreeMap<*, *>
|
||||
val instant = dd["instant"] as LinkedTreeMap<*, *>
|
||||
val next = dd["next_1_hours"] as LinkedTreeMap<*, *>
|
||||
|
||||
val details = instant["details"] as LinkedTreeMap<*, *>
|
||||
val temp = details["air_temperature"] as Double
|
||||
val details = instant["details"] as LinkedTreeMap<*, *>
|
||||
val temp = details["air_temperature"] as Double
|
||||
|
||||
val summary = next["summary"] as LinkedTreeMap<*, *>
|
||||
val iconCode = summary["symbol_code"] as String
|
||||
val summary = next["summary"] as LinkedTreeMap<*, *>
|
||||
val iconCode = summary["symbol_code"] as String
|
||||
|
||||
Preferences.weatherTemp = temp.toFloat()
|
||||
Preferences.weatherIcon = WeatherHelper.getYRIcon(iconCode)
|
||||
Preferences.weatherTempUnit = "C"
|
||||
Preferences.weatherRealTempUnit = Preferences.weatherTempUnit
|
||||
MainWidget.updateWidget(context)
|
||||
Preferences.weatherTemp = temp.toFloat()
|
||||
Preferences.weatherIcon = WeatherHelper.getYRIcon(iconCode)
|
||||
Preferences.weatherTempUnit = "C"
|
||||
Preferences.weatherRealTempUnit = Preferences.weatherTempUnit
|
||||
MainWidget.updateWidget(context)
|
||||
|
||||
Preferences.weatherProviderError = ""
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
break
|
||||
}
|
||||
}
|
||||
Preferences.weatherProviderError = ""
|
||||
Preferences.weatherProviderLocationError = ""
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch(ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
|
||||
@ -448,4 +509,4 @@ class WeatherNetworkApi(val context: Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ object ApiServices {
|
||||
): NetworkResponse<HashMap<String, Any>, HashMap<String, Any>>
|
||||
|
||||
@Headers("User-Agent: (Another Widget, tommaso.berlose@gmail.com)")
|
||||
@GET("gridpoints/{gridId}/{gridX},{gridY}/forecast")
|
||||
@GET("gridpoints/{gridId}/{gridX},{gridY}/forecast/hourly")
|
||||
suspend fun getWeather(
|
||||
@Path("gridId") gridId: String,
|
||||
@Path("gridX") gridX: Int,
|
||||
@ -54,13 +54,17 @@ object ApiServices {
|
||||
}
|
||||
|
||||
interface AccuweatherService {
|
||||
@GET("")
|
||||
suspend fun getWeather(
|
||||
@Path("gridId") gridId: String,
|
||||
@Path("gridX") gridX: Int,
|
||||
@Path("gridY") gridY: Int,
|
||||
@Query("units") unit: String
|
||||
@GET("locations/v1/cities/geoposition/search")
|
||||
suspend fun getLocation(
|
||||
@Query("apikey") apikey: String,
|
||||
@Query("q") location: String
|
||||
): NetworkResponse<HashMap<String, Any>, HashMap<String, Any>>
|
||||
|
||||
@GET("currentconditions/v1/{locationKey}")
|
||||
suspend fun getWeather(
|
||||
@Path("locationKey") locationKey: String,
|
||||
@Query("apikey") apikey: String
|
||||
): NetworkResponse<List<HashMap<String, Any>>, HashMap<String, Any>>
|
||||
}
|
||||
|
||||
interface YrService {
|
||||
@ -80,4 +84,4 @@ object ApiServices {
|
||||
@Query("username") username: String = "tommaso.berlose",
|
||||
): NetworkResponse<HashMap<String, Any>, HashMap<String, Any>>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.tommasoberlose.anotherwidget.network.repository
|
||||
|
||||
import com.haroldadmin.cnradapter.NetworkResponseAdapterFactory
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.network.api.ApiServices
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
@ -9,10 +10,11 @@ class AccuweatherRepository {
|
||||
|
||||
/* ACCUWEATHER */
|
||||
private val apiServiceAccu: ApiServices.AccuweatherService = getRetrofit().create(ApiServices.AccuweatherService::class.java)
|
||||
suspend fun getWeather(): Nothing = TODO()
|
||||
suspend fun getLocation() = apiServiceAccu.getLocation(Preferences.weatherProviderApiAccuweather, "${Preferences.customLocationLat},${Preferences.customLocationLon}")
|
||||
suspend fun getWeather(locationKey: String) = apiServiceAccu.getWeather(locationKey, Preferences.weatherProviderApiAccuweather)
|
||||
|
||||
companion object {
|
||||
private const val BASE_URL_ACCU = ""
|
||||
private const val BASE_URL_ACCU = "https://dataservice.accuweather.com/"
|
||||
|
||||
private fun getRetrofit(): Retrofit {
|
||||
return Retrofit.Builder()
|
||||
@ -22,4 +24,20 @@ class AccuweatherRepository {
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getWeatherIcon(icon: Int, isDaytime: Boolean): String = when(icon) {
|
||||
1, 2, 30, 33, 34 -> "01"
|
||||
3, 4, 35, 36 -> "02"
|
||||
5, 37 -> "50"
|
||||
6, 38 -> "03"
|
||||
7, 8 -> "04"
|
||||
11 -> "82"
|
||||
12, 13, 14, 18, 39, 40 -> "10"
|
||||
15 -> "09"
|
||||
16, 17, 41, 42 -> "11"
|
||||
32 -> "80"
|
||||
19, 20, 21, 22, 23, 24, 31, 43, 44 -> "13"
|
||||
25, 26, 29 -> "81"
|
||||
else -> ""
|
||||
} + if (isDaytime) "d" else "n"
|
||||
}
|
||||
|
@ -23,4 +23,157 @@ class HereRepository {
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getWeatherIcon(iconName: String, isDaytime: Boolean): String = when(iconName.substringAfter("night_")) {
|
||||
"sunny" -> "01"
|
||||
"clear" -> "01"
|
||||
"mostly_sunny" -> "01"
|
||||
"mostly_clear" -> "01"
|
||||
"passing_clounds" -> "02"
|
||||
"more_sun_than_clouds" -> "02"
|
||||
"scattered_clouds" -> "02"
|
||||
"partly_cloudy" -> "02"
|
||||
"a_mixture_of_sun_and_clouds" -> "03"
|
||||
"increasing_cloudiness" -> "03"
|
||||
"breaks_of_sun_late" -> "03"
|
||||
"afternoon_clouds" -> "03"
|
||||
"morning_clouds" -> "03"
|
||||
"partly_sunny" -> "03"
|
||||
"high_level_clouds" -> "03"
|
||||
"decreasing_cloudiness" -> "03"
|
||||
"clearing_skies" -> "01"
|
||||
"high_clouds" -> "03"
|
||||
"rain_early" -> "10"
|
||||
"heavy_rain_early" -> "10"
|
||||
"strong_thunderstorms" -> "09"
|
||||
"severe_thunderstorms" -> "09"
|
||||
"thundershowers" -> "11"
|
||||
"thunderstorms" -> "11"
|
||||
"tstorms_early" -> "11"
|
||||
"isolated_tstorms_late" -> "11"
|
||||
"scattered_tstorms_late" -> "11"
|
||||
"tstorms_late" -> "11"
|
||||
"tstorms" -> "11"
|
||||
"ice_fog" -> "82"
|
||||
"more_clouds_than_sun" -> "03"
|
||||
"broken_clouds" -> "03"
|
||||
"scattered_showers" -> "10"
|
||||
"a_few_showers" -> "10"
|
||||
"light_showers" -> "10"
|
||||
"passing_showers" -> "10"
|
||||
"rain_showers" -> "10"
|
||||
"showers" -> "10"
|
||||
"widely_scattered_tstorms" -> "11"
|
||||
"isolated_tstorms" -> "11"
|
||||
"a_few_tstorms" -> "11"
|
||||
"scattered_tstorms" -> "11"
|
||||
"hazy_sunshine" -> "50"
|
||||
"haze" -> "50"
|
||||
"smoke" -> "50"
|
||||
"low_level_haze" -> "50"
|
||||
"early_fog_followed_by_sunny_skies" -> "50"
|
||||
"early_fog" -> "82"
|
||||
"light_fog" -> "82"
|
||||
"fog" -> "82"
|
||||
"dense_fog" -> "82"
|
||||
//"night_haze"
|
||||
//"night_smoke"
|
||||
//"night_low_level_haze"
|
||||
//"night_widely_scattered_tstorms"
|
||||
//"night_isolated_tstorms"
|
||||
//"night_a_few_tstorms"
|
||||
//"night_scattered_tstorms"
|
||||
//"night_tstorms"
|
||||
//"night_clear"
|
||||
"mostly_cloudy" -> "03"
|
||||
"cloudy" -> "04"
|
||||
"overcast" -> "04"
|
||||
"low_clouds" -> "03"
|
||||
"hail" -> "10"
|
||||
"sleet" -> "81"
|
||||
"light_mixture_of_precip" -> "81"
|
||||
"icy_mix" -> "81"
|
||||
"mixture_of_precip" -> "81"
|
||||
"heavy_mixture_of_precip" -> "81"
|
||||
"snow_changing_to_rain" -> "81"
|
||||
"snow_changing_to_an_icy_mix" -> "81"
|
||||
"an_icy_mix_changing_to_snow" -> "81"
|
||||
"an_icy_mix_changing_to_rain" -> "81"
|
||||
"rain_changing_to_snow" -> "81"
|
||||
"rain_changing_to_an_icy_mix" -> "81"
|
||||
"light_icy_mix_early" -> "81"
|
||||
"icy_mix_early" -> "81"
|
||||
"light_icy_mix_late" -> "81"
|
||||
"icy_mix_late" -> "81"
|
||||
"snow_rain_mix" -> "81"
|
||||
"scattered_flurries" -> "13"
|
||||
"snow_flurries" -> "13"
|
||||
"light_snow_showers" -> "13"
|
||||
"snow_showers" -> "13"
|
||||
"light_snow" -> "13"
|
||||
"flurries_early" -> "13"
|
||||
"snow_showers_early" -> "13"
|
||||
"light_snow_early" -> "13"
|
||||
"flurries_late" -> "13"
|
||||
"snow_showers_late" -> "13"
|
||||
"light_snow_late" -> "13"
|
||||
//"night_decreasing_cloudiness"
|
||||
//"night_clearing_skies"
|
||||
//"night_high_level_clouds"
|
||||
//"night_high_clouds"
|
||||
//"night_scattered_showers"
|
||||
//"night_a_few_showers"
|
||||
//"night_light_showers"
|
||||
//"night_passing_showers"
|
||||
//"night_rain_showers"
|
||||
//"night_sprinkles"
|
||||
//"night_showers"
|
||||
//"night_mostly_clear"
|
||||
//"night_passing_clouds"
|
||||
//"night_scattered_clouds"
|
||||
//"night_partly_cloudy"
|
||||
//"increasing_cloudiness"
|
||||
//"night_afternoon_clouds"
|
||||
//"night_morning_clouds"
|
||||
//"night_broken_clouds"
|
||||
//"night_mostly_cloudy"
|
||||
"light_freezing_rain" -> "81"
|
||||
"freezing_rain" -> "81"
|
||||
"heavy_rain" -> "10"
|
||||
"lots_of_rain" -> "10"
|
||||
"tons_of_rain" -> "10"
|
||||
//"heavy_rain_early" -> "10"
|
||||
"heavy_rain_late" -> "10"
|
||||
"flash_floods" -> "10"
|
||||
"flood" -> "10"
|
||||
"drizzle" -> "10"
|
||||
"sprinkles" -> "10"
|
||||
"light_rain" -> "10"
|
||||
"sprinkles_early" -> "10"
|
||||
"light_rain_early" -> "10"
|
||||
"sprinkles_late" -> "10"
|
||||
"light_rain_late" -> "10"
|
||||
"rain" -> "10"
|
||||
"numerous_showers" -> "10"
|
||||
"showery" -> "10"
|
||||
"showers_early" -> "10"
|
||||
//"rain_early" -> "10"
|
||||
"showers_late" -> "10"
|
||||
"rain_late" -> "10"
|
||||
"snow" -> "13"
|
||||
"moderate_snow" -> "13"
|
||||
"snow_early" -> "13"
|
||||
"snow_late" -> "13"
|
||||
"heavy_snow" -> "13"
|
||||
"heavy_snow_early" -> "13"
|
||||
"heavy_snow_late" -> "13"
|
||||
"tornado" -> "80"
|
||||
"tropical_storm" -> "09"
|
||||
"hurricane" -> "80"
|
||||
"sandstorm" -> "50"
|
||||
"duststorm" -> "50"
|
||||
"snowstorm" -> "13"
|
||||
"blizzard" -> "13"
|
||||
else -> ""
|
||||
} + if (isDaytime) "d" else "n"
|
||||
}
|
||||
|
@ -115,8 +115,6 @@ class WeatherProviderActivity : AppCompatActivity() {
|
||||
|
||||
adapter.updateData(
|
||||
Constants.WeatherProvider.values().asList()
|
||||
.filter { it != Constants.WeatherProvider.HERE }
|
||||
.filter { it != Constants.WeatherProvider.ACCUWEATHER }
|
||||
)
|
||||
|
||||
setupListener()
|
||||
@ -165,7 +163,7 @@ class WeatherProviderActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onMessageEvent(ignore: MainFragment.UpdateUiMessageEvent?) {
|
||||
fun onMessageEvent(@Suppress("UNUSED_PARAMETER") ignore: MainFragment.UpdateUiMessageEvent?) {
|
||||
binding.loader.isVisible = Preferences.weatherProviderError == "-"
|
||||
if (Preferences.weatherProviderError == "" && Preferences.weatherProviderLocationError == "") {
|
||||
Snackbar.make(binding.listView, getString(R.string.settings_weather_provider_api_key_subtitle_all_set), Snackbar.LENGTH_LONG).show()
|
||||
|
Loading…
x
Reference in New Issue
Block a user