@@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.size
18
18
import androidx.compose.foundation.layout.width
19
19
import androidx.compose.foundation.rememberScrollState
20
20
import androidx.compose.foundation.shape.RoundedCornerShape
21
+ import androidx.compose.foundation.text.KeyboardOptions
21
22
import androidx.compose.foundation.verticalScroll
22
23
import androidx.compose.material3.Button
23
24
import androidx.compose.material3.ButtonColors
@@ -42,11 +43,15 @@ import androidx.compose.ui.platform.LocalContext
42
43
import androidx.compose.ui.platform.LocalHapticFeedback
43
44
import androidx.compose.ui.res.painterResource
44
45
import androidx.compose.ui.res.stringResource
46
+ import androidx.compose.ui.text.TextRange
45
47
import androidx.compose.ui.text.font.FontWeight
48
+ import androidx.compose.ui.text.input.KeyboardCapitalization
49
+ import androidx.compose.ui.text.input.TextFieldValue
46
50
import androidx.compose.ui.text.style.TextAlign
47
51
import androidx.compose.ui.text.style.TextOverflow
48
52
import androidx.compose.ui.tooling.preview.Preview
49
53
import androidx.compose.ui.unit.dp
54
+ import androidx.compose.ui.unit.max
50
55
import androidx.compose.ui.window.Dialog
51
56
import com.windscribe.mobile.ui.AppStartActivity
52
57
import com.windscribe.mobile.ui.common.PreferenceBackground
@@ -82,7 +87,9 @@ fun AccountScreen(viewModel: AccountViewModel? = null) {
82
87
PreferencesNavBar (stringResource(R .string.my_account)) {
83
88
navController.popBackStack()
84
89
}
85
- Column (Modifier .navigationBarsPadding().verticalScroll(scrollState)) {
90
+ Column (Modifier
91
+ .navigationBarsPadding()
92
+ .verticalScroll(scrollState)) {
86
93
Spacer (modifier = Modifier .height(20 .dp))
87
94
AccountInfo (viewModel)
88
95
Spacer (modifier = Modifier .height(14 .dp))
@@ -167,19 +174,27 @@ private fun HandleAlertState(viewModel: AccountViewModel?) {
167
174
viewModel?.onDialogDismiss()
168
175
}, onSubmit = {
169
176
viewModel?.onEnterLazyLoginCode(it)
170
- })
177
+ }, true )
171
178
}
172
179
}
173
180
174
181
@Composable
175
182
private fun TextFieldDialog (
176
183
onDismiss : () -> Unit ,
177
- onSubmit : (String ) -> Unit
184
+ onSubmit : (String ) -> Unit ,
185
+ isLazyLogin : Boolean = false
178
186
) {
179
- val text = remember { mutableStateOf(" " ) }
180
187
val activity = LocalContext .current as ? AppStartActivity
181
- val hapticFeedbackEnabled by activity?.viewmodel?.hapticFeedback?.collectAsState() ? : remember { mutableStateOf(false ) }
188
+ val hapticFeedbackEnabled by activity?.viewmodel?.hapticFeedback?.collectAsState()
189
+ ? : remember { mutableStateOf(false ) }
182
190
val hapticFeedback = LocalHapticFeedback .current
191
+ var textFieldValue by remember { mutableStateOf(TextFieldValue (" " )) }
192
+ LaunchedEffect (textFieldValue.text) {
193
+ if (isLazyLogin && textFieldValue.text.replace(" -" , " " ).length == 8 ) {
194
+ onSubmit(textFieldValue.text)
195
+ }
196
+ }
197
+
183
198
Dialog (onDismissRequest = onDismiss) {
184
199
Surface (
185
200
shape = RoundedCornerShape (12 .dp),
@@ -193,9 +208,28 @@ private fun TextFieldDialog(
193
208
horizontalAlignment = Alignment .CenterHorizontally
194
209
) {
195
210
TextField (
196
- value = text.value,
197
- onValueChange = {
198
- text.value = it
211
+ value = textFieldValue,
212
+ onValueChange = { input ->
213
+ if (isLazyLogin) {
214
+ val clean = input.text
215
+ .uppercase()
216
+ .replace(" -" , " " )
217
+ .take(8 )
218
+
219
+ val formatted = if (clean.length > 4 )
220
+ " ${clean.substring(0 , 4 )} -${clean.substring(4 )} "
221
+ else clean
222
+ textFieldValue = if (formatted != textFieldValue.text) {
223
+ TextFieldValue (
224
+ text = formatted,
225
+ selection = TextRange (formatted.length)
226
+ )
227
+ } else {
228
+ input
229
+ }
230
+ } else {
231
+ textFieldValue = input
232
+ }
199
233
},
200
234
colors = TextFieldDefaults .colors().copy(
201
235
focusedContainerColor = MaterialTheme .colorScheme.primaryTextColor,
@@ -219,6 +253,10 @@ private fun TextFieldDialog(
219
253
color = MaterialTheme .colorScheme.preferencesBackgroundColor,
220
254
textAlign = TextAlign .Start
221
255
),
256
+ keyboardOptions = KeyboardOptions .Default .copy(
257
+ capitalization = KeyboardCapitalization .Characters
258
+ ),
259
+ maxLines = 1 ,
222
260
)
223
261
Spacer (modifier = Modifier .height(16 .dp))
224
262
Row {
@@ -253,7 +291,7 @@ private fun TextFieldDialog(
253
291
hapticFeedback.performHapticFeedback(HapticFeedbackType .Confirm )
254
292
}
255
293
onDismiss()
256
- onSubmit(text.value )
294
+ onSubmit(textFieldValue.text )
257
295
},
258
296
colors = ButtonColors (
259
297
containerColor = Color .Transparent ,
0 commit comments