ItemViewModel

class ItemViewModel @AssistedInject constructor(homeRepository: HomeRepository, @Assisted existingJetpackId: String?) : ViewModel

ViewModel for the create/edit item screen, managing Jetpack library creation and updates.

This ViewModel handles both creating new Jetpack items and editing existing ones. The optional item ID arrives by assisted injection from the navigation key. If an ID is present, the screen operates in edit mode; otherwise, it creates a new item with a generated UUID.

The ViewModel demonstrates:

  • Navigation argument handling by assisted injection from a Navigation 3 key

  • Form state management with updateState for field updates

  • Navigation events using OneTimeEvent to trigger back navigation after save

  • Async operations with updateStateWith for create/update operations

Parameters

homeRepository

Repository providing Jetpack data operations.

existingJetpackId

The item to edit, or null to create a new one.

See also

Immutable data class representing form state

State wrapper with loading and error handling

Extension function for synchronous state updates

Extension function for async operations with state updates

Ensures navigation events are consumed only once

Data layer interface for home screen operations

Constructors

Link copied to clipboard
@AssistedInject
constructor(homeRepository: HomeRepository, @Assisted existingJetpackId: String?)

Types

Link copied to clipboard
@AssistedFactory
interface Factory

Creates an ItemViewModel for a given item.

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun updateName(name: String)
Link copied to clipboard
fun updatePrice(priceString: String)