|
|
|
|
@@ -1,19 +1,22 @@
|
|
|
|
|
package ru.myitschool.work.ui.screen.auth
|
|
|
|
|
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
|
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.rememberScrollState
|
|
|
|
|
import androidx.compose.foundation.verticalScroll
|
|
|
|
|
import androidx.compose.material3.Button
|
|
|
|
|
import androidx.compose.material3.CircularProgressIndicator
|
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
|
import androidx.compose.material3.OutlinedTextField
|
|
|
|
|
import androidx.compose.material3.Surface
|
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.material3.TextField
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
|
|
import androidx.compose.runtime.collectAsState
|
|
|
|
|
@@ -24,7 +27,6 @@ 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.layout.onGloballyPositioned
|
|
|
|
|
import androidx.compose.ui.platform.testTag
|
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
|
|
@@ -33,6 +35,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
|
|
import androidx.navigation.NavController
|
|
|
|
|
import ru.myitschool.work.R
|
|
|
|
|
import ru.myitschool.work.core.TestIds
|
|
|
|
|
import ru.myitschool.work.ui.components.conditionalImePadding
|
|
|
|
|
import ru.myitschool.work.ui.nav.MainScreenDestination
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
@@ -51,15 +54,11 @@ fun AuthScreen(
|
|
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.padding(all = 24.dp),
|
|
|
|
|
.padding(all = 32.dp)
|
|
|
|
|
.conditionalImePadding(),
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
|
|
verticalArrangement = Arrangement.Center
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
text = stringResource(R.string.auth_title),
|
|
|
|
|
style = MaterialTheme.typography.headlineMedium,
|
|
|
|
|
textAlign = TextAlign.Center
|
|
|
|
|
)
|
|
|
|
|
when (val currentState = state) {
|
|
|
|
|
is AuthState.Loading -> {
|
|
|
|
|
CircularProgressIndicator(
|
|
|
|
|
@@ -80,7 +79,12 @@ private fun Content(
|
|
|
|
|
val err by viewModel.errorFlow.collectAsState()
|
|
|
|
|
val isButtonEnabled by viewModel.isButtonEnabled.collectAsState()
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.size(16.dp))
|
|
|
|
|
Text(
|
|
|
|
|
text = stringResource(R.string.auth_title),
|
|
|
|
|
style = MaterialTheme.typography.headlineLarge,
|
|
|
|
|
textAlign = TextAlign.Center
|
|
|
|
|
)
|
|
|
|
|
Spacer(modifier = Modifier.size(48.dp))
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
modifier = Modifier.testTag(TestIds.Auth.CODE_INPUT).fillMaxWidth(),
|
|
|
|
|
value = inputText,
|
|
|
|
|
@@ -88,11 +92,12 @@ private fun Content(
|
|
|
|
|
inputText = it
|
|
|
|
|
viewModel.onIntent(AuthIntent.TextInput(it))
|
|
|
|
|
},
|
|
|
|
|
shape = MaterialTheme.shapes.medium,
|
|
|
|
|
label = { Text(stringResource(R.string.auth_label)) },
|
|
|
|
|
placeholder = { Text(stringResource(R.string.auth_label)) }
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
Spacer(modifier = Modifier.size(16.dp))
|
|
|
|
|
Spacer(modifier = Modifier.size(24.dp))
|
|
|
|
|
if (state == AuthState.Error) {
|
|
|
|
|
Text(
|
|
|
|
|
text = err,
|
|
|
|
|
@@ -104,12 +109,17 @@ private fun Content(
|
|
|
|
|
Button(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.testTag(TestIds.Auth.SIGN_BUTTON)
|
|
|
|
|
.fillMaxWidth(),
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(56.dp),
|
|
|
|
|
onClick = {
|
|
|
|
|
viewModel.onIntent(AuthIntent.Send(inputText))
|
|
|
|
|
},
|
|
|
|
|
shape = MaterialTheme.shapes.large,
|
|
|
|
|
enabled = isButtonEnabled
|
|
|
|
|
) {
|
|
|
|
|
Text(stringResource(R.string.auth_sign_in))
|
|
|
|
|
Text(
|
|
|
|
|
text = stringResource(R.string.auth_sign_in),
|
|
|
|
|
style = MaterialTheme.typography.titleLarge
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|