NetworkUsageViewModel

class NetworkUsageViewModel(dispatchersProvider: DispatchersProvider, val observeNetworkUsageUseCase: ObserveNetworkUsageUseCase, val resetNetworkUsageUseCase: ResetNetworkUsageUseCase, val router: NetworkUsageRouter, val onError: (Throwable) -> Unit = {}) : BaseMviViewModel<NetworkUsageState, NetworkUsageIntent, EmptyEffect> (source)

ViewModel for the standalone network usage screen.

It subscribes to persisted traffic counters through ObserveNetworkUsageUseCase so the screen updates when Ktor calls or model downloads report bytes. Resetting statistics clears Room data and briefly switches to the shimmer state while the new zero snapshot is emitted.

Author

Dmitriy Moroz

Parameters

dispatchersProvider

App coroutine dispatchers used by the MVI base class and IO work.

observeNetworkUsageUseCase

Live Room-backed traffic counter stream.

resetNetworkUsageUseCase

Use case that clears all persisted network counters.

router

Standalone route navigation contract.

onError

Error callback forwarded to the app-level error handling pipeline.

Constructors

Link copied to clipboard
constructor(dispatchersProvider: DispatchersProvider, observeNetworkUsageUseCase: ObserveNetworkUsageUseCase, resetNetworkUsageUseCase: ResetNetworkUsageUseCase, router: NetworkUsageRouter, onError: (Throwable) -> Unit = {})

Properties

Link copied to clipboard
private val _effect: Channel<E>
Link copied to clipboard
private val _state: MutableStateFlow<S>
Link copied to clipboard
Link copied to clipboard
open override val effect: Flow<EmptyEffect>
Link copied to clipboard
private val effectDispatcher: CoroutineDispatcher
Link copied to clipboard
private val ioDispatcher: CoroutineDispatcher
Link copied to clipboard
private val onError: (Throwable) -> Unit
Link copied to clipboard
Link copied to clipboard
open override val state: StateFlow<NetworkUsageState>

Functions

Link copied to clipboard
expect open fun addCloseable(closeable: AutoCloseable)
expect fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
internal expect fun clear()
Link copied to clipboard
protected fun emitEffect(effect: EmptyEffect)
Link copied to clipboard
protected fun emitState(state: NetworkUsageState)
Link copied to clipboard
expect fun <T : AutoCloseable> getCloseable(key: String): T?
Link copied to clipboard
protected fun launch(dispatcher: CoroutineDispatcher, start: CoroutineStart, block: suspend CoroutineScope.() -> Unit): Job
Link copied to clipboard
private fun observeNetworkUsage()
Link copied to clipboard
protected expect open fun onCleared()
Link copied to clipboard
open override fun processIntent(intent: NetworkUsageIntent)
Link copied to clipboard
private fun resetStatistics()
Link copied to clipboard
private fun selectCategory(category: UsageCategory)
Link copied to clipboard
protected fun updateState(mutation: (NetworkUsageState) -> NetworkUsageState)