Add basic session management to avoid login each time

This commit is contained in:
ganfra 2018-10-11 09:58:28 +02:00
parent f9e6f4b533
commit 5baaecaea4
4 changed files with 26 additions and 2 deletions

View File

@ -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)

View File

@ -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<Session>): Cancelable
fun hasActiveSessions(): Boolean
fun getLastActiveSession(): Session?
}

View File

@ -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<Session>): Cancelable {
val authAPI = buildAuthAPI(homeServerConnectionConfig)

View File

@ -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 {