Sample app, built with Jetpack Compose.
Using the Canary version of Android Studio 4.2 Canary 7 and the 0.1.0-dev15 jetpack libraries.
Using the Canary version of Android Studio Arctic Fox|2020.3.1 Canary 3 and the 1.0.0-alpha09 jetpack libraries.
This sample contains three screens: a splash screen, a list of coffee, and a page to order a coffee.
Package app.elite.coffeemaker.screen
The Package contains all the application screens.
See how to:
- Use
Rows andColumns to arrange the contents of the UI - Add an
AppBar - Add an
BottomAppBar - Add an
Image - Display
AlertDialog - Use
MaterialTypographyand opacity to style the text - Use
Shapeto round the corners of the images - Use elevation to make the
Cards stand out from the background
Package app.elite.coffeemaker.model
The Package contains all Coffee model.
See how to:
- Declare a Kotlin Model
- Using data class
The Package contains the navigation class using ViewModel and SavedStateHandle
See how to:
- Use
ViewModelto navigate between screens - Use
SavedStateHandleto handle navigation stack
Package app.elite.coffeemaker.utils
Create a sealed class to hold the screens
sealed class Screen(val route: String) {
object SplashScreen : Screen("splash")
object Home : Screen("home")
object Details : Screen("details")
}
Create a NavController by using the rememberNavController() inside the MainActivity
val navController = rememberNavController()
Finally create the NavHost using both the NavController and which screen to start with startDestination
NavHost(
navController = navController,
startDestination = Screen.SplashScreen.route
){
composable(Screen.SplashScreen.route) { BaseComponent { SplashScreen(navController = navController) } }
composable(Screen.Home.route) { BaseComponent { CoffeeListScreen(navController = navController) } }
composable("${Screen.Details.route}/{id}") {
BaseComponent {
DetailsScreen(coffee = it.arguments?.getString("id", "1")?.toInt()!!)
}
}
}
The data in the sample is static, held in the app.elite.coffeemaker.model package in the Data class.
- Adding more screen
- Adding Unit Test
- Adding Animation
- and more
Copyright 2020 The Android Open Source Project
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.


