@@ -4,6 +4,7 @@ import androidx.compose.foundation.background
44import androidx.compose.foundation.clickable
55import androidx.compose.foundation.layout.Arrangement
66import androidx.compose.foundation.layout.Box
7+ import androidx.compose.foundation.layout.Column
78import androidx.compose.foundation.layout.Row
89import androidx.compose.foundation.layout.fillMaxSize
910import androidx.compose.foundation.layout.fillMaxWidth
@@ -113,39 +114,77 @@ fun SelectCountries(
113114 val dialogState = DialogState (
114115 width = 1000 .dp, height = 720 .dp, position = WindowPosition (Alignment .Center )
115116 )
117+ var selectAllState by remember { mutableStateOf(languageList.all { it.isChecked }) }
118+
116119 DialogWindow (
117120 state = dialogState,
118121 onCloseRequest = { onDismiss(countryListState) },
119- title = " Select language " ,
122+ title = " Select Language " ,
120123 content = {
121- LazyVerticalGrid (
122- columns = GridCells .Fixed (5 ),
123- verticalArrangement = Arrangement .Center ,
124- horizontalArrangement = Arrangement .Center ,
125- modifier = Modifier .fillMaxSize()
124+ Column (
125+ horizontalAlignment = Alignment .CenterHorizontally , // Center horizontally
126+ verticalArrangement = Arrangement .Top // Align to the top
127+
126128 ) {
127- itemsIndexed(countryListState) { index, language ->
128- Row (horizontalArrangement = Arrangement .Center ,
129- verticalAlignment = Alignment .CenterVertically ,
130- modifier = Modifier .fillMaxWidth().clickable {
129+ Row (horizontalArrangement = Arrangement .SpaceAround ,
130+ verticalAlignment = Alignment .CenterVertically ,
131+ modifier = Modifier .fillMaxWidth().clickable {
132+ selectAllState = ! selectAllState
133+ countryListState =
134+ countryListState.map { it.copy(isChecked = selectAllState) }
135+ .toMutableList()
136+
137+ }) {
138+ Checkbox (
139+ checked = selectAllState,
140+ onCheckedChange = {
141+ selectAllState = it
142+ countryListState =
143+ countryListState.map { element -> element.copy(isChecked = selectAllState) }
144+ .toMutableList()
145+
146+ },
147+ )
148+ Text (
149+ text = " Select All" ,
150+ fontSize = 18 .sp,
151+ fontWeight = FontWeight .SemiBold ,
152+ modifier = Modifier .fillMaxWidth()
153+ .wrapContentHeight()
154+ )
155+ }
156+
157+ LazyVerticalGrid (
158+ columns = GridCells .Fixed (5 ),
159+ verticalArrangement = Arrangement .Center ,
160+ horizontalArrangement = Arrangement .Center ,
161+ modifier = Modifier .fillMaxSize()
162+ ) {
163+ itemsIndexed(countryListState) { index, language ->
164+ Row (horizontalArrangement = Arrangement .Center ,
165+ verticalAlignment = Alignment .CenterVertically ,
166+ modifier = Modifier .fillMaxWidth().clickable {
131167 countryListState = countryListState.toMutableList().apply {
132168 this [index] = language.copy(isChecked = ! language.isChecked)
133169 }
170+ selectAllState = languageList.all { it.isChecked }
134171 }) {
135- Checkbox (
136- checked = language.isChecked,
137- onCheckedChange = {
138- countryListState = countryListState.toMutableList().apply {
139- this [index] = language.copy(isChecked = it)
140- }
141- },
142- )
143- Text (
144- text = " ${language.name} (${language.code} )" ,
145- fontSize = 18 .sp,
146- fontWeight = FontWeight .SemiBold ,
147- modifier = Modifier .fillMaxWidth().wrapContentHeight()
148- )
172+ Checkbox (
173+ checked = language.isChecked,
174+ onCheckedChange = {
175+ countryListState = countryListState.toMutableList().apply {
176+ this [index] = language.copy(isChecked = it)
177+ }
178+ selectAllState = languageList.all { it.isChecked }
179+ },
180+ )
181+ Text (
182+ text = " ${language.name} (${language.code} )" ,
183+ fontSize = 18 .sp,
184+ fontWeight = FontWeight .SemiBold ,
185+ modifier = Modifier .fillMaxWidth().wrapContentHeight()
186+ )
187+ }
149188 }
150189 }
151190 }
0 commit comments