Created
July 6, 2022 15:38
-
-
Save ibrajix/1f817ef4552a1ad3326be8d66bdcb2f2 to your computer and use it in GitHub Desktop.
HomeScreenItems.kt
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 HomeScreenItems( | |
modifier: Modifier = Modifier, | |
navigator: DestinationsNavigator, | |
albums: List<Album>, | |
albumDatabaseViewModel: AlbumDatabaseViewModel = hiltViewModel(), | |
onCardClicked: (String) -> Unit, | |
onPopularAlbumClicked: () -> Unit | |
) { | |
LazyColumn( | |
modifier = modifier | |
.fillMaxSize() | |
.background(MaterialTheme.colors.bgHome) | |
.padding(20.dp) | |
){ | |
/** | |
* Non-Dynamic Items | |
*/ | |
item { | |
//first section | |
UserHomeSection() | |
//search home screen | |
SearchSection( | |
searchTextFieldValue = "", | |
onSearchTextFieldValueChange = { }, | |
onSearchTextFieldClicked = { navigator.navigate(SearchScreenDestination) }, | |
searchFieldPlaceHolder = R.string.search_albums, | |
searchEnabled = false, | |
showKeyboardOnStart = false | |
) | |
//popular item section | |
PopularAlbumSection( | |
cardTextTitle = R.string.popular, | |
cardTextItem = R.string.top_trending_albums, | |
cardImage = R.drawable.ic_character, | |
onPopularAlbumCardClicked = { | |
//popular album clicked, go to apple music | |
onPopularAlbumClicked() | |
} | |
) | |
} | |
/** | |
* Dynamic Items | |
*/ | |
item{ | |
Text( | |
modifier = modifier | |
.fillMaxWidth() | |
.padding(top = 12.dp), | |
style = MaterialTheme.typography.h2, | |
fontSize = 18.sp, | |
color = MaterialTheme.colors.onSecondary, | |
text = stringResource(id = R.string.all_albums) | |
) | |
} | |
items(items = albums){ album-> | |
AlbumCard( | |
album = album, | |
onClickCard = { albumUrl-> | |
//card clicked, go to details screen | |
onCardClicked(albumUrl) | |
}, | |
onClickLike = { isLiked, albumId-> | |
albumDatabaseViewModel.doUpdateAlbumLikedStatus(!isLiked, albumId) | |
} | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment