Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.