Untitled
unknown
plain_text
8 days ago
5.6 kB
3
Indexable
Never
package com.example.pagervideoswip import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.material3.Checkbox import androidx.compose.material3.CheckboxDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.media3.common.util.UnstableApi @androidx.annotation.OptIn(UnstableApi::class) @Composable fun Parent() { var selectedmode by remember { mutableStateOf(false) } val data = remember { mutableStateListOf<Boolean>() } for (i in 0..50) data.add(false) var dem by remember { mutableIntStateOf(0) } LazyVerticalGrid( columns = GridCells.Fixed(3), horizontalArrangement = Arrangement.spacedBy(2.dp), verticalArrangement = Arrangement.spacedBy(5.dp) ) { if (selectedmode) { item(span = { GridItemSpan(maxLineSpan) }) { Row( Modifier .height(100.dp) .background(Color.White) .padding(top = 50.dp), horizontalArrangement = Arrangement.SpaceAround ) { Checkbox( checked = data[50], onCheckedChange = { data[50] = it if (data[50]) { for (i in 0..50) data[i] = true dem = 20 } else { for (i in 0..50) data[i] = false dem = 0 } }, colors = CheckboxDefaults.colors( checkedColor = Color.Black, uncheckedColor = Color.Black, checkmarkColor = Color.White ) ) Text(text = dem.toString(), color = Color.Black, fontSize = 14.sp) } } } items(count = 20) { index -> Box(Modifier.wrapContentSize()) { Children( index = index, onclick = { data[index] = it if (data[index]) dem++ else dem-- }, onLongClick = { it1, it2 -> selectedmode = it1 if (!data[index]) { data[index] = it2 dem++ } }, smode = selectedmode, checkbox = data[index], opendetail = {} ) if (selectedmode) { Checkbox( checked = data[index], onCheckedChange = { data[index] = it if (data[index]) dem++ else dem-- }, colors = CheckboxDefaults.colors( checkedColor = Color.Black, uncheckedColor = Color.LightGray, checkmarkColor = Color.White ) ) } } } } data[50] = dem == 20 } @OptIn(ExperimentalFoundationApi::class) @Composable fun Children( index: Int, onclick: (Boolean) -> Unit, opendetail: () -> Unit, onLongClick: (Boolean, Boolean) -> Unit, smode: Boolean, checkbox: Boolean ) { Box( modifier = Modifier .size(100.dp) .background(Color.Red) .combinedClickable( onClick = { if (smode) { onclick(!checkbox) } else { opendetail() } }, onLongClick = { onLongClick(true, true) }, ), contentAlignment = Alignment.Center ) { Text(text = index.toString()) } }
Leave a Comment