refactoring logger

This commit is contained in:
Shcherbatykh Oleg
2026-02-19 14:20:13 +03:00
parent 6aa4b6d39d
commit 6a45abf297
5 changed files with 36 additions and 41 deletions

View File

@@ -12,7 +12,6 @@ fun SplashRoute(
viewModel: SplashViewModel = hiltViewModel()
) {
val state = viewModel.state.collectAsStateWithLifecycle().value
LaunchedEffect(Unit) {
viewModel.effects.collect { effect ->
when (effect) {
@@ -20,6 +19,5 @@ fun SplashRoute(
}
}
}
SplashScreen(state = state)
}

View File

@@ -7,40 +7,38 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import ru.fincode.tsudesk.core.common.model.DataResult
import ru.fincode.tsudesk.core.config.domain.usecase.GetConfigUseCase
import ru.fincode.tsudesk.feature.splash.presentation.model.SplashUiState
import ru.fincode.tsudesk.feature.splash.presentation.model.SplashEffect
import ru.fincode.tsudesk.feature.splash.presentation.model.SplashUiState
import javax.inject.Inject
@HiltViewModel
class SplashViewModel @Inject constructor(
private val getConfigUseCase: GetConfigUseCase
) : ViewModel() {
private val _state = MutableStateFlow(SplashUiState(isLoading = true))
val state: StateFlow<SplashUiState> = _state
private val _effects = MutableSharedFlow<SplashEffect>(extraBufferCapacity = 1)
val effects: SharedFlow<SplashEffect> = _effects
val state: StateFlow<SplashUiState> = _state.asStateFlow()
val effects: SharedFlow<SplashEffect> = _effects.asSharedFlow()
init {
viewModelScope.launch {
when (val result = getConfigUseCase()) {
is DataResult.Data -> {
_state.value = SplashUiState(isLoading = false)
_effects.tryEmit(SplashEffect.OpenMain)
}
is DataResult.Error -> {
_state.value = SplashUiState(
isLoading = false,
errorMessage = result.error.toString()
)
_effects.tryEmit(SplashEffect.OpenMain)
}
val errorMessage = when (val result = getConfigUseCase()) {
is DataResult.Data -> null
is DataResult.Error -> result.error.toString()
}
_state.update {
it.copy(
isLoading = false,
errorMessage = errorMessage
)
}
_effects.tryEmit(SplashEffect.OpenMain)
}
}
}