forked from melod1n/fast-messenger
remove usage of context-receivers
This commit is contained in:
@@ -6,7 +6,6 @@ import dev.meloda.fast.auth.captcha.model.CaptchaScreenState
|
||||
import dev.meloda.fast.auth.captcha.navigation.Captcha
|
||||
import dev.meloda.fast.auth.captcha.validation.CaptchaValidator
|
||||
import dev.meloda.fast.common.extensions.setValue
|
||||
import dev.meloda.fast.common.extensions.updateValue
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
@@ -58,13 +57,13 @@ class CaptchaViewModelImpl(
|
||||
}
|
||||
|
||||
override fun onNavigatedToLogin() {
|
||||
screenState.updateValue(CaptchaScreenState.EMPTY)
|
||||
screenState.update { CaptchaScreenState.EMPTY }
|
||||
isNeedToOpenLogin.update { false }
|
||||
}
|
||||
|
||||
private fun processValidation(): Boolean {
|
||||
val isValid = validator.validate(screenState.value).isValid()
|
||||
screenState.updateValue(screenState.value.copy(codeError = !isValid))
|
||||
screenState.setValue { old -> old.copy(codeError = !isValid) }
|
||||
return isValid
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import dev.meloda.fast.common.LongPollController
|
||||
import dev.meloda.fast.common.VkConstants
|
||||
import dev.meloda.fast.common.extensions.listenValue
|
||||
import dev.meloda.fast.common.extensions.setValue
|
||||
import dev.meloda.fast.common.extensions.updateValue
|
||||
import dev.meloda.fast.common.model.LongPollState
|
||||
import dev.meloda.fast.data.State
|
||||
import dev.meloda.fast.data.UserConfig
|
||||
@@ -102,7 +101,7 @@ class LoginViewModelImpl(
|
||||
login = newLogin.trim(),
|
||||
loginError = false
|
||||
)
|
||||
screenState.updateValue(newState)
|
||||
screenState.setValue { newState }
|
||||
}
|
||||
|
||||
override fun onPasswordInputChanged(newPassword: String) {
|
||||
@@ -110,7 +109,7 @@ class LoginViewModelImpl(
|
||||
password = newPassword.trim(),
|
||||
passwordError = false
|
||||
)
|
||||
screenState.updateValue(newState)
|
||||
screenState.setValue { newState }
|
||||
}
|
||||
|
||||
override fun onSignInButtonClicked() {
|
||||
@@ -176,7 +175,7 @@ class LoginViewModelImpl(
|
||||
userIds = null,
|
||||
fields = VkConstants.USER_FIELDS,
|
||||
nomCase = null
|
||||
).listenValue { state ->
|
||||
).listenValue(viewModelScope) { state ->
|
||||
state.processState(
|
||||
error = { error ->
|
||||
UserConfig.currentUserId = -1
|
||||
@@ -227,7 +226,7 @@ class LoginViewModelImpl(
|
||||
validationCode = validationCode.value,
|
||||
captchaSid = captchaArguments.value?.captchaSid,
|
||||
captchaKey = captchaCode.value
|
||||
).listenValue { state ->
|
||||
).listenValue(viewModelScope) { state ->
|
||||
state.processState(
|
||||
error = { error ->
|
||||
Log.d("LoginViewModelImpl", "login: error: $error")
|
||||
@@ -354,11 +353,11 @@ class LoginViewModelImpl(
|
||||
validationState.value.forEach { result ->
|
||||
when (result) {
|
||||
LoginValidationResult.LoginEmpty -> {
|
||||
screenState.updateValue(screenState.value.copy(loginError = true))
|
||||
screenState.setValue { old -> old.copy(loginError = true) }
|
||||
}
|
||||
|
||||
LoginValidationResult.PasswordEmpty -> {
|
||||
screenState.updateValue(screenState.value.copy(passwordError = true))
|
||||
screenState.setValue { old -> old.copy(passwordError = true) }
|
||||
}
|
||||
|
||||
LoginValidationResult.Empty -> Unit
|
||||
|
||||
+8
-17
@@ -10,7 +10,6 @@ import dev.meloda.fast.auth.validation.validation.ValidationValidator
|
||||
import dev.meloda.fast.common.extensions.createTimerFlow
|
||||
import dev.meloda.fast.common.extensions.listenValue
|
||||
import dev.meloda.fast.common.extensions.setValue
|
||||
import dev.meloda.fast.common.extensions.updateValue
|
||||
import dev.meloda.fast.data.processState
|
||||
import dev.meloda.fast.domain.AuthUseCase
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -77,12 +76,12 @@ class ValidationViewModelImpl(
|
||||
}
|
||||
|
||||
override fun onCodeInputChanged(newCode: String) {
|
||||
screenState.updateValue(
|
||||
screenState.value.copy(
|
||||
screenState.setValue { old ->
|
||||
old.copy(
|
||||
code = newCode.trim(),
|
||||
codeError = false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (newCode.length == 6) {
|
||||
viewModelScope.launch {
|
||||
@@ -116,7 +115,7 @@ class ValidationViewModelImpl(
|
||||
}
|
||||
|
||||
override fun onNavigatedToLogin() {
|
||||
screenState.updateValue(ValidationScreenState.EMPTY)
|
||||
screenState.update { ValidationScreenState.EMPTY }
|
||||
isNeedToOpenLogin.update { false }
|
||||
}
|
||||
|
||||
@@ -132,7 +131,7 @@ class ValidationViewModelImpl(
|
||||
val sid = validationSid ?: return
|
||||
|
||||
authUseCase.validatePhone(sid)
|
||||
.listenValue { state ->
|
||||
.listenValue(viewModelScope) { state ->
|
||||
state.processState(
|
||||
error = { error ->
|
||||
|
||||
@@ -164,21 +163,13 @@ class ValidationViewModelImpl(
|
||||
delayJob = createTimerFlow(
|
||||
time = delay,
|
||||
onStartAction = {
|
||||
screenState.updateValue(
|
||||
screenState.value.copy(isSmsButtonVisible = false)
|
||||
)
|
||||
screenState.setValue { old -> old.copy(isSmsButtonVisible = false) }
|
||||
},
|
||||
onTickAction = { remainedTime ->
|
||||
screenState.updateValue(
|
||||
screenState.value.copy(delayTime = remainedTime)
|
||||
)
|
||||
screenState.setValue { old -> old.copy(delayTime = remainedTime) }
|
||||
},
|
||||
onTimeoutAction = {
|
||||
screenState.updateValue(
|
||||
screenState.value.copy(
|
||||
isSmsButtonVisible = true
|
||||
)
|
||||
)
|
||||
screenState.setValue { old -> old.copy(isSmsButtonVisible = true) }
|
||||
},
|
||||
).launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user