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

View File

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

View File

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

View File

@@ -3,6 +3,7 @@ import "dart:convert";
import "package:flutter/foundation.dart"; import "package:flutter/foundation.dart";
import "package:flutter_secure_storage/flutter_secure_storage.dart"; import "package:flutter_secure_storage/flutter_secure_storage.dart";
import "package:flutter_sodium/flutter_sodium.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:photos/utils/crypto_util.dart";
import "package:shared_preferences/shared_preferences.dart"; import "package:shared_preferences/shared_preferences.dart";
@@ -20,7 +21,7 @@ class LockScreenSettings {
static const appLockType = "ls_app_lock_type"; static const appLockType = "ls_app_lock_type";
late FlutterSecureStorage _secureStorage; late FlutterSecureStorage _secureStorage;
late SharedPreferences _preferences; late SharedPreferences _preferences;
final List<Duration> autoLockDurations = const [ static const List<Duration> autoLockDurations = [
Duration(seconds: 0), Duration(seconds: 0),
Duration(seconds: 30), Duration(seconds: 30),
Duration(minutes: 1), Duration(minutes: 1),
@@ -34,8 +35,20 @@ class LockScreenSettings {
_preferences = prefs; _preferences = prefs;
} }
Future<void> setAppLockType(String lockType) async { Future<void> setAppLockType(AppLockUpdateType lockType) async {
await _preferences.setString(appLockType, lockType); 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() { String getAppLockType() {