diff --git a/android/app/src/main/java/ru/daemonlord/messenger/ui/auth/AuthViewModel.kt b/android/app/src/main/java/ru/daemonlord/messenger/ui/auth/AuthViewModel.kt
index bc75d91..34a80fe 100644
--- a/android/app/src/main/java/ru/daemonlord/messenger/ui/auth/AuthViewModel.kt
+++ b/android/app/src/main/java/ru/daemonlord/messenger/ui/auth/AuthViewModel.kt
@@ -1,7 +1,9 @@
package ru.daemonlord.messenger.ui.auth
+import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
+import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@@ -15,6 +17,7 @@ import ru.daemonlord.messenger.domain.auth.usecase.RegisterUseCase
import ru.daemonlord.messenger.domain.auth.usecase.RestoreSessionUseCase
import ru.daemonlord.messenger.domain.common.AppError
import ru.daemonlord.messenger.domain.common.AppResult
+import ru.daemonlord.messenger.R
import javax.inject.Inject
@HiltViewModel
@@ -24,6 +27,7 @@ class AuthViewModel @Inject constructor(
private val registerUseCase: RegisterUseCase,
private val loginUseCase: LoginUseCase,
private val logoutUseCase: LogoutUseCase,
+ @ApplicationContext private val context: Context,
) : ViewModel() {
private val _uiState = MutableStateFlow(AuthUiState())
@@ -95,7 +99,7 @@ class AuthViewModel @Inject constructor(
fun continueWithEmail() {
val email = uiState.value.email.trim().lowercase()
if (email.isBlank()) {
- _uiState.update { it.copy(errorMessage = "Enter email.") }
+ _uiState.update { it.copy(errorMessage = context.getString(R.string.auth_error_enter_email)) }
return
}
viewModelScope.launch {
@@ -114,7 +118,11 @@ class AuthViewModel @Inject constructor(
isLoading = false,
step = if (result.data.registered) AuthStep.PASSWORD else AuthStep.REGISTER,
errorMessage = null,
- successMessage = if (result.data.registered) null else "This email is not registered. Complete sign up.",
+ successMessage = if (result.data.registered) {
+ null
+ } else {
+ context.getString(R.string.auth_info_email_not_registered)
+ },
)
}
}
@@ -143,7 +151,7 @@ class AuthViewModel @Inject constructor(
private fun register() {
val state = uiState.value
if (state.name.isBlank() || state.username.isBlank() || state.password.isBlank()) {
- _uiState.update { it.copy(errorMessage = "Name, username and password are required.") }
+ _uiState.update { it.copy(errorMessage = context.getString(R.string.auth_error_register_fields_required)) }
return
}
viewModelScope.launch {
@@ -161,7 +169,7 @@ class AuthViewModel @Inject constructor(
it.copy(
isLoading = false,
step = AuthStep.PASSWORD,
- successMessage = "Account created. Use password to sign in.",
+ successMessage = context.getString(R.string.auth_info_account_created),
errorMessage = null,
)
}
@@ -182,7 +190,7 @@ class AuthViewModel @Inject constructor(
private fun loginWithoutOtp() {
val state = uiState.value
if (state.password.isBlank()) {
- _uiState.update { it.copy(errorMessage = "Password is required.") }
+ _uiState.update { it.copy(errorMessage = context.getString(R.string.auth_error_password_required)) }
return
}
viewModelScope.launch {
@@ -209,7 +217,7 @@ class AuthViewModel @Inject constructor(
isLoading = false,
step = AuthStep.OTP,
errorMessage = null,
- successMessage = "Enter 2FA code or recovery code.",
+ successMessage = context.getString(R.string.auth_info_enter_2fa_or_recovery),
)
}
} else {
@@ -232,11 +240,11 @@ class AuthViewModel @Inject constructor(
val otpCode = state.otpCode.trim().ifBlank { null }
val recoveryCode = state.recoveryCode.trim().ifBlank { null }
if (!state.useRecoveryCode && otpCode.isNullOrBlank()) {
- _uiState.update { it.copy(errorMessage = "Enter 2FA code.") }
+ _uiState.update { it.copy(errorMessage = context.getString(R.string.auth_error_enter_2fa_code)) }
return
}
if (state.useRecoveryCode && recoveryCode.isNullOrBlank()) {
- _uiState.update { it.copy(errorMessage = "Enter recovery code.") }
+ _uiState.update { it.copy(errorMessage = context.getString(R.string.auth_error_enter_recovery_code)) }
return
}
viewModelScope.launch {
@@ -348,11 +356,11 @@ class AuthViewModel @Inject constructor(
private fun AppError.toUiMessage(): String {
return when (this) {
- AppError.InvalidCredentials -> "Invalid email or password."
- AppError.Network -> "Network error. Check your connection."
- AppError.Unauthorized -> "Session expired. Please sign in again."
- is AppError.Server -> message ?: "Server error. Please try again."
- is AppError.Unknown -> "Unknown error. Please try again."
+ AppError.InvalidCredentials -> context.getString(R.string.auth_error_invalid_credentials)
+ AppError.Network -> context.getString(R.string.auth_error_network)
+ AppError.Unauthorized -> context.getString(R.string.auth_error_session_expired)
+ is AppError.Server -> message ?: context.getString(R.string.auth_error_server)
+ is AppError.Unknown -> context.getString(R.string.auth_error_unknown)
}
}
}
diff --git a/android/app/src/main/res/values-ru/strings.xml b/android/app/src/main/res/values-ru/strings.xml
index 0e77e54..98961d4 100644
--- a/android/app/src/main/res/values-ru/strings.xml
+++ b/android/app/src/main/res/values-ru/strings.xml
@@ -232,6 +232,19 @@
Отправить ссылку сброса
Новый пароль
Сбросить по токену
+ Введите email.
+ Этот email не зарегистрирован. Завершите регистрацию.
+ Нужны имя, имя пользователя и пароль.
+ Аккаунт создан. Используйте пароль для входа.
+ Требуется пароль.
+ Введите код 2FA или код восстановления.
+ Введите код 2FA.
+ Введите код восстановления.
+ Неверный email или пароль.
+ Ошибка сети. Проверьте подключение.
+ Сессия истекла. Войдите снова.
+ Ошибка сервера. Попробуйте снова.
+ Неизвестная ошибка. Попробуйте снова.
Контакты
Поиск контактов/пользователей
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index 0da8c0a..07e506f 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -232,6 +232,19 @@
Send reset link
New password
Reset with token
+ Enter email.
+ This email is not registered. Complete sign up.
+ Name, username and password are required.
+ Account created. Use password to sign in.
+ Password is required.
+ Enter 2FA code or recovery code.
+ Enter 2FA code.
+ Enter recovery code.
+ Invalid email or password.
+ Network error. Check your connection.
+ Session expired. Please sign in again.
+ Server error. Please try again.
+ Unknown error. Please try again.
Contacts
Search contacts/users