Store and restore session
This commit is contained in:
parent
fa50f03fdd
commit
420bfe9a66
5 changed files with 92 additions and 4 deletions
|
|
@ -4,8 +4,11 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import io.element.android.x.ui.screen.login.LoginActivity
|
||||
import io.element.android.x.ui.screen.login.RoomListActivity
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
private val launcher =
|
||||
|
|
@ -18,11 +21,17 @@ class MainActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private val viewModel: MainViewModel by viewModels()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
// Just start the LoginActivity for now.
|
||||
// TODO if a session exist, start the room list
|
||||
launcher.launch(Intent(this, LoginActivity::class.java))
|
||||
lifecycleScope.launch {
|
||||
if (viewModel.hasSession()) {
|
||||
startRoomActivityAndFinish()
|
||||
} else {
|
||||
launcher.launch(Intent(this@MainActivity, LoginActivity::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startRoomActivityAndFinish() {
|
||||
|
|
|
|||
12
app/src/main/java/io/element/android/x/MainViewModel.kt
Normal file
12
app/src/main/java/io/element/android/x/MainViewModel.kt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package io.element.android.x
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import io.element.android.x.sdk.matrix.MatrixInstance
|
||||
|
||||
class MainViewModel : ViewModel() {
|
||||
private val matrix = MatrixInstance.getInstance()
|
||||
|
||||
suspend fun hasSession(): Boolean {
|
||||
return matrix.restoreSession() != null
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue