From 869ecb832ebc280a9f12d68903d2f102a3e4a53b Mon Sep 17 00:00:00 2001 From: Aman Raj Singh Mourya Date: Tue, 23 Jul 2024 23:30:36 +0530 Subject: [PATCH] [mob][auth] Minor fixes and used better names --- .../lock_screen/lock_screen_options.dart | 48 +++++++------------ auth/lib/utils/lock_screen_settings.dart | 18 ++++--- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/auth/lib/ui/settings/lock_screen/lock_screen_options.dart b/auth/lib/ui/settings/lock_screen/lock_screen_options.dart index 685cc384db..ed75a47e65 100644 --- a/auth/lib/ui/settings/lock_screen/lock_screen_options.dart +++ b/auth/lib/ui/settings/lock_screen/lock_screen_options.dart @@ -31,12 +31,12 @@ class _LockScreenOptionsState extends State { bool isPinEnabled = false; bool isPasswordEnabled = false; late int autoLockTimeInMilliseconds; - bool showAppContent = true; + late bool hideAppContent; @override void initState() { super.initState(); - showAppContent = _lockscreenSetting.getShouldShowAppContent(); + hideAppContent = _lockscreenSetting.getShouldHideAppContent(); autoLockTimeInMilliseconds = _lockscreenSetting.getAutoLockTime(); _initializeSettings(); appLock = isPinEnabled || @@ -47,12 +47,12 @@ class _LockScreenOptionsState extends State { Future _initializeSettings() async { final bool passwordEnabled = await _lockscreenSetting.isPasswordSet(); final bool pinEnabled = await _lockscreenSetting.isPinSet(); - final bool shouldShowAppContent = - _lockscreenSetting.getShouldShowAppContent(); + final bool shouldHideAppContent = + _lockscreenSetting.getShouldHideAppContent(); setState(() { isPasswordEnabled = passwordEnabled; isPinEnabled = pinEnabled; - showAppContent = shouldShowAppContent; + hideAppContent = shouldHideAppContent; }); } @@ -102,7 +102,7 @@ class _LockScreenOptionsState extends State { await _configuration.setSystemLockScreen(!appLock); await _lockscreenSetting.removePinAndPassword(); if (appLock == true) { - await _lockscreenSetting.shouldShowAppContent(showAppContent: true); + await _lockscreenSetting.shouldHideAppContent(isContentVisible: false); } setState(() { _initializeSettings(); @@ -123,14 +123,13 @@ class _LockScreenOptionsState extends State { ); } - Future _onShowContent() async { - showAppContent = _lockscreenSetting.getShouldShowAppContent(); - await _lockscreenSetting.shouldShowAppContent( - showAppContent: !showAppContent, - ); + Future _onHideContent() async { setState(() { - showAppContent = !showAppContent; + hideAppContent = !hideAppContent; }); + await _lockscreenSetting.shouldHideAppContent( + isContentVisible: hideAppContent, + ); } String _formatTime(Duration duration) { @@ -290,27 +289,14 @@ class _LockScreenOptionsState extends State { ), PlatformUtil.isMobile() ? Column( + crossAxisAlignment: + CrossAxisAlignment.start, children: [ const SizedBox(height: 24), - MenuItemWidget( - captionedTextWidget: - CaptionedTextWidget( - title: - "App content in Task switcher", - textStyle: - textTheme.small.copyWith( - color: colorTheme.textMuted, - ), - ), - isBottomBorderRadiusRemoved: true, - alignCaptionedTextToLeft: true, - menuItemColor: - colorTheme.fillFaint, - ), MenuItemWidget( captionedTextWidget: const CaptionedTextWidget( - title: "Show Content", + title: "Hide Content", ), alignCaptionedTextToLeft: true, isTopBorderRadiusRemoved: true, @@ -318,9 +304,9 @@ class _LockScreenOptionsState extends State { colorTheme.fillFaint, trailingWidget: ToggleSwitchWidget( - value: () => showAppContent, + value: () => hideAppContent, onChanged: () => - _onShowContent(), + _onHideContent(), ), ), Padding( @@ -330,7 +316,7 @@ class _LockScreenOptionsState extends State { right: 12, ), child: Text( - "If disabled app content will be displayed in the task switcher", + "Hides app content in the app switcher", style: textTheme.miniFaint, textAlign: TextAlign.left, ), diff --git a/auth/lib/utils/lock_screen_settings.dart b/auth/lib/utils/lock_screen_settings.dart index 9415e3828d..bd19582280 100644 --- a/auth/lib/utils/lock_screen_settings.dart +++ b/auth/lib/utils/lock_screen_settings.dart @@ -19,7 +19,7 @@ class LockScreenSettings { static const keyInvalidAttempts = "ls_invalid_attempts"; static const lastInvalidAttemptTime = "ls_last_invalid_attempt_time"; static const autoLockTime = "ls_auto_lock_time"; - static const keyShowAppContent = "ls_show_app_content"; + static const keyHideAppContent = "ls_show_app_content"; final List autoLockDurations = const [ Duration(seconds: 0), Duration(seconds: 5), @@ -35,16 +35,19 @@ class LockScreenSettings { Future init() async { _secureStorage = const FlutterSecureStorage(); _preferences = await SharedPreferences.getInstance(); + await shouldHideAppContent(isContentVisible: getShouldHideAppContent()); } - Future shouldShowAppContent({bool showAppContent = true}) async { + Future shouldHideAppContent({bool isContentVisible = true}) async { final brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness; bool isInDarkMode = brightness == Brightness.dark; - showAppContent + !isContentVisible ? PrivacyScreen.instance.disable() : await PrivacyScreen.instance.enable( - iosOptions: const PrivacyIosOptions(), + iosOptions: const PrivacyIosOptions( + enablePrivacy: true, + ), androidOptions: const PrivacyAndroidOptions( enableSecure: true, ), @@ -53,11 +56,11 @@ class LockScreenSettings { ? PrivacyBlurEffect.dark : PrivacyBlurEffect.extraLight, ); - await _preferences.setBool(keyShowAppContent, showAppContent); + await _preferences.setBool(keyHideAppContent, isContentVisible); } - bool getShouldShowAppContent() { - return _preferences.getBool(keyShowAppContent) ?? true; + bool getShouldHideAppContent() { + return _preferences.getBool(keyHideAppContent) ?? false; } Future setAutoLockTime(Duration duration) async { @@ -146,6 +149,7 @@ class LockScreenSettings { await _secureStorage.delete(key: saltKey); await _secureStorage.delete(key: pin); await _secureStorage.delete(key: password); + await _preferences.remove(keyHideAppContent); } Future isPinSet() async {