π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add lock type selection to app lock
Neeraj Gupta872859138b49
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex 59bc476c9f..3083572781 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -1425,6 +1425,7 @@"enterPin": "Enter PIN","setNewPin": "Set new PIN","appLock": "App lock",+ "lockScreenType": "Lock type","noSystemLockFound": "No system lock found","tapToUnlock": "Tap to unlock","tooManyIncorrectAttempts": "Too many incorrect attempts",diff --git a/mobile/apps/photos/lib/ui/settings/lock_screen/lock_screen_options.dart b/mobile/apps/photos/lib/ui/settings/lock_screen/lock_screen_options.dartindex 1378bae2f6..abc7186e63 100644--- a/mobile/apps/photos/lib/ui/settings/lock_screen/lock_screen_options.dart+++ b/mobile/apps/photos/lib/ui/settings/lock_screen/lock_screen_options.dart@@ -1,11 +1,15 @@import "dart:io";+import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/material.dart";import "package:photos/core/configuration.dart";import "package:photos/generated/l10n.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/components/menu_item_widget/menu_item_widget_new.dart";import "package:photos/ui/components/toggle_switch_widget.dart";+import "package:photos/ui/settings/lock_screen/lock_screen_auto_lock.dart";+import "package:photos/ui/settings/lock_screen/lock_screen_password.dart";+import "package:photos/ui/settings/lock_screen/lock_screen_pin.dart";import "package:photos/ui/tools/app_lock.dart";import "package:photos/utils/lock_screen_settings.dart";@@ -16,11 +20,14 @@ class LockScreenOptions extends StatefulWidget {State<LockScreenOptions> createState() => _LockScreenOptionsState();}+enum LockType { device, pin, password }+class _LockScreenOptionsState extends State<LockScreenOptions> {final Configuration _configuration = Configuration.instance;final LockScreenSettings _lockscreenSetting = LockScreenSettings.instance;late bool appLock;late bool hideAppContent;+ LockType _currentLockType = LockType.device;@overridevoid initState() {@@ -35,8 +42,17 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {final bool pinEnabled = await _lockscreenSetting.isPinSet();final bool shouldShowAppContent =_lockscreenSetting.getShouldHideAppContent();++ LockType lockType = LockType.device;+ if (pinEnabled) {+ lockType = LockType.pin;+ } else if (passwordEnabled) {+ lockType = LockType.password;+ }+setState(() {hideAppContent = shouldShowAppContent;+ _currentLockType = lockType;appLock = pinEnabled ||passwordEnabled ||_configuration.shouldShowSystemLockScreen();@@ -44,15 +60,69 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {}Future<void> _onToggleSwitch() async {- AppLock.of(context)!.setEnabled(!appLock);- await _configuration.setSystemLockScreen(!appLock);+ if (appLock) {+ // Turning off app lock+ AppLock.of(context)!.setEnabled(false);+ await _configuration.setSystemLockScreen(false);+ await _lockscreenSetting.removePinAndPassword();+ setState(() {+ appLock = false;+ _currentLockType = LockType.device;+ });+ } else {+ // Turning on app lock - default to device lock+ AppLock.of(context)!.setEnabled(true);+ await _configuration.setSystemLockScreen(true);+ setState(() {+ appLock = true;+ _currentLockType = LockType.device;+ });+ }+ }++ Future<void> _onSelectDeviceLock() async {+ // Remove any existing PIN/password and use device lockawait _lockscreenSetting.removePinAndPassword();+ await _configuration.setSystemLockScreen(true);+ AppLock.of(context)!.setEnabled(true);setState(() {- _initializeSettings();- appLock = !appLock;+ _currentLockType = LockType.device;});}+ Future<void> _onSelectPinLock() async {+ final result = await routeToPage(+ context,+ const LockScreenPin(),+ );+ if (result == true) {+ await _configuration.setSystemLockScreen(false);+ setState(() {+ _currentLockType = LockType.pin;+ });+ }+ await _initializeSettings();+ }++ Future<void> _onSelectPasswordLock() async {+ final result = await routeToPage(+ context,+ const LockScreenPassword(),+ );+ if (result == true) {+ await _configuration.setSystemLockScreen(false);+ setState(() {+ _currentLockType = LockType.password;+ });+ }+ await _initializeSettings();+ }++ Future<void> _onAutoLockTap() async {+ await routeToPage(context, const LockScreenAutoLock());+ setState(() {});+ }+Future<void> _tapHideContent() async {setState(() {hideAppContent = !hideAppContent;@@ -62,6 +132,17 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {);}+ String _formatAutoLockTime(int milliseconds) {+ final duration = Duration(milliseconds: milliseconds);+ if (duration.inMinutes >= 1) {+ return "${duration.inMinutes}m";+ } else if (duration.inSeconds >= 1) {+ return "${duration.inSeconds}s";+ } else {+ return AppLocalizations.of(context).immediately;+ }+ }+@overrideWidget build(BuildContext context) {final colorScheme = getEnteColorScheme(context);@@ -119,6 +200,72 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {),),),+ if (appLock) ...[+ const SizedBox(height: 24),+ Text(+ AppLocalizations.of(context).lockScreenType,+ style: textTheme.small.copyWith(+ fontWeight: FontWeight.w600,+ ),+ ),+ const SizedBox(height: 8),+ MenuItemWidgetNew(+ title: AppLocalizations.of(context).deviceLock,+ trailingIcon: _currentLockType == LockType.device+ ? Icons.check+ : null,+ onTap: () async => _onSelectDeviceLock(),+ ),+ const SizedBox(height: 8),+ MenuItemWidgetNew(+ title: AppLocalizations.of(context).pinLock,+ trailingIcon: _currentLockType == LockType.pin+ ? Icons.check+ : null,+ onTap: () async => _onSelectPinLock(),+ ),+ const SizedBox(height: 8),+ MenuItemWidgetNew(+ title: AppLocalizations.of(context).passwordLock,+ trailingIcon: _currentLockType == LockType.password+ ? Icons.check+ : null,+ onTap: () async => _onSelectPasswordLock(),+ ),+ const SizedBox(height: 16),+ MenuItemWidgetNew(+ title: AppLocalizations.of(context).autoLock,+ trailingWidget: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(+ _formatAutoLockTime(+ _lockscreenSetting.getAutoLockTime(),+ ),+ style: textTheme.small.copyWith(+ color: colorScheme.textMuted,+ ),+ ),+ const SizedBox(width: 4),+ Icon(+ Icons.chevron_right,+ color: colorScheme.strokeMuted,+ ),+ ],+ ),+ onTap: () async => _onAutoLockTap(),+ ),+ Padding(+ padding: const EdgeInsets.only(top: 8),+ child: Text(+ AppLocalizations.of(context)+ .autoLockFeatureDescription,+ style: textTheme.mini.copyWith(+ color: colorScheme.textMuted,+ ),+ ),+ ),+ ],const SizedBox(height: 16),MenuItemWidgetNew(title: AppLocalizations.of(context).hideContent,