[mob][auth] Minor fixes and used better names

This commit is contained in:
Aman Raj Singh Mourya
2024-07-23 23:30:36 +05:30
parent a73de2848e
commit 869ecb832e
2 changed files with 28 additions and 38 deletions

View File

@@ -31,12 +31,12 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
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<LockScreenOptions> {
Future<void> _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<LockScreenOptions> {
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<LockScreenOptions> {
);
}
Future<void> _onShowContent() async {
showAppContent = _lockscreenSetting.getShouldShowAppContent();
await _lockscreenSetting.shouldShowAppContent(
showAppContent: !showAppContent,
);
Future<void> _onHideContent() async {
setState(() {
showAppContent = !showAppContent;
hideAppContent = !hideAppContent;
});
await _lockscreenSetting.shouldHideAppContent(
isContentVisible: hideAppContent,
);
}
String _formatTime(Duration duration) {
@@ -290,27 +289,14 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
),
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<LockScreenOptions> {
colorTheme.fillFaint,
trailingWidget:
ToggleSwitchWidget(
value: () => showAppContent,
value: () => hideAppContent,
onChanged: () =>
_onShowContent(),
_onHideContent(),
),
),
Padding(
@@ -330,7 +316,7 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
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,
),

View File

@@ -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<Duration> autoLockDurations = const [
Duration(seconds: 0),
Duration(seconds: 5),
@@ -35,16 +35,19 @@ class LockScreenSettings {
Future<void> init() async {
_secureStorage = const FlutterSecureStorage();
_preferences = await SharedPreferences.getInstance();
await shouldHideAppContent(isContentVisible: getShouldHideAppContent());
}
Future<void> shouldShowAppContent({bool showAppContent = true}) async {
Future<void> 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<void> 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<bool> isPinSet() async {