Skip to content

Instantly share code, notes, and snippets.

@ibrajix
Created July 6, 2022 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibrajix/1f817ef4552a1ad3326be8d66bdcb2f2 to your computer and use it in GitHub Desktop.
Save ibrajix/1f817ef4552a1ad3326be8d66bdcb2f2 to your computer and use it in GitHub Desktop.
HomeScreenItems.kt
@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