diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..ed76bea
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/dev/lonami/talaria/MainActivity.kt b/app/src/main/java/dev/lonami/talaria/MainActivity.kt
index eb4053d..a12545a 100644
--- a/app/src/main/java/dev/lonami/talaria/MainActivity.kt
+++ b/app/src/main/java/dev/lonami/talaria/MainActivity.kt
@@ -35,12 +35,16 @@ class MainActivity : ComponentActivity() {
}
}
-fun isPhoneValid(phone: String): Boolean {
- return phone.trim('+', ' ').isNotEmpty()
+enum class LoginStage {
+ ASK_PHONE,
+ ASK_CODE,
}
+fun isPhoneValid(phone: String): Boolean = phone.trim('+', ' ').isNotEmpty()
+fun isLoginCodeValid(code: String): Boolean = code.trim().count { it.isDigit() } == 5
+
@Composable
-fun PhoneInput(phone: String, onPhoneChanged: (String) -> Unit) {
+fun PhoneInput(phone: String, onPhoneChanged: (String) -> Unit, onSendCode: () -> Unit) {
Text(stringResource(R.string.enter_phone))
TextField(
phone,
@@ -55,16 +59,46 @@ fun PhoneInput(phone: String, onPhoneChanged: (String) -> Unit) {
onValueChange = onPhoneChanged
)
Spacer(Modifier.height(16.dp))
- Button(enabled = isPhoneValid(phone), modifier = Modifier.fillMaxWidth(), onClick = {
-
- }) {
+ Button(
+ enabled = isPhoneValid(phone),
+ modifier = Modifier.fillMaxWidth(),
+ onClick = onSendCode
+ ) {
Text(stringResource(R.string.send_otp))
}
}
+@Composable
+fun OtpInput(otp: String, onOtpChanged: (String) -> Unit, onConfirmOtp: () -> Unit) {
+ Text(stringResource(R.string.enter_otp))
+ TextField(
+ otp,
+ label = { Text(stringResource(R.string.otp)) },
+ placeholder = { Text(stringResource(R.string.otp_example)) },
+ singleLine = true,
+ keyboardOptions = KeyboardOptions(
+ keyboardType = KeyboardType.Number,
+ imeAction = ImeAction.Done
+ ),
+ modifier = Modifier.fillMaxWidth(),
+ onValueChange = onOtpChanged
+ )
+ Spacer(Modifier.height(16.dp))
+ Button(
+ enabled = isLoginCodeValid(otp),
+ modifier = Modifier.fillMaxWidth(),
+ onClick = onConfirmOtp
+ ) {
+ Text(stringResource(R.string.do_login))
+ }
+}
+
@Composable
fun Login() {
+ var stage by remember { mutableStateOf(LoginStage.ASK_PHONE) }
var phone by remember { mutableStateOf("") }
+ var otp by remember { mutableStateOf("") }
+
Column(
modifier = Modifier
.fillMaxSize()
@@ -80,7 +114,15 @@ fun Login() {
.wrapContentWidth(Alignment.CenterHorizontally)
.padding(16.dp)
)
- PhoneInput(phone, onPhoneChanged = { phone = it })
+ when (stage) {
+ LoginStage.ASK_PHONE -> PhoneInput(
+ phone,
+ onPhoneChanged = { phone = it },
+ onSendCode = { stage = LoginStage.ASK_CODE })
+ LoginStage.ASK_CODE -> OtpInput(otp, onOtpChanged = { otp = it }, onConfirmOtp = {
+
+ })
+ }
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9035d6b..ad0ff3d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -5,5 +5,8 @@
Phone (international format)
+34 600 000 000
Send code
+ Enter the code you received:
+ Code
+ 12345
Login
\ No newline at end of file