mirror of
https://github.com/Steffo99/twom.git
synced 2024-11-21 23:54:26 +00:00
Start work on building the LoginActivity
This commit is contained in:
parent
395ec102c8
commit
02d3fac1db
6 changed files with 150 additions and 26 deletions
8
app/src/main/java/eu/steffo/twom/ui/BASE_PADDING.kt
Normal file
8
app/src/main/java/eu/steffo/twom/ui/BASE_PADDING.kt
Normal file
|
@ -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)
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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<Intent>
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,4 +20,11 @@
|
|||
<string name="homeserver_title">Select homeserver</string>
|
||||
<string name="login_title">Log into Matrix</string>
|
||||
<string name="back">Go back</string>
|
||||
<string name="login_text">To use TwoM, you need to log into a Matrix homeserver.</string>
|
||||
<string name="login_complete_text">Continue</string>
|
||||
<string name="login_selecthomeserver_text">Select homeserver</string>
|
||||
<string name="login_username_placeholder">\@steffo:candy.steffo.eu</string>
|
||||
<string name="login_username_supporting">The Matrix ID to login as, including the @ symbol and the homeserver name.</string>
|
||||
<string name="login_password_placeholder">••••••••</string>
|
||||
<string name="login_password_supporting">The password of the Matrix account.</string>
|
||||
</resources>
|
Loading…
Reference in a new issue