From 02d3fac1dba9e74bf2ea87dc8a62f17182e35cc5 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 20 Nov 2023 03:33:11 +0100 Subject: [PATCH] Start work on building the LoginActivity --- .../java/eu/steffo/twom/ui/BASE_PADDING.kt | 8 ++ .../ui/homeserver/SelectHomeserverControl.kt | 11 ++- .../eu/steffo/twom/ui/login/LoginActivity.kt | 24 +----- .../twom/ui/login/LoginActivityControl.kt | 73 +++++++++++++++++++ .../twom/ui/login/LoginActivityScaffold.kt | 53 ++++++++++++++ app/src/main/res/values/strings.xml | 7 ++ 6 files changed, 150 insertions(+), 26 deletions(-) create mode 100644 app/src/main/java/eu/steffo/twom/ui/BASE_PADDING.kt create mode 100644 app/src/main/java/eu/steffo/twom/ui/login/LoginActivityControl.kt create mode 100644 app/src/main/java/eu/steffo/twom/ui/login/LoginActivityScaffold.kt diff --git a/app/src/main/java/eu/steffo/twom/ui/BASE_PADDING.kt b/app/src/main/java/eu/steffo/twom/ui/BASE_PADDING.kt new file mode 100644 index 0000000..55155d3 --- /dev/null +++ b/app/src/main/java/eu/steffo/twom/ui/BASE_PADDING.kt @@ -0,0 +1,8 @@ +package eu.steffo.twom.ui + +import androidx.compose.foundation.layout.padding +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp + + +val BASE_PADDING = Modifier.padding(all = 10.dp) diff --git a/app/src/main/java/eu/steffo/twom/ui/homeserver/SelectHomeserverControl.kt b/app/src/main/java/eu/steffo/twom/ui/homeserver/SelectHomeserverControl.kt index 6d6ad7a..1bf02e7 100644 --- a/app/src/main/java/eu/steffo/twom/ui/homeserver/SelectHomeserverControl.kt +++ b/app/src/main/java/eu/steffo/twom/ui/homeserver/SelectHomeserverControl.kt @@ -20,6 +20,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import eu.steffo.twom.R import eu.steffo.twom.matrix.TwoMMatrix +import eu.steffo.twom.ui.BASE_PADDING import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig @@ -36,13 +37,11 @@ fun SelectHomeserverControl( var homeserver by rememberSaveable { mutableStateOf("") } var state by rememberSaveable { mutableStateOf(SelectHomeserverFieldState.Empty) } - val padding = Modifier.padding(all = 10.dp) - Column(modifier) { - Row(padding) { + Row(BASE_PADDING) { Text(LocalContext.current.getString(R.string.selecthomeserver_text)) } - Row(padding) { + Row(BASE_PADDING) { SelectHomeserverField( modifier = Modifier.fillMaxWidth(), value = homeserver, @@ -87,13 +86,13 @@ fun SelectHomeserverControl( state = state, ) } - Row(padding) { + Row(BASE_PADDING) { Button( + modifier = Modifier.fillMaxWidth(), onClick = { onComplete(homeserver) }, enabled = (state == SelectHomeserverFieldState.Valid), - modifier = Modifier.fillMaxWidth(), ) { Text(LocalContext.current.getString(R.string.selecthomeserver_complete_text)) } diff --git a/app/src/main/java/eu/steffo/twom/ui/login/LoginActivity.kt b/app/src/main/java/eu/steffo/twom/ui/login/LoginActivity.kt index 4cbc3f5..5901921 100644 --- a/app/src/main/java/eu/steffo/twom/ui/login/LoginActivity.kt +++ b/app/src/main/java/eu/steffo/twom/ui/login/LoginActivity.kt @@ -22,7 +22,6 @@ import eu.steffo.twom.ui.homeserver.SelectHomeserverActivity import eu.steffo.twom.ui.theme.TwoMTheme -@OptIn(ExperimentalMaterial3Api::class) class LoginActivity : ComponentActivity() { private lateinit var homeserverLauncher: ActivityResultLauncher @@ -38,26 +37,11 @@ class LoginActivity : ComponentActivity() { super.onStart() setContent { - TwoMTheme { - Scaffold( - topBar = { - TopAppBar ( - title = { Text(LocalContext.current.getString(R.string.login_title)) } - ) - } - ) { - Row(Modifier.padding(it)) { - Button( - modifier = Modifier.fillMaxWidth(), - onClick = { - homeserverLauncher.launch(Intent(applicationContext, SelectHomeserverActivity::class.java)) - } - ) { - Text("→") - } - } + LoginActivityScaffold( + onSelectHomeserver = { + homeserverLauncher.launch(Intent(applicationContext, SelectHomeserverActivity::class.java)) } - } + ) } } } diff --git a/app/src/main/java/eu/steffo/twom/ui/login/LoginActivityControl.kt b/app/src/main/java/eu/steffo/twom/ui/login/LoginActivityControl.kt new file mode 100644 index 0000000..e75dd50 --- /dev/null +++ b/app/src/main/java/eu/steffo/twom/ui/login/LoginActivityControl.kt @@ -0,0 +1,73 @@ +package eu.steffo.twom.ui.login + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.material3.TextField +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.tooling.preview.Preview +import eu.steffo.twom.R +import eu.steffo.twom.ui.BASE_PADDING + + +@Composable +@Preview(showBackground = true) +fun LoginActivityControl( + modifier: Modifier = Modifier, + onSelectHomeserver: () -> Unit = {}, + onComplete: () -> Unit = {}, +) { + Column(modifier) { + Row(BASE_PADDING) { + Text(LocalContext.current.getString(R.string.login_text)) + } + Row(BASE_PADDING) { + Button( + modifier = Modifier.fillMaxWidth(), + onClick = onSelectHomeserver, + enabled = true, + ) { + Text(LocalContext.current.getString(R.string.login_selecthomeserver_text)) + } + } + Row(BASE_PADDING) { + TextField( + modifier = Modifier.fillMaxWidth(), + value = "", + onValueChange = {}, + placeholder = { + Text(LocalContext.current.getString(R.string.login_username_placeholder)) + }, + supportingText = { + Text(LocalContext.current.getString(R.string.login_username_supporting)) + }, + ) + } + Row(BASE_PADDING) { + TextField( + modifier = Modifier.fillMaxWidth(), + value = "", + onValueChange = {}, + placeholder = { + Text(LocalContext.current.getString(R.string.login_password_placeholder)) + }, + supportingText = { + Text(LocalContext.current.getString(R.string.login_password_supporting)) + }, + ) + } + Row(BASE_PADDING) { + Button( + modifier = Modifier.fillMaxWidth(), + onClick = onComplete, + enabled = false, + ) { + Text(LocalContext.current.getString(R.string.login_complete_text)) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/steffo/twom/ui/login/LoginActivityScaffold.kt b/app/src/main/java/eu/steffo/twom/ui/login/LoginActivityScaffold.kt new file mode 100644 index 0000000..c701822 --- /dev/null +++ b/app/src/main/java/eu/steffo/twom/ui/login/LoginActivityScaffold.kt @@ -0,0 +1,53 @@ +package eu.steffo.twom.ui.login + +import android.content.Intent +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ArrowBack +import androidx.compose.material3.Button +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.tooling.preview.Preview +import eu.steffo.twom.R +import eu.steffo.twom.ui.theme.TwoMTheme + + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +@Preview +fun LoginActivityScaffold( + onBack: () -> Unit = {}, + onSelectHomeserver: () -> Unit = {}, +) { + TwoMTheme { + Scaffold( + topBar = { + TopAppBar ( + navigationIcon = { + IconButton(onClick = onBack) { + Icon( + imageVector = Icons.Filled.ArrowBack, + contentDescription = LocalContext.current.getString(R.string.back) + ) + } + }, + title = { Text(LocalContext.current.getString(R.string.login_title)) } + ) + } + ) { + LoginActivityControl( + modifier = Modifier.padding(it), + onSelectHomeserver = onSelectHomeserver, + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 86f634c..d3ab092 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -20,4 +20,11 @@ Select homeserver Log into Matrix Go back + To use TwoM, you need to log into a Matrix homeserver. + Continue + Select homeserver + \@steffo:candy.steffo.eu + The Matrix ID to login as, including the @ symbol and the homeserver name. + •••••••• + The password of the Matrix account. \ No newline at end of file