mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Refactoring switching server or user (#205)
Now when initiating a user or server switch, you can't back out of it and must select a user/server. This will be useful when PIN code are implemented down the road. The app will now disconnect the web socket when backgrounded. Also lots of internal refactoring
This commit is contained in:
parent
2e3e4e3f5f
commit
58395e9adf
31 changed files with 442 additions and 277 deletions
|
|
@ -12,6 +12,7 @@ import androidx.compose.runtime.LaunchedEffect
|
|||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
|
|
@ -96,22 +97,19 @@ class MainActivity : AppCompatActivity() {
|
|||
) {
|
||||
var isRestoringSession by remember { mutableStateOf(true) }
|
||||
LaunchedEffect(Unit) {
|
||||
if (appPreferences.currentServerId.isNotBlank() && appPreferences.currentUserId.isNotBlank()) {
|
||||
try {
|
||||
serverRepository.restoreSession(
|
||||
appPreferences.currentServerId?.toUUIDOrNull(),
|
||||
appPreferences.currentUserId?.toUUIDOrNull(),
|
||||
)
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(ex, "Exception restoring session")
|
||||
}
|
||||
Timber.d("MainActivity session restored")
|
||||
try {
|
||||
serverRepository.restoreSession(
|
||||
appPreferences.currentServerId?.toUUIDOrNull(),
|
||||
appPreferences.currentUserId?.toUUIDOrNull(),
|
||||
)
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(ex, "Exception restoring session")
|
||||
}
|
||||
isRestoringSession = false
|
||||
}
|
||||
val server = serverRepository.currentServer
|
||||
val user = serverRepository.currentUser
|
||||
val userDto = serverRepository.currentUserDto
|
||||
val server by serverRepository.currentServer.observeAsState()
|
||||
val user by serverRepository.currentUser.observeAsState()
|
||||
val userDto by serverRepository.currentUserDto.observeAsState()
|
||||
|
||||
val preferences =
|
||||
UserPreferences(
|
||||
|
|
@ -139,8 +137,6 @@ class MainActivity : AppCompatActivity() {
|
|||
val initialDestination =
|
||||
if (server != null && user != null) {
|
||||
Destination.Home()
|
||||
} else if (server != null) {
|
||||
Destination.UserList
|
||||
} else {
|
||||
Destination.ServerList
|
||||
}
|
||||
|
|
@ -155,9 +151,6 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
LaunchedEffect(server, user) {
|
||||
serverEventListener.init(server, user)
|
||||
}
|
||||
ApplicationContent(
|
||||
user = user,
|
||||
server = server,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue