mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
ios: lock toggle; android: fix lock timer (#702)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
@@ -4,6 +4,7 @@ import android.app.Application
|
||||
import android.content.*
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.SystemClock.elapsedRealtime
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.viewModels
|
||||
@@ -37,12 +38,12 @@ class MainActivity: FragmentActivity(), LifecycleEventObserver {
|
||||
private val vm by viewModels<SimplexViewModel>()
|
||||
private val chatController by lazy { (application as SimplexApp).chatController }
|
||||
private val userAuthorized = mutableStateOf<Boolean?>(null)
|
||||
private val lastLA = mutableStateOf<Long?>(null)
|
||||
private val enteredBackground = mutableStateOf<Long?>(null)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
|
||||
// testJson()
|
||||
// testJson()
|
||||
val m = vm.chatModel
|
||||
processNotificationIntent(intent, m)
|
||||
setContent {
|
||||
@@ -67,38 +68,37 @@ class MainActivity: FragmentActivity(), LifecycleEventObserver {
|
||||
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
|
||||
withApi {
|
||||
when (event) {
|
||||
Lifecycle.Event.ON_STOP -> {
|
||||
enteredBackground.value = elapsedRealtime()
|
||||
}
|
||||
Lifecycle.Event.ON_START -> {
|
||||
// perform local authentication if needed
|
||||
val m = vm.chatModel
|
||||
val lastLAVal = lastLA.value
|
||||
if (
|
||||
m.controller.appPrefs.performLA.get()
|
||||
&& (lastLAVal == null || (System.nanoTime() - lastLAVal >= 30 * 1e+9))
|
||||
) {
|
||||
userAuthorized.value = false
|
||||
authenticate(
|
||||
generalGetString(R.string.auth_access_chats),
|
||||
generalGetString(R.string.auth_log_in_using_credential),
|
||||
this@MainActivity,
|
||||
completed = { laResult ->
|
||||
when (laResult) {
|
||||
LAResult.Success -> {
|
||||
userAuthorized.value = true
|
||||
lastLA.value = System.nanoTime()
|
||||
}
|
||||
is LAResult.Error -> laErrorToast(applicationContext, laResult.errString)
|
||||
LAResult.Failed -> laFailedToast(applicationContext)
|
||||
LAResult.Unavailable -> {
|
||||
userAuthorized.value = true
|
||||
m.performLA.value = false
|
||||
m.controller.appPrefs.performLA.set(false)
|
||||
laUnavailableTurningOffAlert()
|
||||
val enteredBackgroundVal = enteredBackground.value
|
||||
if (!m.controller.appPrefs.performLA.get()) {
|
||||
userAuthorized.value = true
|
||||
} else {
|
||||
if (enteredBackgroundVal == null || elapsedRealtime() - enteredBackgroundVal >= 30 * 1e+3) {
|
||||
userAuthorized.value = false
|
||||
authenticate(
|
||||
generalGetString(R.string.auth_unlock),
|
||||
generalGetString(R.string.auth_log_in_using_credential),
|
||||
this@MainActivity,
|
||||
completed = { laResult ->
|
||||
when (laResult) {
|
||||
LAResult.Success -> userAuthorized.value = true
|
||||
is LAResult.Error -> laErrorToast(applicationContext, laResult.errString)
|
||||
LAResult.Failed -> laFailedToast(applicationContext)
|
||||
LAResult.Unavailable -> {
|
||||
userAuthorized.value = true
|
||||
m.performLA.value = false
|
||||
m.controller.appPrefs.performLA.set(false)
|
||||
laUnavailableTurningOffAlert()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
userAuthorized.value = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,8 +137,6 @@ class MainActivity: FragmentActivity(), LifecycleEventObserver {
|
||||
LAResult.Success -> {
|
||||
m.performLA.value = true
|
||||
prefPerformLA.set(true)
|
||||
userAuthorized.value = true
|
||||
lastLA.value = System.nanoTime()
|
||||
laTurnedOnAlert()
|
||||
}
|
||||
is LAResult.Error -> {
|
||||
@@ -206,7 +204,7 @@ fun MainPage(
|
||||
showLANotice: () -> Unit
|
||||
) {
|
||||
// this with LaunchedEffect(userAuthorized.value) fixes bottom sheet visibly collapsing after authentication
|
||||
var chatsAccessAuthorized by remember { mutableStateOf<Boolean>(false) }
|
||||
var chatsAccessAuthorized by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(userAuthorized.value) {
|
||||
delay(500L)
|
||||
chatsAccessAuthorized = userAuthorized.value == true
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
<!-- LocalAuthentication.kt -->
|
||||
<string name="auth_turned_on">Блокировка SimpleX включена</string>
|
||||
<string name="auth_turned_on_desc">Вы будете аутентифицированы при запуске и возобновлении приложения, которое было 30 секунд в фоновом режиме.</string>
|
||||
<string name="auth_access_chats">Разблокировать SimpleX</string>
|
||||
<string name="auth_unlock">Разблокировать</string>
|
||||
<string name="auth_log_in_using_credential">Пройдите аутентификацию</string>
|
||||
<string name="auth_enable">Включить блокировку SimpleX</string>
|
||||
<string name="auth_disable">Отключить блокировку SimpleX</string>
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
<!-- LocalAuthentication.kt -->
|
||||
<string name="auth_turned_on">SimpleX Lock turned on</string>
|
||||
<string name="auth_turned_on_desc">You will be required to authenticate when you start or resume the app after 30 seconds in background.</string>
|
||||
<string name="auth_access_chats">Access chats</string>
|
||||
<string name="auth_unlock">Unlock</string>
|
||||
<string name="auth_log_in_using_credential">Log in using your credential</string>
|
||||
<string name="auth_enable">Enable SimpleX Lock</string>
|
||||
<string name="auth_disable">Disable SimpleX Lock</string>
|
||||
|
||||
Reference in New Issue
Block a user