diff --git a/app/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt b/app/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt index 9b3e6b00..dbe08986 100644 --- a/app/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt +++ b/app/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt @@ -23,6 +23,7 @@ class LoginActivity : RiotActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_login) authenticateButton.setOnClickListener { authenticate() } + checkActiveSessions() } private fun authenticate() { @@ -48,6 +49,13 @@ class LoginActivity : RiotActivity() { }) } + private fun checkActiveSessions() { + if (authenticator.hasActiveSessions()) { + matrix.currentSession = authenticator.getLastActiveSession() + goToHomeScreen() + } + } + private fun goToHomeScreen() { val intent = HomeActivity.newIntent(this) startActivity(intent) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt index 6c72e104..906176e6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt @@ -1,12 +1,17 @@ package im.vector.matrix.android.api.auth import im.vector.matrix.android.api.MatrixCallback -import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig +import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.util.Cancelable interface Authenticator { fun authenticate(homeServerConnectionConfig: HomeServerConnectionConfig, login: String, password: String, callback: MatrixCallback): Cancelable + fun hasActiveSessions(): Boolean + + fun getLastActiveSession(): Session? + + } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt index b804c7c6..118170b4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt @@ -25,6 +25,17 @@ class DefaultAuthenticator(private val retrofitBuilder: Retrofit.Builder, private val coroutineDispatchers: MatrixCoroutineDispatchers, private val sessionParamsStore: SessionParamsStore) : Authenticator { + override fun hasActiveSessions(): Boolean { + return sessionParamsStore.get() != null + } + + override fun getLastActiveSession(): Session? { + val sessionParams = sessionParamsStore.get() + return sessionParams?.let { + DefaultSession(it) + } + } + override fun authenticate(homeServerConnectionConfig: HomeServerConnectionConfig, login: String, password: String, callback: MatrixCallback): Cancelable { val authAPI = buildAuthAPI(homeServerConnectionConfig) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index 09fb9167..c353eae6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -20,7 +20,7 @@ class DefaultSession(sessionParams: SessionParams) : Session, KoinComponent { val sessionModule = SessionModule(sessionParams) val syncModule = SyncModule() StandAloneContext.loadKoinModules(listOf(sessionModule, syncModule)) - scope = getKoin().createScope(SCOPE) + scope = getKoin().getOrCreateScope(SCOPE) } override fun synchronizer(): Synchronizer {