Skip to content

Commit

Permalink
fix: LTAND-221: fix animation (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
migulyaev authored Dec 29, 2023
1 parent 29ded30 commit 7e175f9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.util.Log
import androidx.annotation.StringRes
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -70,40 +71,43 @@ class RegistrationViewModel @Inject constructor(
return
}
viewModelScope.launch(dispatchers.IO) {
_uiState.update {
it.copy(
isSendingMessage = true,
)
}
updateIsSendingMessage(true)
try {
registrationRepository.createNewAccount(
requestedUserName = uiState.value.username,
domainName = uiState.value.domain,
locale = domainProvider.getDomainLocale(),
)
delay(2000L)
updateIsSendingMessage(false)
} catch (e: GatewayUnregisteredException) {
logger.e(AwalaManagerImpl.TAG, "Failed to register endpoint", e)
_showOpenAwalaSnackbar.emit(Unit)
updateIsSendingMessage(false)
} catch (e: AwaladroidException) {
Log.w(TAG, e)
showSnackbarDebounced.emit(
SnackbarString(SnackbarStringsProvider.Type.SEND_MESSAGE_ERROR),
)
updateIsSendingMessage(false)
} catch (e: DuplicateAccountIdException) {
Log.w(TAG, e)
showSnackbarDebounced.emit(
SnackbarString(SnackbarStringsProvider.Type.ACCOUNT_LINKING_ID_ALREADY_EXISTS),
)
} finally {
_uiState.update {
it.copy(
isSendingMessage = false,
)
}
updateIsSendingMessage(false)
}
}
}

private fun updateIsSendingMessage(isSendingMessage: Boolean) {
_uiState.update {
it.copy(
isSendingMessage = isSendingMessage,
)
}
}

private fun isCreateAccountButtonEnabled(
isValidText: Boolean,
username: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tech.relaycorp.letro.account.registration
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
Expand Down Expand Up @@ -92,22 +93,27 @@ class UseExistingAccountViewModel @Inject constructor(
}
viewModelScope.launch(dispatchers.IO) {
try {
_uiState.update { it.copy(isSendingMessage = true) }
updateIsSendingMessage(true)
registrationRepository.loginToExistingAccount(
uiState.value.domain,
uiState.value.awalaEndpoint,
uiState.value.token,
)
delay(2000L)
updateIsSendingMessage(false)
} catch (e: AwaladroidException) {
showSnackbarDebounced.emit(
SnackbarString(SnackbarStringsProvider.Type.SEND_MESSAGE_ERROR),
)
updateIsSendingMessage(false)
} catch (e: DuplicateAccountIdException) {
showSnackbarDebounced.emit(
SnackbarString(SnackbarStringsProvider.Type.ACCOUNT_LINKING_ID_ALREADY_EXISTS, args = arrayOf(_uiState.value.domain)),
SnackbarString(
SnackbarStringsProvider.Type.ACCOUNT_LINKING_ID_ALREADY_EXISTS,
args = arrayOf(_uiState.value.domain),
),
)
} finally {
_uiState.update { it.copy(isSendingMessage = false) }
updateIsSendingMessage(false)
}
}
}
Expand All @@ -119,6 +125,14 @@ class UseExistingAccountViewModel @Inject constructor(
) = token.isNotEmptyOrBlank() && domain.isNotEmptyOrBlank() && domain.matches(CorrectDomainRegex) && (
endpoint.isEmpty() || endpoint.isNotEmptyOrBlank() && endpoint.matches(CorrectDomainRegex)
)

private fun updateIsSendingMessage(isSendingMessage: Boolean) {
_uiState.update {
it.copy(
isSendingMessage = isSendingMessage,
)
}
}
}

data class UseExistingAccountUiState(
Expand Down

0 comments on commit 7e175f9

Please sign in to comment.