Kotlin

Building the log in interface

To be able to log in, you will need to add three elements to the screen:

  • A Button to log in Alice
  • A Button to log in Bob

Open MainActivity.kt and add it programmatically:


class MainActivity : ComponentActivity() {
    private val chatState by viewModels<ChatViewModel>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            LoginScreen()
        }
    }
}

@Composable
fun LoginScreen() {
    val vm = LocalChatState.current
    Column(
        modifier = Modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        Button(onClick = { }) {
            Text("Login as Alice")
        }
        Button(onClick = { }) {
            Text("Login as Bob")
        }
    }
}


Build and Run

Run the project again to launch it in the simulator.

Login interface