@@ -53,7 +53,9 @@ enum class ValueType {
5353 Unknown ,
5454}
5555
56- data class ArrayValueType <T : ValueType >(val v : T )
56+ data class ArrayValueType <T : ValueType >(
57+ val v : T ,
58+ )
5759
5860@OptIn(ExperimentalMaterial3Api ::class )
5961@Composable
@@ -79,13 +81,18 @@ fun EditPropertyDialog(
7981 properties = DialogProperties (),
8082 ) {
8183 Card (
82- colors = CardDefaults .cardColors(
83- containerColor = AlertDialogDefaults .containerColor,
84- contentColor = AlertDialogDefaults .textContentColor,
85- ),
84+ colors =
85+ CardDefaults .cardColors(
86+ containerColor = AlertDialogDefaults .containerColor,
87+ contentColor = AlertDialogDefaults .textContentColor,
88+ ),
8689 ) {
8790 Column (modifier = Modifier .padding(20 .dp)) {
88- Text (stringResource(R .string.update_value), modifier = Modifier .padding(bottom = 16 .dp), style = MaterialTheme .typography.titleMedium)
91+ Text (
92+ stringResource(R .string.update_value),
93+ modifier = Modifier .padding(bottom = 16 .dp),
94+ style = MaterialTheme .typography.titleMedium,
95+ )
8996 if (availableKeys != null ) {
9097 ExposedDropdownMenuBox (
9198 expanded = keyDropdownExpanded,
@@ -96,12 +103,13 @@ fun EditPropertyDialog(
96103 ) {
97104 TextField (
98105 // The `menuAnchor` modifier must be passed to the text field for correctness.
99- modifier = Modifier
100- .menuAnchor()
101- .fillMaxWidth()
102- .onFocusChanged {
103- onKeyDropdownExpandedChange(it.isFocused)
104- },
106+ modifier =
107+ Modifier
108+ .menuAnchor()
109+ .fillMaxWidth()
110+ .onFocusChanged {
111+ onKeyDropdownExpandedChange(it.isFocused)
112+ },
105113 value = configKey,
106114 onValueChange = { onConfigKeyChange(it) },
107115 label = { Text (stringResource(R .string.property_name)) },
@@ -134,23 +142,31 @@ fun EditPropertyDialog(
134142 )
135143 }
136144 Row (
137- modifier = Modifier
138- .fillMaxWidth()
139- .padding(top = 4 .dp),
140- verticalAlignment = if (selectedValueType == ValueType .Bool ) { Alignment .CenterVertically } else { Alignment .Top },
145+ modifier =
146+ Modifier
147+ .fillMaxWidth()
148+ .padding(top = 4 .dp),
149+ verticalAlignment =
150+ if (selectedValueType == ValueType .Bool ) {
151+ Alignment .CenterVertically
152+ } else {
153+ Alignment .Top
154+ },
141155 ) {
142156 ExposedDropdownMenuBox (
143157 expanded = valueTypeDropdownExpanded,
144158 onExpandedChange = { onValueDropdownExpandedChange(it) },
145- modifier = Modifier
146- .padding(bottom = 8 .dp)
147- .weight(1.0F ),
159+ modifier =
160+ Modifier
161+ .padding(bottom = 8 .dp)
162+ .weight(1.0F ),
148163 ) {
149164 TextField (
150165 // The `menuAnchor` modifier must be passed to the text field for correctness.
151- modifier = Modifier
152- .menuAnchor()
153- .weight(1.0F ),
166+ modifier =
167+ Modifier
168+ .menuAnchor()
169+ .weight(1.0F ),
154170 readOnly = true ,
155171 value = selectedValueType?.name ? : " " ,
156172 onValueChange = {},
@@ -182,26 +198,28 @@ fun EditPropertyDialog(
182198 Box (modifier = Modifier .weight(0.05F ))
183199 Box (modifier = Modifier .weight(1.0F , fill = true )) {
184200 when (selectedValueType) {
185- ValueType .Bool -> Row (
186- modifier = Modifier .selectableGroup(),
187- verticalAlignment = Alignment .CenterVertically ,
188- ) {
189- RadioButton (
190- selected = value == " true" ,
191- onClick = { onValueChange(" true" ) },
192- )
193- Text (stringResource(R .string.true_))
194- RadioButton (
195- selected = value == " false" ,
196- onClick = { onValueChange(" false" ) },
201+ ValueType .Bool ->
202+ Row (
203+ modifier = Modifier .selectableGroup(),
204+ verticalAlignment = Alignment .CenterVertically ,
205+ ) {
206+ RadioButton (
207+ selected = value == " true" ,
208+ onClick = { onValueChange(" true" ) },
209+ )
210+ Text (stringResource(R .string.true_))
211+ RadioButton (
212+ selected = value == " false" ,
213+ onClick = { onValueChange(" false" ) },
214+ )
215+ Text (stringResource(R .string.false_))
216+ }
217+ ValueType .Int , ValueType .Long ->
218+ TextField (
219+ value = value,
220+ onValueChange = { onValueChange(it) },
221+ keyboardOptions = KeyboardOptions (keyboardType = KeyboardType .Text ),
197222 )
198- Text (stringResource(R .string.false_))
199- }
200- ValueType .Int , ValueType .Long -> TextField (
201- value = value,
202- onValueChange = { onValueChange(it) },
203- keyboardOptions = KeyboardOptions (keyboardType = KeyboardType .Text ),
204- )
205223 is ValueType -> TextField (value = value, onValueChange = { onValueChange(it) })
206224 else -> Box (modifier = Modifier .fillMaxWidth())
207225 }
@@ -217,9 +235,10 @@ fun EditPropertyDialog(
217235 TextButton (
218236 border = if (selectedValueType != null ) BorderStroke (0.5 .dp, MaterialTheme .colorScheme.primary) else null ,
219237 shape = ButtonDefaults .outlinedShape,
220- colors = ButtonDefaults .filledTonalButtonColors(
221- containerColor = MaterialTheme .colorScheme.primary,
222- ),
238+ colors =
239+ ButtonDefaults .filledTonalButtonColors(
240+ containerColor = MaterialTheme .colorScheme.primary,
241+ ),
223242 onClick = {
224243 if (onUpdate(configKey, selectedValueType, value)) {
225244 dismissDialog()
@@ -234,7 +253,11 @@ fun EditPropertyDialog(
234253}
235254
236255@Composable
237- fun KeyValueEditView (label : String , availableKeys : Iterable <String >? = null, onUpdate : ((String , ValueType ? , String ) -> Boolean )) {
256+ fun KeyValueEditView (
257+ label : String ,
258+ availableKeys : Iterable <String >? = null,
259+ onUpdate : ((String , ValueType ? , String ) -> Boolean ),
260+ ) {
238261 var configKey by rememberSaveable { mutableStateOf(" " ) }
239262 var selectedValueType: ValueType ? by rememberSaveable { mutableStateOf(null ) }
240263 var value by rememberSaveable { mutableStateOf(" " ) }
@@ -246,16 +269,17 @@ fun KeyValueEditView(label: String, availableKeys: Iterable<String>? = null, onU
246269 LaunchedEffect (configKey) {
247270 if (availableKeys != null ) {
248271 withContext(Dispatchers .Default ) {
249- filteringOptions = if (configKey.length >= 3 ) {
250- val filteredItems = availableKeys.filter { it.contains(configKey, ignoreCase = false ) }
251- if (filteredItems.size > 7 ) {
252- filteredItems.subList(0 , 7 )
272+ filteringOptions =
273+ if (configKey.length >= 3 ) {
274+ val filteredItems = availableKeys.filter { it.contains(configKey, ignoreCase = false ) }
275+ if (filteredItems.size > 7 ) {
276+ filteredItems.subList(0 , 7 )
277+ } else {
278+ filteredItems
279+ }
253280 } else {
254- filteredItems
281+ listOf ()
255282 }
256- } else {
257- listOf ()
258- }
259283 }
260284 }
261285 }
0 commit comments