android: fix lock not showing (#3181)

* android: fix lock not showing

* better fix
This commit is contained in:
Stanislav Dmitrenko 2023-10-08 02:00:40 +08:00 committed by GitHub
parent 420d80ad6c
commit 76fb5b6dca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 3 deletions

View File

@ -91,11 +91,11 @@ class MainActivity: FragmentActivity() {
// When pressed Back and there is no one wants to process the back event, clear auth state to force re-auth on launch // When pressed Back and there is no one wants to process the back event, clear auth state to force re-auth on launch
AppLock.clearAuthState() AppLock.clearAuthState()
AppLock.laFailed.value = true AppLock.laFailed.value = true
AppLock.destroyedAfterBackPress.value = true
} }
if (!onBackPressedDispatcher.hasEnabledCallbacks()) { if (!onBackPressedDispatcher.hasEnabledCallbacks()) {
// Drop shared content // Drop shared content
SimplexApp.context.chatModel.sharedContent.value = null SimplexApp.context.chatModel.sharedContent.value = null
finish()
} }
} }
} }

View File

@ -69,3 +69,5 @@ actual fun hideKeyboard(view: Any?) {
(androidAppContext.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(view.windowToken, 0) (androidAppContext.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(view.windowToken, 0)
} }
} }
actual fun androidIsFinishingMainActivity(): Boolean = (mainActivity.get()?.isFinishing == true)

View File

@ -149,7 +149,7 @@ fun MainScreen() {
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
// With these constrains when user presses back button while on ChatList, activity destroys and shows auth request // With these constrains when user presses back button while on ChatList, activity destroys and shows auth request
// while the screen moves to a launcher. Detect it and prevent showing the auth // while the screen moves to a launcher. Detect it and prevent showing the auth
if (!(AppLock.destroyedAfterBackPress.value && chatModel.controller.appPrefs.laMode.get() == LAMode.SYSTEM)) { if (!(androidIsFinishingMainActivity() && chatModel.controller.appPrefs.laMode.get() == LAMode.SYSTEM)) {
AppLock.runAuthenticate() AppLock.runAuthenticate()
} }
} }

View File

@ -24,7 +24,6 @@ object AppLock {
// Remember result and show it after orientation change // Remember result and show it after orientation change
val laFailed = mutableStateOf(false) val laFailed = mutableStateOf(false)
val destroyedAfterBackPress = mutableStateOf(false)
fun clearAuthState() { fun clearAuthState() {
userAuthorized.value = null userAuthorized.value = null

View File

@ -14,3 +14,5 @@ expect fun LocalMultiplatformView(): Any?
@Composable @Composable
expect fun getKeyboardState(): State<KeyboardState> expect fun getKeyboardState(): State<KeyboardState>
expect fun hideKeyboard(view: Any?) expect fun hideKeyboard(view: Any?)
expect fun androidIsFinishingMainActivity(): Boolean

View File

@ -17,3 +17,5 @@ actual fun LocalMultiplatformView(): Any? = null
@Composable @Composable
actual fun getKeyboardState(): State<KeyboardState> = remember { mutableStateOf(KeyboardState.Opened) } actual fun getKeyboardState(): State<KeyboardState> = remember { mutableStateOf(KeyboardState.Opened) }
actual fun hideKeyboard(view: Any?) {} actual fun hideKeyboard(view: Any?) {}
actual fun androidIsFinishingMainActivity(): Boolean = false