Last active
August 20, 2022 15:58
-
-
Save attilakruchio/31ef0d7af9cf571b49cc81446054b89c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltViewModel | |
class EventViewModel @Inject constructor( | |
private val savedStateHandle: SavedStateHandle, | |
// ... | |
) : ViewModel() { | |
private val _selectedEventId = savedStateHandle.getStateFlow<Int?>( | |
KEY_SELECTED_EVENT_ID, null | |
) | |
private val _eventFilter = savedStateHandle.getStateFlow<EventFilter>( | |
KEY_EVENT_FILTER, EventFilter.ALL | |
) | |
// ... | |
fun setSelectedEventId(id: Int?) { | |
savedStateHandle[KEY_SELECTED_EVENT_ID] = id | |
} | |
fun setEventFilter(filter: EventFilter) { | |
savedStateHandle[KEY_EVENT_FILTER] = filter | |
} | |
companion object { | |
private const val KEY_SELECTED_EVENT_ID = "selected_event_id" | |
private const val KEY_EVENT_FILTER = "event_filter" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment