Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Auto lock options fixes

Aman Raj Singh Mourya82f3cd19bea2
diff --git a/mobile/lib/ui/settings/lock_screen/lock_screen_auto_lock.dart b/mobile/lib/ui/settings/lock_screen/lock_screen_auto_lock.dart
index 1a26ab5736..26682f4a2c 100644
--- a/mobile/lib/ui/settings/lock_screen/lock_screen_auto_lock.dart
+++ b/mobile/lib/ui/settings/lock_screen/lock_screen_auto_lock.dart
@@ -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";
}
}
}
diff --git a/mobile/lib/ui/settings/lock_screen/lock_screen_options.dart b/mobile/lib/ui/settings/lock_screen/lock_screen_options.dart
index 362f745d27..0084c263ef 100644
--- a/mobile/lib/ui/settings/lock_screen/lock_screen_options.dart
+++ b/mobile/lib/ui/settings/lock_screen/lock_screen_options.dart
@@ -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,
diff --git a/mobile/lib/ui/settings/security_section_widget.dart b/mobile/lib/ui/settings/security_section_widget.dart
index 60471593f2..dc8a5cac62 100644
--- a/mobile/lib/ui/settings/security_section_widget.dart
+++ b/mobile/lib/ui/settings/security_section_widget.dart
@@ -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();
}
diff --git a/mobile/lib/utils/lock_screen_settings.dart b/mobile/lib/utils/lock_screen_settings.dart
index 6487fb47f0..e975321d7f 100644
--- a/mobile/lib/utils/lock_screen_settings.dart
+++ b/mobile/lib/utils/lock_screen_settings.dart
@@ -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() {