Skip to content

Instantly share code, notes, and snippets.

@fabioCollini
Created June 12, 2019 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabioCollini/982d1477ca7a973987462ff4c37c36fd to your computer and use it in GitHub Desktop.
Save fabioCollini/982d1477ca7a973987462ff4c37c36fd to your computer and use it in GitHub Desktop.
class WeatherUseCase(
private val locationManager: LocationManager,
private val repository: TemperatureRepository) {
suspend fun getCityData(): String = coroutineScope {
try {
val location = locationManager.getLastLocation()
val cities = async { locationManager.getCities(location) }
val temperature = repository.getTemperature(
location.lat, location.lon)
val city = cities.await().getOrElse(0) { "No city found" }
"$city \n $temperature"
} catch (e: Exception) {
"Error retrieving data: ${e.message}"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment