[mob][photos] Auto lock options fixes

This commit is contained in:
Aman Raj Singh Mourya 2024-07-15 12:02:54 +05:30
parent fd2c22dc5f
commit 82f3cd19be
4 changed files with 35 additions and 16 deletions

View File

@ -67,19 +67,20 @@ class AutoLockItems extends StatefulWidget {
}
class _AutoLockItemsState extends State<AutoLockItems> {
final autoLockDurations = LockScreenSettings.instance.autoLockDurations;
final autoLockDurations = LockScreenSettings.autoLockDurations;
final autoLockTimeInMilliseconds =
LockScreenSettings.instance.getAutoLockTime();
List<Widget> items = [];
late Duration currentAutoLockTime;
@override
void initState() {
super.initState();
for (Duration autoLockDuration in autoLockDurations) {
if (autoLockDuration.inMilliseconds ==
LockScreenSettings.instance.getAutoLockTime()) {
if (autoLockDuration.inMilliseconds == autoLockTimeInMilliseconds) {
currentAutoLockTime = autoLockDuration;
break;
}
}
super.initState();
}
@override
@ -135,7 +136,7 @@ class _AutoLockItemsState extends State<AutoLockItems> {
} else if (duration.inSeconds != 0) {
return "${duration.inSeconds}s";
} else {
return "Disable";
return "Disabled";
}
}
}

View File

@ -53,7 +53,7 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
Future<void> _deviceLock() async {
await _lockscreenSetting.removePinAndPassword();
await _initializeSettings();
await _lockscreenSetting.setAppLockType("Device lock");
await _lockscreenSetting.setAppLockType(AppLockUpdateType.device);
Bus.instance.fire(
AppLockUpdateEvent(
AppLockUpdateType.device,
@ -77,7 +77,7 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
AppLockUpdateType.pin,
),
);
_lockscreenSetting.setAppLockType("Pin");
_lockscreenSetting.setAppLockType(AppLockUpdateType.pin);
appLock = isPinEnabled ||
isPasswordEnabled ||
_configuration.shouldShowSystemLockScreen();
@ -101,7 +101,7 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
AppLockUpdateType.password,
),
);
_lockscreenSetting.setAppLockType("Password");
_lockscreenSetting.setAppLockType(AppLockUpdateType.password);
appLock = isPinEnabled ||
isPasswordEnabled ||
_configuration.shouldShowSystemLockScreen();
@ -124,7 +124,9 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
AppLock.of(context)!.setEnabled(!appLock);
await _configuration.setSystemLockScreen(!appLock);
await _lockscreenSetting.removePinAndPassword();
await _lockscreenSetting.setAppLockType(appLock ? "None" : "Device lock");
await _lockscreenSetting.setAppLockType(
appLock ? AppLockUpdateType.none : AppLockUpdateType.device,
);
Bus.instance.fire(
AppLockUpdateEvent(
appLock ? AppLockUpdateType.none : AppLockUpdateType.device,
@ -144,7 +146,7 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
} else if (duration.inSeconds != 0) {
return "in ${duration.inSeconds} second${duration.inSeconds > 1 ? 's' : ''}";
} else {
return "Disable";
return "Disabled";
}
}
@ -270,6 +272,8 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
),
),
),
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
alignCaptionedTextToLeft: true,
singleBorderRadius: 8,
menuItemColor: colorTheme.fillFaint,

View File

@ -43,13 +43,14 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
late String appLockSubtitle;
late StreamSubscription<TwoFactorStatusChangeEvent>
_twoFactorStatusChangeEvent;
late StreamSubscription<AppLockUpdateEvent> _appLockUpdateEvent;
late StreamSubscription<AppLockUpdateEvent> _appLockUpdateEventSubscription;
final Logger _logger = Logger('SecuritySectionWidget');
@override
void initState() {
super.initState();
appLockSubtitle = LockScreenSettings.instance.getAppLockType();
_appLockUpdateEvent = Bus.instance.on<AppLockUpdateEvent>().listen((event) {
_appLockUpdateEventSubscription =
Bus.instance.on<AppLockUpdateEvent>().listen((event) {
if (mounted) {
setState(() {
appLockSubtitle = LockScreenSettings.instance.getAppLockType();
@ -66,7 +67,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
@override
void dispose() {
_appLockUpdateEvent.cancel();
_appLockUpdateEventSubscription.cancel();
_twoFactorStatusChangeEvent.cancel();
super.dispose();
}

View File

@ -3,6 +3,7 @@ import "dart:convert";
import "package:flutter/foundation.dart";
import "package:flutter_secure_storage/flutter_secure_storage.dart";
import "package:flutter_sodium/flutter_sodium.dart";
import "package:photos/events/app_lock_update_event.dart";
import "package:photos/utils/crypto_util.dart";
import "package:shared_preferences/shared_preferences.dart";
@ -20,7 +21,7 @@ class LockScreenSettings {
static const appLockType = "ls_app_lock_type";
late FlutterSecureStorage _secureStorage;
late SharedPreferences _preferences;
final List<Duration> autoLockDurations = const [
static const List<Duration> autoLockDurations = [
Duration(seconds: 0),
Duration(seconds: 30),
Duration(minutes: 1),
@ -34,8 +35,20 @@ class LockScreenSettings {
_preferences = prefs;
}
Future<void> setAppLockType(String lockType) async {
await _preferences.setString(appLockType, lockType);
Future<void> setAppLockType(AppLockUpdateType lockType) async {
switch (lockType) {
case AppLockUpdateType.device:
await _preferences.setString(appLockType, "Device lock");
break;
case AppLockUpdateType.pin:
await _preferences.setString(appLockType, "Pin");
break;
case AppLockUpdateType.password:
await _preferences.setString(appLockType, "Password");
default:
await _preferences.setString(appLockType, "None");
break;
}
}
String getAppLockType() {