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
val BottomNavigationElevation = 16.dp | |
@Composable | |
fun BloomBottomBar() { | |
BottomAppBar( | |
elevation = BottomNavigationElevation, | |
backgroundColor = MaterialTheme.colors.primary | |
) { | |
Row( | |
modifier = Modifier.fillMaxWidth(), | |
horizontalArrangement = Arrangement.SpaceEvenly, |
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
@Composable | |
private fun BloomBottomBarItem(isSelected: Boolean = false, text: String, @DrawableRes icon: Int) { | |
val color = | |
if (isSelected) MaterialTheme.colors.onBackground else LocalContentColor.current.copy(alpha = .6f) | |
val style = if (isSelected) MaterialTheme.typography.caption else LocalTextStyle.current | |
Column( | |
horizontalAlignment = Alignment.CenterHorizontally, | |
verticalArrangement = Arrangement.Center | |
) { |
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
@ExperimentalComposeUiApi | |
@Composable | |
fun Home() { | |
Scaffold( | |
topBar = { BloomTopBar() }, | |
bottomBar = { BloomBottomBar() } | |
) { | |
... | |
} | |
} |
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
interface IHomeGardenRepository { | |
fun getHomeGardenList(): Flow<List<HomeGarden>> | |
} | |
class HomeGardenRepository : IHomeGardenRepository { | |
override fun getHomeGardenList() = flowOf( | |
listOf( | |
HomeGarden( | |
name = "Desert chic", | |
imageRes = R.drawable.desert_chic |
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 HomeGardenViewModel(homeGardenRepository: IHomeGardenRepository) : ViewModel() { | |
val homeGardens = homeGardenRepository.getHomeGardenList() | |
} | |
@Suppress("UNCHECKED_CAST") | |
class HomeGardenViewModelFactory(private val homeGardenRepository: IHomeGardenRepository) : ViewModelProvider.Factory { | |
override fun <T : ViewModel?> create(modelClass: Class<T>): T { | |
if (modelClass.isAssignableFrom(HomeGardenViewModel::class.java)) { | |
return HomeGardenViewModel(homeGardenRepository) as T |
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
@ExperimentalComposeUiApi | |
@Composable | |
fun Bloom() { | |
val navController = rememberNavController() | |
val viewModel = viewModel( | |
HomeGardenViewModel::class.java, | |
factory = HomeGardenViewModelFactory(HomeGardenRepository()) | |
) | |
NavHost(navController, startDestination = "welcome") { |
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
@ExperimentalComposeUiApi | |
@Composable | |
fun Home(viewModel: HomeGardenViewModel) { | |
val scrollState = rememberScrollState() | |
val homeGardens by viewModel.homeGardens.collectAsState(initial = listOf()) | |
Scaffold( | |
topBar = { BloomTopBar() }, | |
bottomBar = { BloomBottomBar() } | |
) { |
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
@Composable | |
fun BloomCardRow(homeGardens: List<HomeGarden>) { | |
Text( | |
text = "Browse themes", | |
modifier = Modifier | |
.paddingFromBaseline(top = 32.dp) | |
.padding(start = 16.dp), | |
style = MaterialTheme.typography.h1, | |
color = MaterialTheme.colors.onBackground | |
) |
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
@Composable | |
private fun BloomCardRowItem(homeGarden: HomeGarden) { | |
val cardShape = MaterialTheme.shapes.small.copy( | |
bottomStart = CornerSize(0.dp), | |
bottomEnd = CornerSize(0.dp) | |
) | |
Box( | |
modifier = Modifier | |
.size(138.dp) |
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
@Composable | |
fun BloomImageList(homeGardens: List<HomeGarden>) { | |
Row( | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(top = 32.dp, start = 16.dp), | |
horizontalArrangement = Arrangement.SpaceBetween, | |
verticalAlignment = Alignment.CenterVertically | |
) { | |
Text( |