Skip to content

Instantly share code, notes, and snippets.

@Filmaluco
Created November 25, 2022 12:05
Show Gist options
  • Save Filmaluco/58a6a469c50cbf5f3b64ab299c027e7c to your computer and use it in GitHub Desktop.
Save Filmaluco/58a6a469c50cbf5f3b64ab299c027e7c to your computer and use it in GitHub Desktop.
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