mirror of
https://github.com/Steffo99/twom.git
synced 2024-11-21 23:54:26 +00:00
Clean up MatrixActivity
This commit is contained in:
parent
c00039b008
commit
5a083bbd05
5 changed files with 118 additions and 61 deletions
|
@ -7,19 +7,8 @@ import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Scaffold
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import eu.steffo.twom.R
|
|
||||||
import eu.steffo.twom.login.LoginActivity
|
import eu.steffo.twom.login.LoginActivity
|
||||||
import eu.steffo.twom.theme.TwoMTheme
|
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,7 +26,7 @@ class MatrixActivity : ComponentActivity() {
|
||||||
|
|
||||||
loginLauncher =
|
loginLauncher =
|
||||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) HandleResult@{
|
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) HandleResult@{
|
||||||
Log.d(this::class.qualifiedName, "LoginActivity has returned a result!")
|
Log.d("Matrix", "LoginActivity has returned a result!")
|
||||||
|
|
||||||
when (it.resultCode) {
|
when (it.resultCode) {
|
||||||
RESULT_OK -> {
|
RESULT_OK -> {
|
||||||
|
@ -45,25 +34,13 @@ class MatrixActivity : ComponentActivity() {
|
||||||
TwoMMatrix.matrix.authenticationService().getLastAuthenticatedSession()
|
TwoMMatrix.matrix.authenticationService().getLastAuthenticatedSession()
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
TwoMTheme {
|
MatrixActivityScaffold(
|
||||||
Scaffold(
|
onClickLogin = this::onClickLogin,
|
||||||
topBar = {
|
session = session,
|
||||||
CenterAlignedTopAppBar(
|
)
|
||||||
title = {
|
|
||||||
Text(LocalContext.current.getString(R.string.app_name))
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Text(session?.myUserId ?: "No session", Modifier.padding(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (it.resultCode == RESULT_CANCELED) {
|
|
||||||
return@HandleResult
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,28 +48,13 @@ class MatrixActivity : ComponentActivity() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
TwoMTheme {
|
MatrixActivityScaffold(
|
||||||
Scaffold(
|
onClickLogin = this::onClickLogin
|
||||||
topBar = {
|
)
|
||||||
CenterAlignedTopAppBar(
|
|
||||||
title = {
|
|
||||||
Text(LocalContext.current.getString(R.string.app_name))
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Row(Modifier.padding(it)) {
|
|
||||||
Button(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
onClick = {
|
|
||||||
loginLauncher.launch(Intent(applicationContext, LoginActivity::class.java))
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Text("plis login with matrics no scam 100%")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun onClickLogin() {
|
||||||
|
loginLauncher.launch(Intent(applicationContext, LoginActivity::class.java))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package eu.steffo.twom.matrix
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import eu.steffo.twom.R
|
||||||
|
import eu.steffo.twom.theme.TwoMPadding
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MatrixActivityLoggedInControl(
|
||||||
|
session: Session,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
Column(modifier) {
|
||||||
|
Row(TwoMPadding.base) {
|
||||||
|
Text(LocalContext.current.getString(R.string.loggedin_text))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package eu.steffo.twom.matrix
|
||||||
|
|
||||||
|
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.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.theme.TwoMPadding
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
@Preview(showBackground = true)
|
||||||
|
fun MatrixActivityNotLoggedInControl(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
onClickLogin: () -> Unit = {},
|
||||||
|
) {
|
||||||
|
Column(modifier) {
|
||||||
|
Row(TwoMPadding.base) {
|
||||||
|
Text(LocalContext.current.getString(R.string.notloggedin_text))
|
||||||
|
}
|
||||||
|
Row(TwoMPadding.base) {
|
||||||
|
Button(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
onClick = onClickLogin,
|
||||||
|
) {
|
||||||
|
Text(LocalContext.current.getString(R.string.notloggedin_login_text))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package eu.steffo.twom.matrix
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
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.theme.TwoMTheme
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
@Preview
|
||||||
|
fun MatrixActivityScaffold(
|
||||||
|
onClickLogin: () -> Unit = {},
|
||||||
|
session: Session? = null,
|
||||||
|
) {
|
||||||
|
TwoMTheme {
|
||||||
|
Scaffold(
|
||||||
|
topBar = {
|
||||||
|
CenterAlignedTopAppBar(
|
||||||
|
title = {
|
||||||
|
Text(LocalContext.current.getString(R.string.app_name))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
if (session != null) {
|
||||||
|
MatrixActivityLoggedInControl(
|
||||||
|
modifier = Modifier.padding(it),
|
||||||
|
session = session,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
MatrixActivityNotLoggedInControl(
|
||||||
|
modifier = Modifier.padding(it),
|
||||||
|
onClickLogin = onClickLogin,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,5 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">TwoM</string>
|
<string name="app_name">TwoM</string>
|
||||||
<string name="selecthomeserver_input_placeholder">https://candy.steffo.eu</string>
|
|
||||||
<string name="selecthomeserver_input_label">Homeserver</string>
|
|
||||||
<string name="selecthomeserver_input_supporting_empty">The URL of the homeserver providing you with Matrix access.</string>
|
|
||||||
<string name="selecthomeserver_input_supporting_urlinvalid">The homeserver URL you provided is not a valid URL.</string>
|
|
||||||
<string name="room_name_fallback_members_0">Is this even a party?</string>
|
<string name="room_name_fallback_members_0">Is this even a party?</string>
|
||||||
<string name="room_name_fallback_members_1">%1$s\'s party</string>
|
<string name="room_name_fallback_members_1">%1$s\'s party</string>
|
||||||
<string name="room_name_fallback_members_2">%1$s and %2$s\'s party</string>
|
<string name="room_name_fallback_members_2">%1$s and %2$s\'s party</string>
|
||||||
|
@ -11,12 +7,6 @@
|
||||||
<string name="room_name_fallback_members_4">%1$s, %2$s, %3$s, %4$s\'s party</string>
|
<string name="room_name_fallback_members_4">%1$s, %2$s, %3$s, %4$s\'s party</string>
|
||||||
<string name="room_name_fallback_members_more">%1$s, %2$s, %3$s and %4$d others\' party</string>
|
<string name="room_name_fallback_members_more">%1$s, %2$s, %3$s and %4$d others\' party</string>
|
||||||
<string name="room_name_fallback_invite">Party invite</string>
|
<string name="room_name_fallback_invite">Party invite</string>
|
||||||
<string name="selecthomeserver_complete_text">Continue</string>
|
|
||||||
<string name="selecthomeserver_input_supporting_flowinvalid">The homeserver URL you provided does not point to a Matrix homeserver.</string>
|
|
||||||
<string name="selecthomeserver_input_supporting_validating">Checking if the URL points to a Matrix homeserver…</string>
|
|
||||||
<string name="selecthomeserver_input_supporting_waiting">Waiting for you to stop writing…</string>
|
|
||||||
<string name="selecthomeserver_input_supporting_valid">All checks complete!</string>
|
|
||||||
<string name="homeserver_title">Select homeserver</string>
|
|
||||||
<string name="login_title">Log into Matrix</string>
|
<string name="login_title">Log into Matrix</string>
|
||||||
<string name="back">Go back</string>
|
<string name="back">Go back</string>
|
||||||
<string name="login_text">To use TwoM, you need to log into a Matrix homeserver. Currently, TwoM supports only username and password authentication.</string>
|
<string name="login_text">To use TwoM, you need to log into a Matrix homeserver. Currently, TwoM supports only username and password authentication.</string>
|
||||||
|
@ -29,5 +19,7 @@
|
||||||
<string name="login_password_label">Password</string>
|
<string name="login_password_label">Password</string>
|
||||||
<string name="password_show">Show password</string>
|
<string name="password_show">Show password</string>
|
||||||
<string name="password_hide">Hide password</string>
|
<string name="password_hide">Hide password</string>
|
||||||
<string name="selecthomeserver_text">Please enter the localpart of your Matrix homeserver.</string>
|
<string name="notloggedin_text">To use TwoM, you need to be logged into Matrix.</string>
|
||||||
|
<string name="notloggedin_login_text">Login</string>
|
||||||
|
<string name="loggedin_text">You are logged in.</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in a new issue