Files
forkmessager/client-mobile/core/presentation/settings/SettingsViewModel.kt
Халимов Рустам 1fb1be47dd Приложение
2026-04-14 01:15:54 +03:00

42 lines
1.1 KiB
Kotlin

package core.presentation.settings
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import core.domain.model.ServerConfigModel
import core.network.ServerConfig
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import javax.inject.Inject
data class SettingsState(
val baseUrl: String = "",
val config: ServerConfigModel = ServerConfigModel()
)
@HiltViewModel
class SettingsViewModel @Inject constructor(
private val serverConfig: ServerConfig
) : ViewModel() {
private val _state = MutableStateFlow(SettingsState())
val state: StateFlow<SettingsState> = _state.asStateFlow()
init {
_state.update {
it.copy(
baseUrl = serverConfig.getBaseUrl(),
config = serverConfig.getServerConfig()
)
}
}
fun saveBaseUrl(url: String) {
serverConfig.setBaseUrl(url)
_state.update { it.copy(baseUrl = url) }
}
}