diff --git a/app/src/main/java/com/example/shawarma/screens/authorization/AuthorizationScreen.kt b/app/src/main/java/com/example/shawarma/screens/authorization/AuthorizationScreen.kt index 44e4c06..1a2775a 100644 --- a/app/src/main/java/com/example/shawarma/screens/authorization/AuthorizationScreen.kt +++ b/app/src/main/java/com/example/shawarma/screens/authorization/AuthorizationScreen.kt @@ -9,10 +9,12 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll +import androidx.compose.material.AlertDialog import androidx.compose.material.Button import androidx.compose.material.ButtonDefaults import androidx.compose.material.Card import androidx.compose.material.Text +import androidx.compose.material.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.mutableStateOf @@ -22,6 +24,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp @@ -32,6 +35,7 @@ import androidx.navigation.NavHostController import com.example.shawarma.data.sharedpref.PreferencesManager import com.example.shawarma.ui.theme.JejuFamily import com.example.shawarma.ui.theme.MyLightRed +import com.example.shawarma.ui.theme.NunitoFamily import com.example.shawarma.utils.ScreenPaths import com.example.shawarma.viewmodels.UserViewModel import com.example.shawarma.widgets.MyTextField @@ -63,6 +67,40 @@ fun AuthorizationCard(navHostController: NavHostController) { } } + if (userViewModel.authorizationState.observeAsState().value == false) { + AlertDialog( + title = { + Text( + text = "Ошибка входа в аккаунт", + fontFamily = NunitoFamily, + fontWeight = FontWeight.Bold, + fontSize = 20.sp + ) + }, + text = { + Text( + text = "Проверьте корректность введенных данных", + fontFamily = NunitoFamily, + fontWeight = FontWeight.Normal, + fontSize = 16.sp + ) + }, + onDismissRequest = { + userViewModel.calmAuthorizationState() + }, + buttons = { + TextButton( + onClick = { + userViewModel.calmAuthorizationState() + } + ) { + Text("ОК") + } + + } + ) + } + Column( horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier diff --git a/app/src/main/java/com/example/shawarma/screens/registration/RegistrationScreen.kt b/app/src/main/java/com/example/shawarma/screens/registration/RegistrationScreen.kt index c87440d..5bead58 100644 --- a/app/src/main/java/com/example/shawarma/screens/registration/RegistrationScreen.kt +++ b/app/src/main/java/com/example/shawarma/screens/registration/RegistrationScreen.kt @@ -53,8 +53,6 @@ fun RegistrationCard(navHostController: NavHostController){ val password = remember { mutableStateOf(TextFieldValue("")) } val passwordRepeat = remember { mutableStateOf(TextFieldValue("")) } - val showError = remember { mutableStateOf(false) } - val userViewModel: UserViewModel = hiltViewModel() if (userViewModel.registrationState.observeAsState().value == true) { @@ -64,9 +62,8 @@ fun RegistrationCard(navHostController: NavHostController){ } } } - showError.value = userViewModel.registrationState.observeAsState().value == false - if (showError.value) { + if (userViewModel.registrationState.observeAsState().value == false) { AlertDialog( title = { Text( @@ -85,12 +82,12 @@ fun RegistrationCard(navHostController: NavHostController){ ) }, onDismissRequest = { - userViewModel.calmRegisterState() + userViewModel.calmRegistrationState() }, buttons = { TextButton( onClick = { - userViewModel.calmRegisterState() + userViewModel.calmRegistrationState() } ) { Text("ОК") diff --git a/app/src/main/java/com/example/shawarma/viewmodels/UserViewModel.kt b/app/src/main/java/com/example/shawarma/viewmodels/UserViewModel.kt index 31fe2b9..3cf56bd 100644 --- a/app/src/main/java/com/example/shawarma/viewmodels/UserViewModel.kt +++ b/app/src/main/java/com/example/shawarma/viewmodels/UserViewModel.kt @@ -19,6 +19,9 @@ class UserViewModel @Inject constructor( private val _userModel = MutableLiveData() val userModel: LiveData get() = _userModel + private val _authorizationState = MutableLiveData() + val authorizationState: LiveData + get() = _authorizationState fun login(login: String, password: String){ viewModelScope.launch { @@ -26,15 +29,21 @@ class UserViewModel @Inject constructor( userRepository.login(login, password).collect() { user -> if (user != null) { _userModel.postValue(user) + _authorizationState.postValue(true) } else { _userModel.postValue(null) + _authorizationState.postValue(false) } } } } } + fun calmAuthorizationState() { + _authorizationState.postValue(null) + } + private val _registrationState = MutableLiveData() val registrationState: LiveData get() = _registrationState @@ -74,7 +83,7 @@ class UserViewModel @Inject constructor( } } - fun calmRegisterState() { + fun calmRegistrationState() { _registrationState.postValue(null) }