o t l i n M e e t u p 2 0 2 0 | N Y C 2 0 2 0 Pedro Veloso Twitter && Instagram: @pedronveloso Hands-On Jetpack Compose K o t l i n M e e t u p 2 0 2 0 | N Y C 2 0 2 0
Android. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs.” Source: https://developer.android.com/jetpack/compose
A n o t h e r W e a t h e r A p p l i c a t i o n • Display Current temperature, max and min • 2nd Screen with the forecast • Style the App • Forecast list must be scrollable Compose Weather
fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MaterialTheme { MainScreen() } } } @Composable fun DrawBackground() { DrawImage(image = imageResource(R.drawable.nyc_night_1)) } B a c k g r o u n d
S E N T A T I O N data class CurrentWeather( val locationName: String, val curTemperature: Temperature, val forecast: WeatherForecast ) class Temperature(val celcius: Double) data class WeatherForecast( val maxTemperature: Temperature, val minTemperature: Temperature, val state: WeatherState ) enum class WeatherState(@DrawableRes val iconResId: Int, @StringRes val descriptionResId: Int) { SUNNY(R.drawable.ic_sunny, R.string.state_sunny), RAINY(R.drawable.ic_rainy, R.string.state_rainy), PARTLY_CLOUDY(R.drawable.ic_p_cloudy, R.string.state_p_cloudy), SNOWY(R.drawable.ic_snowy, R.string.state_snowy) } <string name="state_sunny">Sunny</string> <string name="state_rainy">Rainy</string> … D a t a M o d e l s
Arrangement.Center) { Spacer(LayoutHeight(16.dp)) Text(text = currentWeather.locationName, style = MaterialTheme.typography().h2) } } C e n t e r Column { DrawBackground() Title(currentWeather) }
e c a s t @Composable fun CurrentWeatherBlock( current: CurrentWeather) { Column(modifier = LayoutWidth.Fill , arrangement = Arrangement.Center) { } } WeatherState(current) CurrentTemperature(current) MinMaxTemperatures(current)