Merge branch 'patch-1' into patch-develop

This commit is contained in:
azuo 2021-09-26 22:29:09 +08:00
commit 32c580bac7
7 changed files with 372 additions and 140 deletions

View File

@ -342,13 +342,13 @@ object WeatherHelper {
fun getWeatherGovIcon(iconString: String, isDaytime: Boolean): String = when (iconString.substringBefore('?').substringAfterLast('/')) { fun getWeatherGovIcon(iconString: String, isDaytime: Boolean): String = when (iconString.substringBefore('?').substringAfterLast('/')) {
"skc" -> "01" "skc" -> "01"
"few" -> "02" "few" -> "02"
"sct" -> "03" "sct" -> "02"
"bkn" -> "04" "bkn" -> "03"
"ovc" -> "04" "ovc" -> "04"
"wind_skc" -> "01" "wind_skc" -> "01"
"wind_few" -> "02" "wind_few" -> "02"
"wind_sct" -> "03" "wind_sct" -> "02"
"wind_bkn" -> "04" "wind_bkn" -> "03"
"wind_ovc" -> "04" "wind_ovc" -> "04"
"snow" -> "13" "snow" -> "13"
"rain_snow" -> "81" "rain_snow" -> "81"
@ -361,28 +361,28 @@ object WeatherHelper {
"rain" -> "10" "rain" -> "10"
"rain_showers" -> "10" "rain_showers" -> "10"
"rain_showers_hi" -> "10" "rain_showers_hi" -> "10"
"tsra" -> "82" "tsra" -> "09"
"tsra_sct" -> "82" "tsra_sct" -> "11"
"tsra_hi" -> "82" "tsra_hi" -> "11"
"tornado" -> "80" "tornado" -> "80"
"hurricane" -> "80" "hurricane" -> "80"
"tropical_storm" -> "09" "tropical_storm" -> "09"
"dust" -> "Dust" "dust" -> "50"
"smoke" -> "Smoke" "smoke" -> "50"
"haze" -> "50" "haze" -> "50"
"hot" -> "01" "hot" -> "01"
"cold" -> "13" "cold" -> "13"
"blizzard" -> "80" "blizzard" -> "13"
"fog" -> "82" "fog" -> "82"
else -> "" else -> ""
} + if (isDaytime) "d" else "n" } + if (isDaytime) "d" else "n"
fun getWeatherBitIcon(iconString: String): String = when (iconString.substring(0, 3)) { fun getWeatherBitIcon(iconString: String): String = when (iconString.substring(0, 3)) {
"t01" -> "11" "t01" -> "11"
"t02" -> "09" "t02" -> "11"
"t03" -> "09" "t03" -> "09"
"t04" -> "09" "t04" -> "11"
"t05" -> "09" "t05" -> "11"
"d01" -> "10" "d01" -> "10"
"d02" -> "10" "d02" -> "10"
"d03" -> "10" "d03" -> "10"
@ -397,17 +397,17 @@ object WeatherHelper {
"s02" -> "13" "s02" -> "13"
"s03" -> "13" "s03" -> "13"
"s04" -> "81" "s04" -> "81"
"s05" -> "90" "s05" -> "81"
"s06" -> "13" "s06" -> "13"
"a01" -> "82" "a01" -> "50"
"a02" -> "82" "a02" -> "50"
"a03" -> "82" "a03" -> "50"
"a04" -> "82" "a04" -> "50"
"a05" -> "82" "a05" -> "82"
"a06" -> "82" "a06" -> "82"
"c01" -> "01" "c01" -> "01"
"c02" -> "02" "c02" -> "02"
"c03" -> "04" "c03" -> "03"
"c04" -> "04" "c04" -> "04"
else -> "" else -> ""
} + iconString.substring(3) } + iconString.substring(3)
@ -417,14 +417,14 @@ object WeatherHelper {
1003 -> "02" 1003 -> "02"
1006 -> "03" 1006 -> "03"
1009 -> "04" 1009 -> "04"
1030 -> "82" 1030 -> "50"
1063 -> "10" 1063 -> "10"
1066 -> "10" 1066 -> "13"
1069 -> "10" 1069 -> "81"
1072 -> "81" 1072 -> "81"
1087 -> "11" 1087 -> "11"
1114 -> "13" 1114 -> "13"
1117 -> "09" 1117 -> "13"
1135 -> "82" 1135 -> "82"
1147 -> "82" 1147 -> "82"
1150 -> "10" 1150 -> "10"
@ -439,8 +439,8 @@ object WeatherHelper {
1195 -> "10" 1195 -> "10"
1198 -> "81" 1198 -> "81"
1201 -> "81" 1201 -> "81"
1204 -> "13" 1204 -> "81"
1207 -> "13" 1207 -> "81"
1210 -> "13" 1210 -> "13"
1213 -> "13" 1213 -> "13"
1216 -> "13" 1216 -> "13"
@ -451,13 +451,13 @@ object WeatherHelper {
1240 -> "10" 1240 -> "10"
1243 -> "10" 1243 -> "10"
1246 -> "10" 1246 -> "10"
1249 -> "13" 1249 -> "81"
1252 -> "13" 1252 -> "81"
1255 -> "13" 1255 -> "13"
1258 -> "13" 1258 -> "13"
1261 -> "13" 1261 -> "13"
1264 -> "13" 1264 -> "13"
1273 -> "09" 1273 -> "11"
1276 -> "09" 1276 -> "09"
1279 -> "13" 1279 -> "13"
1282 -> "13" 1282 -> "13"
@ -470,13 +470,13 @@ object WeatherHelper {
"fair" -> "02" "fair" -> "02"
"fog" -> "82" "fog" -> "82"
"heavyrain" -> "10" "heavyrain" -> "10"
"heavyrainandthunder" -> "11" "heavyrainandthunder" -> "09"
"heavyrainshowers" -> "10" "heavyrainshowers" -> "10"
"heavyrainshowersandthunder" -> "11" "heavyrainshowersandthunder" -> "09"
"heavysleet" -> "10" "heavysleet" -> "81"
"heavysleetandthunder" -> "11" "heavysleetandthunder" -> "81"
"heavysleetshowers" -> "10" "heavysleetshowers" -> "81"
"heavysleetshowersandthunder" -> "11" "heavysleetshowersandthunder" -> "81"
"heavysnow" -> "13" "heavysnow" -> "13"
"heavysnowandthunder" -> "13" "heavysnowandthunder" -> "13"
"heavysnowshowers" -> "13" "heavysnowshowers" -> "13"
@ -485,9 +485,9 @@ object WeatherHelper {
"lightrainandthunder" -> "11" "lightrainandthunder" -> "11"
"lightrainshowers" -> "10" "lightrainshowers" -> "10"
"lightrainshowersandthunder" -> "11" "lightrainshowersandthunder" -> "11"
"lightsleet" -> "10" "lightsleet" -> "81"
"lightsleetandthunder" -> "11" "lightsleetandthunder" -> "81"
"lightsleetshowers" -> "10" "lightsleetshowers" -> "81"
"lightsnow" -> "13" "lightsnow" -> "13"
"lightsnowandthunder" -> "13" "lightsnowandthunder" -> "13"
"lightsnowshowers" -> "13" "lightsnowshowers" -> "13"
@ -498,10 +498,10 @@ object WeatherHelper {
"rainandthunder" -> "11" "rainandthunder" -> "11"
"rainshowers" -> "10" "rainshowers" -> "10"
"rainshowersandthunder" -> "11" "rainshowersandthunder" -> "11"
"sleet" -> "10" "sleet" -> "81"
"sleetandthunder" -> "11" "sleetandthunder" -> "81"
"sleetshowers" -> "10" "sleetshowers" -> "81"
"sleetshowersandthunder" -> "11" "sleetshowersandthunder" -> "81"
"snow" -> "13" "snow" -> "13"
"snowandthunder" -> "13" "snowandthunder" -> "13"
"snowshowers" -> "13" "snowshowers" -> "13"

View File

@ -26,9 +26,7 @@ class TimeZonesApi(val context: Context) {
when (val response = repository.getTimeZone(lat, long)) { when (val response = repository.getTimeZone(lat, long)) {
is NetworkResponse.Success -> { is NetworkResponse.Success -> {
try { try {
Log.d("ciao", response.body.toString())
id = response.body["timezoneId"] as String id = response.body["timezoneId"] as String
} catch(ex: Exception) { } catch(ex: Exception) {
ex.printStackTrace() ex.printStackTrace()
} }
@ -37,4 +35,4 @@ class TimeZonesApi(val context: Context) {
return id return id
} }
} }

View File

@ -121,25 +121,34 @@ class WeatherNetworkApi(val context: Context) {
val props = val props =
weatherResponse.body["properties"] as LinkedTreeMap<*, *> weatherResponse.body["properties"] as LinkedTreeMap<*, *>
val periods = props["periods"] as List<*> 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 Preferences.weatherTemp = temp.toFloat()
val fullIcon = now["icon"] as String Preferences.weatherIcon = WeatherHelper.getWeatherGovIcon(fullIcon, isDaytime)
val isDaytime = now["isDaytime"] as Boolean Preferences.weatherRealTempUnit = Preferences.weatherTempUnit
MainWidget.updateWidget(context)
Preferences.weatherTemp = temp.toFloat() Preferences.weatherProviderError = ""
Preferences.weatherIcon = WeatherHelper.getWeatherGovIcon(fullIcon, isDaytime) Preferences.weatherProviderLocationError = ""
Preferences.weatherRealTempUnit = Preferences.weatherTempUnit break
}
Preferences.weatherProviderError = "" }
Preferences.weatherProviderLocationError = ""
MainWidget.updateWidget(context)
} catch (ex: Exception) { } catch (ex: Exception) {
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic) Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
Preferences.weatherProviderLocationError = "" Preferences.weatherProviderLocationError = ""
} finally {
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
} }
} }
else -> { else -> {
@ -155,14 +164,16 @@ class WeatherNetworkApi(val context: Context) {
} }
} }
is NetworkResponse.ServerError -> { is NetworkResponse.ServerError -> {
if (pointsResponse.body?.containsKey("status") == true && (pointsResponse.body?.get("status") as Double).toInt() == 404) { when (pointsResponse.code) {
Preferences.weatherProviderError = "" 404 -> {
Preferences.weatherProviderLocationError = context.getString(R.string.weather_provider_error_wrong_location) Preferences.weatherProviderError = ""
} else { Preferences.weatherProviderLocationError = context.getString(R.string.weather_provider_error_wrong_location)
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic) }
Preferences.weatherProviderLocationError = "" else -> {
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
Preferences.weatherProviderLocationError = ""
}
} }
WeatherHelper.removeWeather( WeatherHelper.removeWeather(
context context
) )
@ -183,7 +194,18 @@ class WeatherNetworkApi(val context: Context) {
when (val response = repository.getWeather()) { when (val response = repository.getWeather()) {
is NetworkResponse.Success -> { is NetworkResponse.Success -> {
try { 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.weatherProviderError = ""
Preferences.weatherProviderLocationError = "" Preferences.weatherProviderLocationError = ""
} catch(ex: Exception) { } catch(ex: Exception) {
@ -194,8 +216,16 @@ class WeatherNetworkApi(val context: Context) {
} }
} }
is NetworkResponse.ServerError -> { is NetworkResponse.ServerError -> {
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic) when (response.code) {
Preferences.weatherProviderLocationError = "" 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( WeatherHelper.removeWeather(
context context
) )
@ -225,10 +255,10 @@ class WeatherNetworkApi(val context: Context) {
when (val response = repository.getWeather()) { when (val response = repository.getWeather()) {
is NetworkResponse.Success -> { is NetworkResponse.Success -> {
try { try {
val data = response.body["data"] as List<LinkedTreeMap<String, Any>>? val data = response.body["data"] as List<*>?
data?.first()?.let { data?.first()?.let { it as LinkedTreeMap<*, *>
val temp = it["temp"] as Double 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 val iconCode = weatherInfo["icon"] as String
Preferences.weatherTemp = temp.toFloat() Preferences.weatherTemp = temp.toFloat()
@ -238,8 +268,6 @@ class WeatherNetworkApi(val context: Context) {
Preferences.weatherProviderError = "" Preferences.weatherProviderError = ""
Preferences.weatherProviderLocationError = "" Preferences.weatherProviderLocationError = ""
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
} }
} catch(ex: Exception) { } catch(ex: Exception) {
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic) Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
@ -288,12 +316,12 @@ class WeatherNetworkApi(val context: Context) {
when (val response = repository.getWeather()) { when (val response = repository.getWeather()) {
is NetworkResponse.Success -> { is NetworkResponse.Success -> {
try { try {
val current = response.body["current"] as LinkedTreeMap<String, Any>? val current = response.body["current"] as LinkedTreeMap<*, *>?
current?.let { current?.let {
val tempC = current["temp_c"] as Double val tempC = current["temp_c"] as Double
val tempF = current["temp_f"] as Double val tempF = current["temp_f"] as Double
val isDay = current["is_day"] 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 val iconCode = condition["code"] as Double
Preferences.weatherTemp = if (Preferences.weatherTempUnit == "F") tempF.toFloat() else tempC.toFloat() Preferences.weatherTemp = if (Preferences.weatherTempUnit == "F") tempF.toFloat() else tempC.toFloat()
@ -303,8 +331,6 @@ class WeatherNetworkApi(val context: Context) {
Preferences.weatherProviderError = "" Preferences.weatherProviderError = ""
Preferences.weatherProviderLocationError = "" Preferences.weatherProviderLocationError = ""
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
} }
} catch(ex: Exception) { } catch(ex: Exception) {
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic) 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) { private suspend fun useAccuweatherProvider(context: Context) {
if (Preferences.weatherProviderApiAccuweather != "") { if (Preferences.weatherProviderApiAccuweather != "") {
// val repository = AccuweatherRepository() val repository = AccuweatherRepository()
// when (val response = repository.getWeather()) { when (val locationResponse = repository.getLocation()) {
// is NetworkResponse.Success -> { is NetworkResponse.Success -> {
// try { try {
// Log.d("ciao", response.body.toString()) val key = locationResponse.body["Key"] as String
// } 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 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 { } else {
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_missing_key) Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_missing_key)
Preferences.weatherProviderLocationError = "" Preferences.weatherProviderLocationError = ""
@ -393,38 +465,27 @@ class WeatherNetworkApi(val context: Context) {
is NetworkResponse.Success -> { is NetworkResponse.Success -> {
try { try {
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<*>?
data?.let { data?.first()?.let { it as LinkedTreeMap<*, *>
val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").apply { timeZone = TimeZone.getTimeZone("UTC") } val dd = it["data"] as LinkedTreeMap<*, *>
for (item in data) { val instant = dd["instant"] as LinkedTreeMap<*, *>
val time = Calendar.getInstance().apply { time = format.parse(item["time"] as String)!! } val next = dd["next_1_hours"] as LinkedTreeMap<*, *>
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 details = instant["details"] as LinkedTreeMap<*, *> val details = instant["details"] as LinkedTreeMap<*, *>
val temp = details["air_temperature"] as Double val temp = details["air_temperature"] as Double
val summary = next["summary"] as LinkedTreeMap<*, *> val summary = next["summary"] as LinkedTreeMap<*, *>
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) 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)
Preferences.weatherProviderError = "" Preferences.weatherProviderError = ""
Preferences.weatherProviderLocationError = "" Preferences.weatherProviderLocationError = ""
break
}
}
} }
} catch(ex: Exception) { } catch(ex: Exception) {
ex.printStackTrace() ex.printStackTrace()
Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic) Preferences.weatherProviderError = context.getString(R.string.weather_provider_error_generic)
@ -448,4 +509,4 @@ class WeatherNetworkApi(val context: Context) {
} }
} }
} }
} }

View File

@ -13,7 +13,7 @@ object ApiServices {
): NetworkResponse<HashMap<String, Any>, HashMap<String, Any>> ): NetworkResponse<HashMap<String, Any>, HashMap<String, Any>>
@Headers("User-Agent: (Another Widget, tommaso.berlose@gmail.com)") @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( suspend fun getWeather(
@Path("gridId") gridId: String, @Path("gridId") gridId: String,
@Path("gridX") gridX: Int, @Path("gridX") gridX: Int,
@ -54,13 +54,17 @@ object ApiServices {
} }
interface AccuweatherService { interface AccuweatherService {
@GET("") @GET("locations/v1/cities/geoposition/search")
suspend fun getWeather( suspend fun getLocation(
@Path("gridId") gridId: String, @Query("apikey") apikey: String,
@Path("gridX") gridX: Int, @Query("q") location: String
@Path("gridY") gridY: Int,
@Query("units") unit: String
): NetworkResponse<HashMap<String, Any>, HashMap<String, Any>> ): 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 { interface YrService {
@ -80,4 +84,4 @@ object ApiServices {
@Query("username") username: String = "tommaso.berlose", @Query("username") username: String = "tommaso.berlose",
): NetworkResponse<HashMap<String, Any>, HashMap<String, Any>> ): NetworkResponse<HashMap<String, Any>, HashMap<String, Any>>
} }
} }

View File

@ -1,6 +1,7 @@
package com.tommasoberlose.anotherwidget.network.repository package com.tommasoberlose.anotherwidget.network.repository
import com.haroldadmin.cnradapter.NetworkResponseAdapterFactory import com.haroldadmin.cnradapter.NetworkResponseAdapterFactory
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.network.api.ApiServices import com.tommasoberlose.anotherwidget.network.api.ApiServices
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
@ -9,10 +10,11 @@ class AccuweatherRepository {
/* ACCUWEATHER */ /* ACCUWEATHER */
private val apiServiceAccu: ApiServices.AccuweatherService = getRetrofit().create(ApiServices.AccuweatherService::class.java) 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 { companion object {
private const val BASE_URL_ACCU = "" private const val BASE_URL_ACCU = "https://dataservice.accuweather.com/"
private fun getRetrofit(): Retrofit { private fun getRetrofit(): Retrofit {
return Retrofit.Builder() return Retrofit.Builder()
@ -22,4 +24,20 @@ class AccuweatherRepository {
.build() .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"
}

View File

@ -23,4 +23,157 @@ class HereRepository {
.build() .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"
}

View File

@ -115,8 +115,6 @@ class WeatherProviderActivity : AppCompatActivity() {
adapter.updateData( adapter.updateData(
Constants.WeatherProvider.values().asList() Constants.WeatherProvider.values().asList()
.filter { it != Constants.WeatherProvider.HERE }
.filter { it != Constants.WeatherProvider.ACCUWEATHER }
) )
setupListener() setupListener()
@ -165,7 +163,7 @@ class WeatherProviderActivity : AppCompatActivity() {
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(ignore: MainFragment.UpdateUiMessageEvent?) { fun onMessageEvent(@Suppress("UNUSED_PARAMETER") ignore: MainFragment.UpdateUiMessageEvent?) {
binding.loader.isVisible = Preferences.weatherProviderError == "-" binding.loader.isVisible = Preferences.weatherProviderError == "-"
if (Preferences.weatherProviderError == "" && Preferences.weatherProviderLocationError == "") { if (Preferences.weatherProviderError == "" && Preferences.weatherProviderLocationError == "") {
Snackbar.make(binding.listView, getString(R.string.settings_weather_provider_api_key_subtitle_all_set), Snackbar.LENGTH_LONG).show() Snackbar.make(binding.listView, getString(R.string.settings_weather_provider_api_key_subtitle_all_set), Snackbar.LENGTH_LONG).show()