Skip to content

Commit

Permalink
fix: run UI logic on the main thread [WPB-9458] (#3055)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara authored May 29, 2024
1 parent 5aaf191 commit 2435b45
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ import com.wire.android.navigation.NavigationGraph
import com.wire.android.navigation.navigateToItem
import com.wire.android.navigation.rememberNavigator
import com.wire.android.ui.calling.getIncomingCallIntent
import com.wire.android.ui.calling.getOutgoingCallIntent
import com.wire.android.ui.calling.getOngoingCallIntent
import com.wire.android.ui.calling.getOutgoingCallIntent
import com.wire.android.ui.common.snackbar.LocalSnackbarHostState
import com.wire.android.ui.common.topappbar.CommonTopAppBar
import com.wire.android.ui.common.topappbar.CommonTopAppBarViewModel
Expand Down Expand Up @@ -151,7 +151,7 @@ class WireActivity : AppCompatActivity() {

WindowCompat.setDecorFitsSystemWindows(window, false)

lifecycleScope.launch(Dispatchers.Default) {
lifecycleScope.launch {

appLogger.i("$TAG persistent connection status")
viewModel.observePersistentConnectionStatus()
Expand All @@ -167,12 +167,11 @@ class WireActivity : AppCompatActivity() {
InitialAppState.LOGGED_IN -> HomeScreenDestination
}
appLogger.i("$TAG composable content")
withContext(Dispatchers.Main) {
setComposableContent(startDestination) {
appLogger.i("$TAG splash hide")
shouldKeepSplashOpen = false
handleDeepLink(intent, savedInstanceState)
}

setComposableContent(startDestination) {
appLogger.i("$TAG splash hide")
shouldKeepSplashOpen = false
handleDeepLink(intent, savedInstanceState)
}
}
}
Expand Down Expand Up @@ -237,17 +236,17 @@ class WireActivity : AppCompatActivity() {

// This setup needs to be done after the navigation graph is created, because building the graph takes some time,
// and if any NavigationCommand is executed before the graph is fully built, it will cause a NullPointerException.
setUpNavigation(navigator.navController, onComplete)
handleScreenshotCensoring()
handleDialogs(navigator::navigate)
SetUpNavigation(navigator.navController, onComplete)
HandleScreenshotCensoring()
HandleDialogs(navigator::navigate)
}
}
}
}
}

@Composable
private fun setUpNavigation(
private fun SetUpNavigation(
navController: NavHostController,
onComplete: () -> Unit,
) {
Expand Down Expand Up @@ -281,7 +280,7 @@ class WireActivity : AppCompatActivity() {
}

@Composable
private fun handleScreenshotCensoring() {
private fun HandleScreenshotCensoring() {
LaunchedEffect(viewModel.globalAppState.screenshotCensoringEnabled) {
if (viewModel.globalAppState.screenshotCensoringEnabled) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
Expand All @@ -293,7 +292,7 @@ class WireActivity : AppCompatActivity() {

@Suppress("ComplexMethod")
@Composable
private fun handleDialogs(navigate: (NavigationCommand) -> Unit) {
private fun HandleDialogs(navigate: (NavigationCommand) -> Unit) {
val context = LocalContext.current
with(featureFlagNotificationViewModel.featureFlagState) {
if (shouldShowTeamAppLockDialog) {
Expand Down Expand Up @@ -471,7 +470,7 @@ class WireActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()

lifecycleScope.launch(Dispatchers.Default) {
lifecycleScope.launch {
lockCodeTimeManager.get().observeAppLock()
// Listen to one flow in a lifecycle-aware manner using flowWithLifecycle
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
Expand Down

0 comments on commit 2435b45

Please sign in to comment.