Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private val items = listOf(
- Icons.Filled.Check,
- Icons.Filled.Close,
- Icons.Filled.ThumbUp,
- Icons.Filled.Build,
- Icons.Filled.Delete,
- Icons.Filled.Home,
- Icons.Filled.Close,
- Icons.Filled.ThumbUp,
- Icons.Filled.Build,
- Icons.Filled.ThumbUp,
- )
- @Composable
- fun GridScreen() {
- GridView(columnCount = 3)
- BackButtonHandler {
- JetFundamentalsRouter.navigateTo(Screen.Navigation)
- }
- }
- @Composable
- fun GridView(columnCount: Int) {
- val itemSize= items.size
- val rowCount= ceil(itemSize.toFloat() / columnCount).toInt()
- val gridItems= mutableListOf<List<IconResource>>()
- var position= 0
- for(i in 0 until rowCount){
- val rowItem= mutableListOf<IconResource>()
- for(j in 0 until columnCount){
- //idk the position value, init 0, when it get changed?
- //dialog appear inc() in android studio just tell "Increment this value"
- //idk when this condition true or false because idk the value...0? the inc() increment like how many?
- if(position.inc() <= itemSize){
- rowItem.add(IconResource(items[position++],true))
- }
- }
- val itemToFill= columnCount - rowItem.size
- for(j in 0 until itemToFill){
- rowItem.add(IconResource(Icons.Filled.Delete, false))
- }
- gridItems.add(rowItem)
- }
- LazyColumn(modifier= Modifier.fillMaxSize()) {
- items(gridItems){items ->
- RowItem(items)
- }
- }
- }
- @Composable
- fun RowItem(rowItems: List<IconResource>) {
- Row{
- for(element in rowItems)
- GridIcon(element)
- }
- }
- @Composable
- fun RowScope.GridIcon(iconResource: IconResource) {
- val color= if(iconResource.isVisible)
- colorResource(R.color.colorPrimary)
- else Color.Transparent
- Icon(
- imageVector =iconResource.imageVector,
- tint = color,
- contentDescription = stringResource(R.string.grid_icon),
- modifier = Modifier
- .size(80.dp,80.dp)
- .weight(1f)
- )
- }
- data class IconResource(val imageVector: ImageVector, val isVisible: Boolean)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement