diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/CallSettings.kt b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/CallSettings.kt index 20b941ec34..8d34d74860 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/CallSettings.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/CallSettings.kt @@ -80,8 +80,9 @@ private fun LockscreenOpts(lockscreenOpts: State, enabled: Sta fun SharedPreferenceToggle( text: String, preference: SharedPreference, - preferenceState: MutableState? = null -) { + preferenceState: MutableState? = null, + onChange: ((Boolean) -> Unit)? = null, + ) { val prefState = preferenceState ?: remember { mutableStateOf(preference.get()) } Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { Text(text, Modifier.padding(end = 24.dp)) @@ -91,6 +92,7 @@ fun SharedPreferenceToggle( onCheckedChange = { preference.set(it) prefState.value = it + onChange?.invoke(it) }, colors = SwitchDefaults.colors( checkedThumbColor = MaterialTheme.colors.primary, diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/PrivacySettings.kt b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/PrivacySettings.kt index 4b97ec9777..d2402f9f6d 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/PrivacySettings.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/PrivacySettings.kt @@ -5,13 +5,17 @@ import SectionItemView import SectionSpacer import SectionTextFooter import SectionView +import android.view.WindowManager import androidx.compose.foundation.layout.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.stringResource +import androidx.fragment.app.FragmentActivity import chat.simplex.app.R import chat.simplex.app.model.* import chat.simplex.app.views.helpers.* @@ -30,7 +34,17 @@ fun PrivacySettingsView( SectionView(stringResource(R.string.settings_section_title_device)) { ChatLockItem(chatModel.performLA, setPerformLA) SectionDivider() - SettingsPreferenceItem(Icons.Outlined.VisibilityOff, stringResource(R.string.protect_app_screen), chatModel.controller.appPrefs.privacyProtectScreen) + val context = LocalContext.current + SettingsPreferenceItem(Icons.Outlined.VisibilityOff, stringResource(R.string.protect_app_screen), chatModel.controller.appPrefs.privacyProtectScreen) { on -> + if (on) { + (context as? FragmentActivity)?.window?.setFlags( + WindowManager.LayoutParams.FLAG_SECURE, + WindowManager.LayoutParams.FLAG_SECURE + ) + } else { + (context as? FragmentActivity)?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) + } + } } SectionSpacer() diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt index a92f1fa387..048ce68454 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt @@ -381,12 +381,18 @@ fun SettingsActionItem(icon: ImageVector, text: String, click: (() -> Unit)? = n } @Composable -fun SettingsPreferenceItem(icon: ImageVector, text: String, pref: SharedPreference, prefState: MutableState? = null) { +fun SettingsPreferenceItem( + icon: ImageVector, + text: String, + pref: SharedPreference, + prefState: MutableState? = null, + onChange: ((Boolean) -> Unit)? = null, +) { SectionItemView { Row(verticalAlignment = Alignment.CenterVertically) { Icon(icon, text, tint = HighOrLowlight) Spacer(Modifier.padding(horizontal = 4.dp)) - SharedPreferenceToggle(text, pref, prefState) + SharedPreferenceToggle(text, pref, prefState, onChange) } } }