Last active
May 6, 2020 14:15
-
-
Save samiuelson/908330d2d1a37edcfd6cbafc39167650 to your computer and use it in GitHub Desktop.
This file contains 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 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