Merge pull request #1806 from vector-im/feature/fga/lock_screen_composition
LockScreen : rework LoggedInFlowNode and Back management
This commit is contained in:
@@ -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")
|
||||
class MainActivity : NodeActivity() {
|
||||
|
||||
private lateinit var mainNode: MainNode
|
||||
|
||||
private lateinit var appBindings: AppBindings
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -61,6 +61,20 @@ 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 {
|
||||
@Suppress("DEPRECATION")
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MainContent(appBindings: AppBindings) {
|
||||
ElementTheme {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
1
changelog.d/1806.misc
Normal file
1
changelog.d/1806.misc
Normal file
@@ -0,0 +1 @@
|
||||
LockScreen : rework LoggedInFlowNode and back management when locked.
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user