Created
November 25, 2022 12:05
-
-
Save Filmaluco/58a6a469c50cbf5f3b64ab299c027e7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun showInfo(content : String) { | |
val json = JSONObject(content) | |
val sb = StringBuilder("Weather information:\n") | |
json.getJSONObject("location").let { | |
sb.append("City: ${it["name"]},${it["country"]}\n") | |
} | |
json.getJSONObject("current").let { | |
sb.append("Current temp: ${it["temp_c"]}\n") | |
it.getJSONObject("condition").let { | |
val icon = it["icon"] | |
/*Glide.with(this) | |
.load("https:$icon") | |
.into(binding.imageView)*/ | |
} | |
} | |
json.getJSONObject("forecast").let { | |
sb.append("\nForecast:\n") | |
val forecastday=it["forecastday"] as JSONArray | |
repeat(forecastday.length()) { | |
val dayInfo = forecastday[it] as JSONObject | |
val dayInfo2 = dayInfo["day"] as JSONObject | |
sb.append(" - ${dayInfo["date"]}: ${dayInfo2["mintemp_c"]} <-t-> ${dayInfo2["maxtemp_c"]}\n") | |
} | |
} | |
binding.tvContent.text = content | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment