NetworkMockViewModel

class NetworkMockViewModel(configRepository: MockConfigRepository, stateRepository: MockStateRepository) : ViewModel

ViewModel for the Network Mock screen.

This ViewModel manages the state and business logic for the network mocking UI, combining data from configuration files and persisted state to provide a complete view of available mocks and their current settings.

Responsibilities

  • Load mock configuration from resources

  • Observe persisted mock state from DataStore

  • Combine config and state into UI-friendly models

  • Handle user actions (toggle mocking, select responses)

  • Manage loading and error states

State Flow

The ViewModel exposes a single uiState flow that combines:

  • Mock configuration (from JSON file)

  • Runtime state (from DataStore)

  • Discovered response files (from resources)

Constructors

Link copied to clipboard
constructor(configRepository: MockConfigRepository, stateRepository: MockStateRepository)

Properties

Link copied to clipboard
val uiState: StateFlow<NetworkMockUiState>

Combined UI state for the Network Mock screen.

Functions

Link copied to clipboard
expect open fun addCloseable(closeable: AutoCloseable)
expect fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
expect fun <T : AutoCloseable> getCloseable(key: String): T?
Link copied to clipboard

Resets all endpoint mocks to use actual network.

Link copied to clipboard
fun setEndpointMockState(key: EndpointKey, responseFileName: String?)

Sets the mock state for a specific endpoint identified by an EndpointKey.

Link copied to clipboard

Toggles global mocking on/off.