Skip to content

Instantly share code, notes, and snippets.

@fergusonm
Created January 26, 2021 23:03
Show Gist options
  • Save fergusonm/091851d1b2227fa69e578e2c4e782280 to your computer and use it in GitHub Desktop.
Save fergusonm/091851d1b2227fa69e578e2c4e782280 to your computer and use it in GitHub Desktop.
class MainViewModel : ViewModel() {
sealed class Event {
object NavigateToSettings: Event()
data class ShowSnackBar(val text: String): Event()
data class ShowToast(val text: String): Event()
}
private val eventChannel = Channel<Event>(Channel.BUFFERED)
val eventsFlow = eventChannel.receiveAsFlow()
init {
viewModelScope.launch {
eventChannel.send(Event.ShowSnackBar("Sample"))
eventChannel.send(Event.ShowToast("Toast"))
}
}
fun settingsButtonClicked() {
viewModelScope.launch {
eventChannel.send(Event.NavigateToSettings)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment