Browse Source

LockScreen : avoid removing from composition the LoggedInFlowNode.Children when LockScreen is displayed.

pull/1806/head
ganfra 10 months ago
parent
commit
97bbc37f6c
  1. 15
      app/src/main/kotlin/io/element/android/x/MainActivity.kt
  2. 29
      appnav/src/main/kotlin/io/element/android/appnav/LoggedInFlowNode.kt
  3. 39
      appnav/src/main/kotlin/io/element/android/appnav/MoveActivityToBackgroundBackHandler.kt
  4. 6
      features/lockscreen/api/src/main/kotlin/io/element/android/features/lockscreen/api/LockScreenService.kt

15
app/src/main/kotlin/io/element/android/x/MainActivity.kt

@ -33,6 +33,7 @@ import com.bumble.appyx.core.integration.NodeHost @@ -33,6 +33,7 @@ import com.bumble.appyx.core.integration.NodeHost
import com.bumble.appyx.core.integrationpoint.NodeActivity
import com.bumble.appyx.core.plugin.NodeReadyObserver
import io.element.android.features.lockscreen.api.handleSecureFlag
import io.element.android.features.lockscreen.api.isLocked
import io.element.android.libraries.architecture.bindings
import io.element.android.libraries.core.log.logger.LoggerTag
import io.element.android.libraries.designsystem.utils.snackbar.LocalSnackbarDispatcher
@ -46,7 +47,6 @@ private val loggerTag = LoggerTag("MainActivity") @@ -46,7 +47,6 @@ private val loggerTag = LoggerTag("MainActivity")
class MainActivity : NodeActivity() {
private lateinit var mainNode: MainNode
private lateinit var appBindings: AppBindings
override fun onCreate(savedInstanceState: Bundle?) {
@ -61,6 +61,19 @@ class MainActivity : NodeActivity() { @@ -61,6 +61,19 @@ class MainActivity : NodeActivity() {
}
}
@Deprecated("")
override fun onBackPressed() {
// If the app is locked, we need to intercept onBackPressed before it goes to OnBackPressedDispatcher.
// Indeed, otherwise we would need to trick Appyx backstack management everywhere.
// Without this trick, we would get pop operations on the hidden backstack.
if (appBindings.lockScreenService().isLocked) {
//Do not kill the app in this case, just go to background.
moveTaskToBack(false)
} else {
super.onBackPressed()
}
}
@Composable
private fun MainContent(appBindings: AppBindings) {
ElementTheme {

29
appnav/src/main/kotlin/io/element/android/appnav/LoggedInFlowNode.kt

@ -362,23 +362,18 @@ class LoggedInFlowNode @AssistedInject constructor( @@ -362,23 +362,18 @@ class LoggedInFlowNode @AssistedInject constructor(
override fun View(modifier: Modifier) {
Box(modifier = modifier) {
val lockScreenState by lockScreenStateService.lockState.collectAsState()
when (lockScreenState) {
LockScreenLockState.Unlocked -> {
Children(
navModel = backstack,
modifier = Modifier,
// Animate navigation to settings and to a room
transitionHandler = rememberDefaultTransitionHandler(),
)
val isFtueDisplayed by ftueState.shouldDisplayFlow.collectAsState()
if (!isFtueDisplayed) {
PermanentChild(permanentNavModel = permanentNavModel, navTarget = NavTarget.LoggedInPermanent)
}
}
LockScreenLockState.Locked -> {
MoveActivityToBackgroundBackHandler()
PermanentChild(permanentNavModel = permanentNavModel, navTarget = NavTarget.LockPermanent)
}
Children(
navModel = backstack,
modifier = Modifier,
// Animate navigation to settings and to a room
transitionHandler = rememberDefaultTransitionHandler(),
)
val isFtueDisplayed by ftueState.shouldDisplayFlow.collectAsState()
if (!isFtueDisplayed) {
PermanentChild(permanentNavModel = permanentNavModel, navTarget = NavTarget.LoggedInPermanent)
}
if (lockScreenState == LockScreenLockState.Locked) {
PermanentChild(permanentNavModel = permanentNavModel, navTarget = NavTarget.LockPermanent)
}
}
}

39
appnav/src/main/kotlin/io/element/android/appnav/MoveActivityToBackgroundBackHandler.kt

@ -1,39 +0,0 @@ @@ -1,39 +0,0 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.appnav
import android.content.Context
import android.content.ContextWrapper
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
@Composable
fun MoveActivityToBackgroundBackHandler(enabled: Boolean = true) {
fun Context.findActivity(): ComponentActivity? = when (this) {
is ComponentActivity -> this
is ContextWrapper -> baseContext.findActivity()
else -> null
}
val context = LocalContext.current
BackHandler(enabled = enabled) {
context.findActivity()?.moveTaskToBack(false)
}
}

6
features/lockscreen/api/src/main/kotlin/io/element/android/features/lockscreen/api/LockScreenService.kt

@ -44,6 +44,12 @@ interface LockScreenService { @@ -44,6 +44,12 @@ interface LockScreenService {
fun isPinSetup(): Flow<Boolean>
}
/**
* Check if the app is currently locked.
*/
val LockScreenService.isLocked: Boolean
get() = lockState.value == LockScreenLockState.Locked
/**
* Makes sure the secure flag is set on the activity if the pin is setup.
* @param activity the activity to set the flag on.

Loading…
Cancel
Save