Skip to content

Instantly share code, notes, and snippets.

@samiuelson
Last active May 6, 2020 14:15
Show Gist options
  • Save samiuelson/908330d2d1a37edcfd6cbafc39167650 to your computer and use it in GitHub Desktop.
Save samiuelson/908330d2d1a37edcfd6cbafc39167650 to your computer and use it in GitHub Desktop.
class LiveStreamActivity : AppCompatActivity(R.layout.activity_main) {
private val adapter = MessagesListAdapter()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
loadMockVideoStream()
messagesList.adapter = adapter
val viewModel: LiveStreamViewModel by viewModels()
viewModel.viewState.observe(this, Observer {
when (it) {
is State.Messages -> updateMessagesList(it.messages)
is State.NewMessage -> updateMessagesList(adapter.currentList + it.message)
is State.Error -> showToast(it.message)
}
})
sendMessageButton.setOnClickListener {
viewModel.sendButtonClicked(messageInput.text.toString())
messageInput.setText("")
messageInput.clearFocus()
messageInput.hideKeyboard()
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment