Created
June 12, 2019 06:10
-
-
Save fabioCollini/982d1477ca7a973987462ff4c37c36fd 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
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