StorageUsageViewModel

class StorageUsageViewModel(dispatchersProvider: DispatchersProvider, val getAllGalleryUseCase: GetAllGalleryUseCase, val deleteAllGalleryUseCase: DeleteAllGalleryUseCase, val getLocalOnnxModelsUseCase: GetLocalOnnxModelsUseCase, val getLocalMediaPipeModelsUseCase: GetLocalMediaPipeModelsUseCase, val getLocalSdxlModelsUseCase: GetLocalSdxlModelsUseCase, val getLocalCoreMlModelsUseCase: GetLocalCoreMlModelsUseCase, val getLocalBonsaiModelsUseCase: GetLocalBonsaiModelsUseCase, val deleteModelUseCase: DeleteModelUseCase, val storageUsageObserver: StorageUsageObserver, val buildInfoProvider: BuildInfoProvider, val router: StorageUsageRouter, val platformActions: StorageUsagePlatformActions, val onError: (Throwable) -> Unit = {}) : BaseMviViewModel<StorageUsageState, StorageUsageIntent, EmptyEffect> (source)

ViewModel for the standalone storage usage screen.

Storage usage is assembled from platform cache bytes, generated gallery payloads, and downloaded model directories. The ViewModel listens to StorageUsageObserver instead of lifecycle callbacks so Settings summaries and the standalone screen refresh from the same invalidation signal.

Author

Dmitriy Moroz

Parameters

dispatchersProvider

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

getAllGalleryUseCase

Reads generated gallery records whose payload strings are counted.

deleteAllGalleryUseCase

Deletes gallery records after explicit user confirmation.

getLocalOnnxModelsUseCase

Reads locally configured ONNX models.

getLocalMediaPipeModelsUseCase

Reads locally configured MediaPipe models.

getLocalSdxlModelsUseCase

Reads locally configured SDXL models.

getLocalCoreMlModelsUseCase

Reads locally configured Core ML models on supported builds.

deleteModelUseCase

Deletes downloaded local model metadata and files.

storageUsageObserver

Shared invalidation stream used by Settings and this screen.

buildInfoProvider

Build metadata used to filter platform-supported model categories.

router

Standalone route navigation contract.

platformActions

Filesystem bridge for cache and downloaded model byte accounting.

onError

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

Constructors

Link copied to clipboard
constructor(dispatchersProvider: DispatchersProvider, getAllGalleryUseCase: GetAllGalleryUseCase, deleteAllGalleryUseCase: DeleteAllGalleryUseCase, getLocalOnnxModelsUseCase: GetLocalOnnxModelsUseCase, getLocalMediaPipeModelsUseCase: GetLocalMediaPipeModelsUseCase, getLocalSdxlModelsUseCase: GetLocalSdxlModelsUseCase, getLocalCoreMlModelsUseCase: GetLocalCoreMlModelsUseCase, getLocalBonsaiModelsUseCase: GetLocalBonsaiModelsUseCase, deleteModelUseCase: DeleteModelUseCase, storageUsageObserver: StorageUsageObserver, buildInfoProvider: BuildInfoProvider, router: StorageUsageRouter, platformActions: StorageUsagePlatformActions, 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
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
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
Link copied to clipboard
open override val state: StateFlow<StorageUsageState>
Link copied to clipboard

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
private fun clearAll(categories: Set<UsageCategory>)
Link copied to clipboard
private fun clearCategory(category: UsageCategory)
Link copied to clipboard
private suspend fun clearCategoryInternal(category: UsageCategory)
Link copied to clipboard
protected fun emitEffect(effect: EmptyEffect)
Link copied to clipboard
protected fun emitState(state: StorageUsageState)
Link copied to clipboard
expect fun <T : AutoCloseable> getCloseable(key: String): T?
Link copied to clipboard
private suspend fun getCoreMlModelBytes(allowedModes: List<ServerSource>, modelIds: List<String>): Long

Reads Core ML model bytes from the entire platform model store on iOS-style targets.

Link copied to clipboard
private suspend fun getDownloadedModels(getModels: suspend () -> List<LocalAiModel>): List<LocalAiModel>
Link copied to clipboard
protected fun launch(dispatcher: CoroutineDispatcher, start: CoroutineStart, block: suspend CoroutineScope.() -> Unit): Job
Link copied to clipboard
private suspend fun loadStorageUsage(selectedCategory: UsageCategory?): UsageState
Link copied to clipboard
private fun observeStorageUsage()
Link copied to clipboard
protected expect open fun onCleared()
Link copied to clipboard
open override fun processIntent(intent: StorageUsageIntent)
Link copied to clipboard
private fun requestClearAll()
Link copied to clipboard
private fun requestClearCategory(category: UsageCategory)
Link copied to clipboard
private fun selectCategory(category: UsageCategory)
Link copied to clipboard

Returns true when Core ML is the only local model provider exposed by this platform.

Link copied to clipboard
protected fun updateState(mutation: (StorageUsageState) -> StorageUsageState)