mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Add basic session management to avoid login each time
This commit is contained in:
parent
f9e6f4b533
commit
5baaecaea4
@ -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)
|
||||
|
@ -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?
|
||||
|
||||
|
||||
}
|
@ -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)
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user