Fix bunch of issues around login/logout and introduces messages feature
This commit is contained in:
parent
b5e4ef9637
commit
d04d847521
19 changed files with 314 additions and 89 deletions
|
|
@ -33,7 +33,12 @@ private fun MainScreen(viewModel: MainViewModel) {
|
|||
val engine = rememberNavHostEngine()
|
||||
val navController = engine.rememberNavController()
|
||||
val startRoute = runBlocking {
|
||||
if (!viewModel.hasSession()) LoginScreenNavigationDestination else NavGraphs.root.startRoute
|
||||
if (!viewModel.isLoggedIn()) {
|
||||
LoginScreenNavigationDestination
|
||||
} else {
|
||||
viewModel.restoreSession()
|
||||
NavGraphs.root.startRoute
|
||||
}
|
||||
}
|
||||
|
||||
DestinationsNavHost(
|
||||
|
|
|
|||
|
|
@ -2,11 +2,16 @@ package io.element.android.x
|
|||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import io.element.android.x.matrix.MatrixInstance
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
||||
class MainViewModel : ViewModel() {
|
||||
private val matrix = MatrixInstance.getInstance()
|
||||
|
||||
suspend fun hasSession(): Boolean {
|
||||
return matrix.restoreSession() != null
|
||||
suspend fun isLoggedIn(): Boolean {
|
||||
return matrix.isLoggedIn().first()
|
||||
}
|
||||
|
||||
suspend fun restoreSession() {
|
||||
matrix.restoreSession()
|
||||
}
|
||||
}
|
||||
|
|
@ -4,17 +4,25 @@ import androidx.compose.runtime.Composable
|
|||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import com.ramcosta.composedestinations.annotation.RootNavGraph
|
||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||
import com.ramcosta.composedestinations.navigation.popUpTo
|
||||
import io.element.android.x.destinations.LoginScreenNavigationDestination
|
||||
import io.element.android.x.destinations.MessagesScreenNavigationDestination
|
||||
import io.element.android.x.destinations.RoomListScreenNavigationDestination
|
||||
import io.element.android.x.features.login.LoginScreen
|
||||
import io.element.android.x.features.messages.MessagesScreen
|
||||
import io.element.android.x.features.roomlist.RoomListScreen
|
||||
import io.element.android.x.matrix.core.RoomId
|
||||
|
||||
@Destination
|
||||
@Composable
|
||||
fun LoginScreenNavigation(navigator: DestinationsNavigator) {
|
||||
LoginScreen(
|
||||
onLoginWithSuccess = {
|
||||
navigator.clearBackStack(RoomListScreenNavigationDestination)
|
||||
navigator.navigate(RoomListScreenNavigationDestination){
|
||||
popUpTo(LoginScreenNavigationDestination){
|
||||
inclusive = true
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -23,9 +31,24 @@ fun LoginScreenNavigation(navigator: DestinationsNavigator) {
|
|||
@Destination
|
||||
@Composable
|
||||
fun RoomListScreenNavigation(navigator: DestinationsNavigator) {
|
||||
RoomListScreen(onSuccessLogout = {
|
||||
navigator.clearBackStack(LoginScreenNavigationDestination)
|
||||
})
|
||||
RoomListScreen(
|
||||
onRoomClicked = { roomId: RoomId ->
|
||||
navigator.navigate(MessagesScreenNavigationDestination(roomId = roomId.value))
|
||||
},
|
||||
onSuccessLogout = {
|
||||
navigator.navigate(LoginScreenNavigationDestination){
|
||||
popUpTo(RoomListScreenNavigationDestination){
|
||||
inclusive = true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@Destination
|
||||
@Composable
|
||||
fun MessagesScreenNavigation(roomId: String) {
|
||||
MessagesScreen(roomId)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue