Skip to content

Commit

Permalink
pulled up the latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsec13 committed May 13, 2024
2 parents e3b2a8a + 80646a8 commit ebad3ca
Show file tree
Hide file tree
Showing 34 changed files with 1,291 additions and 148 deletions.
9 changes: 9 additions & 0 deletions app/src/main/java/app/cashadvisor/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package app.cashadvisor

import android.app.Application
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
import com.google.firebase.crashlytics.FirebaseCrashlytics
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber
Expand All @@ -11,6 +13,7 @@ class App : Application() {

override fun onCreate() {
super.onCreate()
setRussianLocale()
configureTimber()
}

Expand Down Expand Up @@ -55,6 +58,12 @@ class App : Application() {
})
}

private fun setRussianLocale() {
val appLocale: LocaleListCompat =
LocaleListCompat.forLanguageTags("ru")
AppCompatDelegate.setApplicationLocales(appLocale)
}

companion object {
private const val DEBUG = "DEBUG"
private const val RELEASE = "RELEASE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import app.cashadvisor.common.utill.exceptions.LoginException
import app.cashadvisor.common.utill.exceptions.NetworkException
import kotlinx.serialization.json.Json
import javax.inject.Inject
import kotlin.time.Duration.Companion.nanoseconds

class NetworkToLoginExceptionMapper @Inject constructor(
private val json: Json
Expand Down Expand Up @@ -57,7 +58,7 @@ class NetworkToLoginExceptionMapper @Inject constructor(
handleErrorResponse<ErrorWrongConfirmationCodeResponse>(exception.errorBody)
LoginException.LoginCodeConfirmation.UnauthorizedWrongConfirmationCode(
remainingAttempts = errorResponse.remainingAttempts,
lockDuration = errorResponse.lockDuration,
lockDuration = errorResponse.lockDurationNanoseconds.nanoseconds.inWholeMinutes,
message = errorResponse.error,
statusCode = errorResponse.statusCode
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import app.cashadvisor.common.utill.exceptions.NetworkException
import app.cashadvisor.common.utill.exceptions.RegisterException
import kotlinx.serialization.json.Json
import javax.inject.Inject
import kotlin.time.Duration.Companion.nanoseconds

class NetworkToRegisterExceptionMapper @Inject constructor(
private val json: Json
Expand Down Expand Up @@ -49,7 +50,7 @@ class NetworkToRegisterExceptionMapper @Inject constructor(
handleErrorResponse<ErrorWrongConfirmationCodeResponse>(exception.errorBody)
RegisterException.EmailCodeConfirmation.UnauthorizedWrongConfirmationCode(
remainingAttempts = errorResponse.remainingAttempts,
lockDuration = errorResponse.lockDuration,
lockDuration = errorResponse.lockDurationNanoseconds.nanoseconds.inWholeMinutes,
message = errorResponse.error,
statusCode = errorResponse.statusCode
)
Expand All @@ -69,9 +70,9 @@ class NetworkToRegisterExceptionMapper @Inject constructor(

private fun handleCommonException(exception: NetworkException): RegisterException {
return when (exception) {

is NetworkException.NoInternetConnection -> {
val errorResponse = handleErrorResponse<ErrorResponse>(exception.errorBody)
RegisterException.NoConnection(errorResponse.message)
RegisterException.NoConnection(exception.errorBody)
}

is NetworkException.Undefined -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class ErrorWrongConfirmationCodeResponse(
@SerialName("remaining_attempts") val remainingAttempts: Int,
@SerialName("lock_duration") val lockDuration: Long,
@SerialName("lock_duration") val lockDurationNanoseconds: Long,
val error: String,
@SerialName("status_code") val statusCode: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,36 @@ class InputValidationInteractorImpl @Inject constructor() : InputValidationInter
val isEmailValid = isValidText(email.trimStart().trimEnd(), REGEX_PATTERN_EMAIL)
return if (isEmailValid) {
EmailValidationState.Success(Email(value = email))
} else EmailValidationState.Error(
} else EmailValidationState.Error(
email = Email(EMPTY_VALUE),
emailValidationError = EmailValidationError.EMAIL_NOT_VALID
)
}

override suspend fun validatePassword(password: String): PasswordValidationState {
if (password.length < 8) {
return PasswordValidationState.Error(
password = Password(EMPTY_VALUE),
passwordValidationError = PasswordValidationError.PASSWORD_IS_NOT_LONG_ENOUGH
)
}

// if (password.length in 31..7) {
// return PasswordValidationState.Error(
// //password = Password(EMPTY_VALUE),
// passwordValidationError = PasswordValidationError.PASSWORD_IS_NOT_LONG_ENOUGH
// )
// }

val isPasswordValid = isValidText(password.trimStart().trimEnd(), REGEX_PATTERN_PASSWORD)
return if (isPasswordValid) {
PasswordValidationState.Success(Password(value = password))
} else PasswordValidationState.Error(
password = Password(EMPTY_VALUE),
//val isPasswordLengthValid: Boolean = isValidText(password.trimStart().trimEnd(), REGEX_PATTERN_LENGTH_PASSWORD)

return if (!isPasswordValid)
PasswordValidationState.Error(
//password = Password(EMPTY_VALUE),
passwordValidationError = PasswordValidationError.PASSWORD_NOT_VALID
)

else if (password.length !in 8 .. 30){
PasswordValidationState.Error(
//password = Password(EMPTY_VALUE),
passwordValidationError = PasswordValidationError.PASSWORD_IS_NOT_LONG_ENOUGH)
}
else PasswordValidationState.Success(Password(value = password))
}

override suspend fun validateConfirmationCode(code: String): ConfirmCodeValidationState {
Expand All @@ -63,7 +73,8 @@ class InputValidationInteractorImpl @Inject constructor() : InputValidationInter
companion object {
const val REGEX_PATTERN_EMAIL =
"""^(?=(?:(?!.*[_.-]{2,})(?!.*[_.-]$)(?!^[-_.])[a-zA-Z0-9._-]{1,49}[a-zA-Z0-9]@(?!-)[a-zA-Z0-9-]{1,63}(\.[a-zA-Z]{2,})+)$)(?=(?:.{7,114})$).*"""
const val REGEX_PATTERN_PASSWORD = """^[a-zA-Z0-9_]{8,30}$"""
const val REGEX_PATTERN_PASSWORD = """^[a-zA-Z0-9_]*$"""
const val REGEX_PATTERN_LENGTH_PASSWORD = """^{8,30}$"""
const val REGEX_PATTERN_CODE = """^[0-9]{4}$"""
const val EMPTY_VALUE = ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ sealed interface EmailValidationState {
val email: Email,
val emailValidationError: EmailValidationError
) : EmailValidationState
data object Default: EmailValidationState
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import app.cashadvisor.authorization.domain.models.PasswordValidationError
sealed interface PasswordValidationState {
data class Success(val password: Password) : PasswordValidationState
data class Error(
val password: Password,
//val password: Password,
val passwordValidationError: PasswordValidationError
) : PasswordValidationState
data object Default : PasswordValidationState
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
import app.cashadvisor.authorization.domain.models.states.EmailValidationState
import app.cashadvisor.authorization.domain.models.states.PasswordValidationState
import app.cashadvisor.authorization.presentation.ui.models.LoginScreenSideEffects
import app.cashadvisor.authorization.presentation.ui.models.LoginScreenMessageContent
import app.cashadvisor.authorization.presentation.ui.models.LoginScreenSideEffects
import app.cashadvisor.authorization.presentation.viewmodel.LoginViewModel
import app.cashadvisor.authorization.presentation.viewmodel.models.LoginEmailValidationState
import app.cashadvisor.authorization.presentation.viewmodel.models.LoginPasswordValidationState
import app.cashadvisor.authorization.presentation.viewmodel.models.LoginScreenState
import app.cashadvisor.common.ui.BaseFragment
import app.cashadvisor.databinding.FragmentLoginBinding
Expand Down Expand Up @@ -173,43 +173,43 @@ class LoginFragment :
}
}

private fun manageEmailValidation(state: EmailValidationState?) {
private fun manageEmailValidation(state: LoginEmailValidationState?) {
state?.let {
with(binding) {
when (state) {
is EmailValidationState.Error -> {
is LoginEmailValidationState.Error -> {
showErrorEditText(etEmailInput)
}

is EmailValidationState.Success -> {
is LoginEmailValidationState.Success -> {
showSuccessEditText(etEmailInput)
}

EmailValidationState.Default -> {
LoginEmailValidationState.Default -> {
showNeutralEditText(etEmailInput)
}
}
}
}
}

private fun managePasswordValidation(state: PasswordValidationState?) {
private fun managePasswordValidation(state: LoginPasswordValidationState?) {
state?.let {
with(binding) {
when (state) {
is PasswordValidationState.Error -> {
is LoginPasswordValidationState.Error -> {
showErrorEditText(etPasswordInput)
tiPasswordInput.isHelperTextEnabled = true
tiPasswordInput.helperText =
getString(R.string.password_text_input_helper_text)
}

is PasswordValidationState.Success -> {
is LoginPasswordValidationState.Success -> {
showSuccessEditText(etPasswordInput)
tiPasswordInput.isHelperTextEnabled = false
}

PasswordValidationState.Default -> {
LoginPasswordValidationState.Default -> {
showNeutralEditText(etPasswordInput)
tiPasswordInput.isHelperTextEnabled = false
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TestViewModel @Inject constructor(
private fun setEmail(email: String) {
viewModelScope.launch {
val result = inputValidationInteractor.validateEmail(email)

when (result) {
is EmailValidationState.Success -> {
_state.update {
Expand All @@ -87,10 +88,6 @@ class TestViewModel @Inject constructor(
it.copy(email = result.email, isEmailValid = false)
}
}

EmailValidationState.Default -> {

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class EntryViewModel @Inject constructor() : BaseViewModel() {
private var _state = MutableStateFlow<EntryScreenState>(EntryScreenState.Default)
val state: StateFlow<EntryScreenState>
get() = _state

private var coolDownDebounce: ((Unit) -> Unit) = debounce(
COOL_DOWN_DELAY,
viewModelScope
Expand Down
Loading

0 comments on commit ebad3ca

Please sign in to comment.