diff --git a/app/src/main/java/eu/steffo/twom/matrix/MatrixActivity.kt b/app/src/main/java/eu/steffo/twom/matrix/MatrixActivity.kt index f67fd3e..5aeee9c 100644 --- a/app/src/main/java/eu/steffo/twom/matrix/MatrixActivity.kt +++ b/app/src/main/java/eu/steffo/twom/matrix/MatrixActivity.kt @@ -7,19 +7,8 @@ import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.result.ActivityResultLauncher 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.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.theme.TwoMTheme import org.matrix.android.sdk.api.session.Session @@ -37,7 +26,7 @@ class MatrixActivity : ComponentActivity() { loginLauncher = 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) { RESULT_OK -> { @@ -45,25 +34,13 @@ class MatrixActivity : ComponentActivity() { TwoMMatrix.matrix.authenticationService().getLastAuthenticatedSession() setContent { - TwoMTheme { - Scaffold( - topBar = { - CenterAlignedTopAppBar( - title = { - Text(LocalContext.current.getString(R.string.app_name)) - } - ) - } - ) { - Text(session?.myUserId ?: "No session", Modifier.padding(it)) - } - } + MatrixActivityScaffold( + onClickLogin = this::onClickLogin, + session = session, + ) } } } - if (it.resultCode == RESULT_CANCELED) { - return@HandleResult - } } } @@ -71,28 +48,13 @@ class MatrixActivity : ComponentActivity() { super.onStart() setContent { - TwoMTheme { - Scaffold( - 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%") - } - } - } - } + MatrixActivityScaffold( + onClickLogin = this::onClickLogin + ) } } + + private fun onClickLogin() { + loginLauncher.launch(Intent(applicationContext, LoginActivity::class.java)) + } } diff --git a/app/src/main/java/eu/steffo/twom/matrix/MatrixActivityLoggedInControl.kt b/app/src/main/java/eu/steffo/twom/matrix/MatrixActivityLoggedInControl.kt new file mode 100644 index 0000000..241f68f --- /dev/null +++ b/app/src/main/java/eu/steffo/twom/matrix/MatrixActivityLoggedInControl.kt @@ -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)) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/steffo/twom/matrix/MatrixActivityNotLoggedInControl.kt b/app/src/main/java/eu/steffo/twom/matrix/MatrixActivityNotLoggedInControl.kt new file mode 100644 index 0000000..03db1a7 --- /dev/null +++ b/app/src/main/java/eu/steffo/twom/matrix/MatrixActivityNotLoggedInControl.kt @@ -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)) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/steffo/twom/matrix/MatrixActivityScaffold.kt b/app/src/main/java/eu/steffo/twom/matrix/MatrixActivityScaffold.kt new file mode 100644 index 0000000..f6c64c1 --- /dev/null +++ b/app/src/main/java/eu/steffo/twom/matrix/MatrixActivityScaffold.kt @@ -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, + ) + } + } + } +} \ 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 2775d3f..036a23f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,9 +1,5 @@ TwoM - https://candy.steffo.eu - Homeserver - The URL of the homeserver providing you with Matrix access. - The homeserver URL you provided is not a valid URL. Is this even a party? %1$s\'s party %1$s and %2$s\'s party @@ -11,12 +7,6 @@ %1$s, %2$s, %3$s, %4$s\'s party %1$s, %2$s, %3$s and %4$d others\' party Party invite - Continue - The homeserver URL you provided does not point to a Matrix homeserver. - Checking if the URL points to a Matrix homeserver… - Waiting for you to stop writing… - All checks complete! - Select homeserver Log into Matrix Go back To use TwoM, you need to log into a Matrix homeserver. Currently, TwoM supports only username and password authentication. @@ -29,5 +19,7 @@ Password Show password Hide password - Please enter the localpart of your Matrix homeserver. + To use TwoM, you need to be logged into Matrix. + Login + You are logged in. \ No newline at end of file