Skip to content

Instantly share code, notes, and snippets.

@CDRussell
Last active March 18, 2021 11:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CDRussell/0d9327996c90bb7fa8709c02e385731a to your computer and use it in GitHub Desktop.
Save CDRussell/0d9327996c90bb7fa8709c02e385731a to your computer and use it in GitHub Desktop.
viewModel.command.observe(this, Observer {
when (it) {
is BrowserViewModel.Command.Refresh -> webView.reload()
is BrowserViewModel.Command.Navigate -> webView.loadUrl(it.url)
is BrowserViewModel.Command.DialNumber -> {
val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:${it.telephoneNumber}")
launchExternalActivity(intent)
}
is BrowserViewModel.Command.SendEmail -> {
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse(it.emailAddress)
launchExternalActivity(intent)
}
is BrowserViewModel.Command.SendSms -> {
val intent = Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:${it.telephoneNumber}"))
startActivity(intent)
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment