Created
January 26, 2021 23:03
-
-
Save fergusonm/091851d1b2227fa69e578e2c4e782280 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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