Kotlin

Building the chat interface

To be able to chat, you will need to create a new View for the chat interface. For simplicity we will add a new composable screen to display the chat UI, and a third composable to manage the switch between the two views.

In your MainActivity.kt add:

This is your basic chat application UI, with LazyColumn that will display the messages, a TextField to enter a message and a send Button to send the message.

Next lets create the Composable that will manage switching between the two UI views. Add the below Composable to your MainActivity.kt:

This will check the current state of the isLoggedIn flag, and display the correct UI, it will also display a Toast when an error is captured.

Finally update your MainActivity class to call the ApplicationSwitcher instead of the LoginScreen:

Build and Run

Run the project again to launch it in the simulator. If you log in with one of the users you will see the chat interface

Chat interface