Package-level declarations

Types

Link copied to clipboard

Derived, UI-friendly summary of the device connection state. Combines ServiceRepository.connectionState with "region unset" to surface the MUST_SET_REGION case that otherwise needs a separate boolean flag in the UI layer.

Link copied to clipboard
class ConnectionsViewModel(radioConfigRepository: RadioConfigRepository, serviceRepository: ServiceRepository, nodeRepository: NodeRepository, uiPrefs: UiPrefs) : ViewModel
Link copied to clipboard
sealed interface UiState<out T>

Lightweight tri-state wrapper for UI data. Prefer this over bare nullable initial values when the UI needs to distinguish "still loading" from "genuinely empty."

Link copied to clipboard
class UIViewModel(nodeDB: NodeRepository, serviceRepository: ServiceRepository, radioController: RadioController, radioInterfaceService: RadioInterfaceService, meshLogRepository: MeshLogRepository, firmwareReleaseRepository: FirmwareReleaseRepository, uiPrefs: UiPrefs, notificationManager: NotificationManager, packetRepository: PacketRepository, val alertManager: AlertManager, val snackbarManager: SnackbarManager) : ViewModel

Shared base for the application-level ViewModel.

Functions

Link copied to clipboard
context(viewModel: ViewModel)
fun <T> Flow<T>.asUiState(stopTimeout: Duration = 5.seconds): StateFlow<UiState<T>>

Wraps this Flow into a StateFlow<UiState<T>>, emitting UiState.Loading until the first value, then UiState.Content for each emission. Upstream errors are caught and mapped to UiState.Error.

Link copied to clipboard
fun <T> UiState<T>.dataOrNull(): T?

Returns the Content data, or null if this state is Loading or Error.

Link copied to clipboard
fun errorEventFlow(): MutableSharedFlow<UiText>

Creates and returns a MutableSharedFlow intended for one-shot error events. Expose as SharedFlow via asSharedFlow in the ViewModel, and collect in the UI to show snackbars or toasts.

Link copied to clipboard
context(viewModel: ViewModel)
fun safeLaunch(context: CoroutineContext = EmptyCoroutineContext, errorEvents: MutableSharedFlow<UiText>? = null, tag: String? = null, block: suspend CoroutineScope.() -> Unit): Job

Launches a coroutine in viewModelScope that catches all exceptions except CancellationException. Non-cancellation errors are logged and emitted to errorEvents (if provided) for one-shot UI consumption (e.g. snackbar / toast).

Link copied to clipboard
context(viewModel: ViewModel)
fun <T> Flow<T>.stateInWhileSubscribed(initialValue: T, stopTimeout: Duration = 5.seconds): StateFlow<T>

Extension for converting a Flow to a StateFlow in a ViewModel context.