diff --git a/app/src/main/java/ru/myitschool/work/core/Constants.kt b/app/src/main/java/ru/myitschool/work/core/Constants.kt index ab0c588..c495a10 100644 --- a/app/src/main/java/ru/myitschool/work/core/Constants.kt +++ b/app/src/main/java/ru/myitschool/work/core/Constants.kt @@ -1,9 +1,10 @@ package ru.myitschool.work.core object Constants { - const val HOST = "http://10.0.0.103:49165" + const val HOST = "http://10.0.0.12:49165" const val AUTH_URL = "/auth" const val INFO_URL = "/info" const val BOOKING_URL = "/booking" const val BOOK_URL = "/book" + const val AUTH_DELAY = 60 } \ No newline at end of file diff --git a/app/src/main/java/ru/myitschool/work/ui/screen/auth/AuthViewModel.kt b/app/src/main/java/ru/myitschool/work/ui/screen/auth/AuthViewModel.kt index 3cb44c8..2a33de1 100644 --- a/app/src/main/java/ru/myitschool/work/ui/screen/auth/AuthViewModel.kt +++ b/app/src/main/java/ru/myitschool/work/ui/screen/auth/AuthViewModel.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch +import ru.myitschool.work.core.Constants import ru.myitschool.work.data.repo.AuthRepository import ru.myitschool.work.domain.auth.CheckAndSaveAuthCodeUseCase import ru.myitschool.work.domain.auth.CheckCodeFormatUseCase @@ -32,11 +33,14 @@ class AuthViewModel : ViewModel() { private var authTries: Int = 0 private var timerSecs: Int = 0 + private var login: String = "" + private var password: String = "" + fun onIntent(intent: AuthIntent) { when (intent) { is AuthIntent.Send -> { if (authTries >= 5) { - timerSecs = 60 + timerSecs = Constants.AUTH_DELAY val timer = object : CountDownTimer((timerSecs * 1000).toLong(), 1000) { override fun onTick(millisUntilFinished: Long) { timerSecs -= 1 @@ -53,8 +57,8 @@ class AuthViewModel : ViewModel() { updateStateIfData { oldState -> oldState.copy( isEnabledSend = checkCodeFormatUseCase.invoke( - login = intent.login, - password = intent.password + login = login, + password = password ), error = null ) @@ -79,13 +83,15 @@ class AuthViewModel : ViewModel() { } is AuthIntent.TextInput -> { + login = intent.login + password = intent.password updateStateIfData { oldState -> oldState.copy( isEnabledSend = checkCodeFormatUseCase.invoke( login = intent.login, password = intent.password - ), - error = null + ) && authTries <= 5, + error = if (authTries >= 5) oldState.error else null ) } }