From 172f4ff76b58aabd8781c322cf79024693f5da03 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 4 Feb 2024 23:52:04 +0100 Subject: [PATCH] Explicitly declare sessions --- .../activities/ConfigureRoomActivity.kt | 2 ++ .../components/ConfigureRoomScaffold.kt | 5 ++--- .../viewroom/activities/ViewRoomActivity.kt | 20 +------------------ 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/steffo/twom/configureroom/activities/ConfigureRoomActivity.kt b/app/src/main/java/eu/steffo/twom/configureroom/activities/ConfigureRoomActivity.kt index 545a0a6..ee1fd33 100644 --- a/app/src/main/java/eu/steffo/twom/configureroom/activities/ConfigureRoomActivity.kt +++ b/app/src/main/java/eu/steffo/twom/configureroom/activities/ConfigureRoomActivity.kt @@ -8,6 +8,7 @@ import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.result.contract.ActivityResultContract import eu.steffo.twom.configureroom.components.ConfigureRoomScaffold +import eu.steffo.twom.matrix.utils.TwoMMatrix class ConfigureRoomActivity : ComponentActivity() { @@ -91,6 +92,7 @@ class ConfigureRoomActivity : ComponentActivity() { setContent { ConfigureRoomScaffold( + session = TwoMMatrix.session!!, initialConfiguration = configuration, ) } diff --git a/app/src/main/java/eu/steffo/twom/configureroom/components/ConfigureRoomScaffold.kt b/app/src/main/java/eu/steffo/twom/configureroom/components/ConfigureRoomScaffold.kt index 677c94f..5380e45 100644 --- a/app/src/main/java/eu/steffo/twom/configureroom/components/ConfigureRoomScaffold.kt +++ b/app/src/main/java/eu/steffo/twom/configureroom/components/ConfigureRoomScaffold.kt @@ -7,15 +7,14 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier import eu.steffo.twom.configureroom.activities.ConfigureRoomActivity import eu.steffo.twom.matrix.complocals.LocalSession -import eu.steffo.twom.matrix.utils.TwoMMatrix import eu.steffo.twom.theme.components.TwoMTheme +import org.matrix.android.sdk.api.session.Session @Composable fun ConfigureRoomScaffold( + session: Session, initialConfiguration: ConfigureRoomActivity.Configuration? = null, ) { - val session = TwoMMatrix.matrix.authenticationService().getLastAuthenticatedSession()!! - TwoMTheme { CompositionLocalProvider(LocalSession provides session) { Scaffold( diff --git a/app/src/main/java/eu/steffo/twom/viewroom/activities/ViewRoomActivity.kt b/app/src/main/java/eu/steffo/twom/viewroom/activities/ViewRoomActivity.kt index bb248b1..5977de8 100644 --- a/app/src/main/java/eu/steffo/twom/viewroom/activities/ViewRoomActivity.kt +++ b/app/src/main/java/eu/steffo/twom/viewroom/activities/ViewRoomActivity.kt @@ -2,14 +2,11 @@ package eu.steffo.twom.viewroom.activities import android.content.Context import android.content.Intent -import android.os.Bundle -import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.result.contract.ActivityResultContract import eu.steffo.twom.matrix.utils.TwoMMatrix import eu.steffo.twom.viewroom.components.ViewRoomScaffold -import org.matrix.android.sdk.api.session.Session class ViewRoomActivity : ComponentActivity() { companion object { @@ -26,21 +23,6 @@ class ViewRoomActivity : ComponentActivity() { override fun parseResult(resultCode: Int, intent: Intent?) {} } - private lateinit var session: Session - - private fun fetchLastSession() { - Log.d("Main", "Fetching the last successfully authenticated session...") - // FIXME: If this is null, it means that something launched this while no session was authenticated... - session = TwoMMatrix.matrix.authenticationService().getLastAuthenticatedSession()!! - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - // FIXME: Hopefully, if this succeeds, the session is also open... hopefully. - fetchLastSession() - } - override fun onStart() { super.onStart() @@ -48,7 +30,7 @@ class ViewRoomActivity : ComponentActivity() { setContent { ViewRoomScaffold( - session = session, + session = TwoMMatrix.session!!, roomId = roomId!!, ) }