π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Implemented Auto lock options
Aman Raj Singh Mourya4af03ad2ddae
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.dartnew file mode 100644index 0000000000..65950043bc--- /dev/null+++ b/mobile/lib/ui/settings/lock_screen/lock_screen_auto_lock.dart@@ -0,0 +1,149 @@+import "package:flutter/material.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/components/captioned_text_widget.dart";+import "package:photos/ui/components/divider_widget.dart";+import "package:photos/ui/components/menu_item_widget/menu_item_widget.dart";+import "package:photos/ui/components/title_bar_title_widget.dart";+import "package:photos/ui/components/title_bar_widget.dart";+import "package:photos/utils/lock_screen_settings.dart";+import "package:photos/utils/separators_util.dart";++class LockScreenAutoLock extends StatefulWidget {+ const LockScreenAutoLock({super.key});++ @override+ State<LockScreenAutoLock> createState() => _LockScreenAutoLockState();+}++class _LockScreenAutoLockState extends State<LockScreenAutoLock> {+ @override+ Widget build(BuildContext context) {+ return Scaffold(+ body: CustomScrollView(+ primary: false,+ slivers: <Widget>[+ const TitleBarWidget(+ flexibleSpaceTitle: TitleBarTitleWidget(+ title: "Auto lock",+ ),+ ),+ SliverList(+ delegate: SliverChildBuilderDelegate(+ (context, index) {+ return const Padding(+ padding: EdgeInsets.symmetric(+ horizontal: 16,+ vertical: 20,+ ),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ Column(+ children: [+ ClipRRect(+ borderRadius: BorderRadius.all(Radius.circular(8)),+ child: AutoLockItems(),+ ),+ ],+ ),+ ],+ ),+ );+ },+ childCount: 1,+ ),+ ),+ ],+ ),+ );+ }+}++class AutoLockItems extends StatefulWidget {+ const AutoLockItems({super.key});++ @override+ State<AutoLockItems> createState() => _AutoLockItemsState();+}++class _AutoLockItemsState extends State<AutoLockItems> {+ final List<Duration> autoLockDurations = const [+ Duration(seconds: 0),+ Duration(seconds: 30),+ Duration(minutes: 1),+ Duration(minutes: 5),+ Duration(minutes: 15),+ Duration(minutes: 30),+ Duration(hours: 1),+ ];+ List<Widget> items = [];+ late Duration currentAutoLockTime;+ @override+ void initState() {+ for (int i = 0; i < autoLockDurations.length; i++) {+ if (autoLockDurations[i].inMilliseconds ==+ LockScreenSettings.instance.getAutoLockTime()) {+ currentAutoLockTime = autoLockDurations[i];+ break;+ }+ }+ super.initState();+ }++ @override+ Widget build(BuildContext context) {+ items.clear();+ for (Duration autoLockDuration in autoLockDurations) {+ items.add(+ _menuItemForPicker(autoLockDuration),+ );+ }+ items = addSeparators(+ items,+ DividerWidget(+ dividerType: DividerType.menuNoIcon,+ bgColor: getEnteColorScheme(context).fillFaint,+ ),+ );+ return Column(+ mainAxisSize: MainAxisSize.min,+ children: items,+ );+ }++ Widget _menuItemForPicker(Duration autoLockTime) {+ return MenuItemWidget(+ key: ValueKey(autoLockTime),+ menuItemColor: getEnteColorScheme(context).fillFaint,+ captionedTextWidget: CaptionedTextWidget(+ title: _formatTime(autoLockTime),+ ),+ trailingIcon: currentAutoLockTime == autoLockTime ? Icons.check : null,+ alignCaptionedTextToLeft: true,+ isTopBorderRadiusRemoved: true,+ isBottomBorderRadiusRemoved: true,+ showOnlyLoadingState: true,+ onTap: () async {+ await LockScreenSettings.instance.setAutoLockTime(autoLockTime).then(+ (value) => {+ setState(() {+ currentAutoLockTime = autoLockTime;+ }),+ },+ );+ },+ );+ }++ String _formatTime(Duration duration) {+ if (duration.inHours != 0) {+ return "${duration.inHours}hr";+ } else if (duration.inMinutes != 0) {+ return "${duration.inMinutes}m";+ } else if (duration.inSeconds != 0) {+ return "${duration.inSeconds}s";+ } else {+ return "Disable";+ }+ }+}diff --git a/mobile/lib/ui/settings/lock_screen/lock_screen_options.dart b/mobile/lib/ui/settings/lock_screen/lock_screen_options.dartindex be57aae3e5..e15bf8ba86 100644--- a/mobile/lib/ui/settings/lock_screen/lock_screen_options.dart+++ b/mobile/lib/ui/settings/lock_screen/lock_screen_options.dart@@ -8,10 +8,12 @@ import "package:photos/ui/components/menu_item_widget/menu_item_widget.dart";import "package:photos/ui/components/title_bar_title_widget.dart";import "package:photos/ui/components/title_bar_widget.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";+import "package:photos/utils/navigation_util.dart";class LockScreenOptions extends StatefulWidget {const LockScreenOptions({super.key});@@ -26,10 +28,11 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {late bool appLock;bool isPinEnabled = false;bool isPasswordEnabled = false;-+ late int autoLockTimeInMilliseconds;@overridevoid initState() {super.initState();+ autoLockTimeInMilliseconds = _lockscreenSetting.getAutoLockTime();_initializeSettings();appLock = isPinEnabled ||isPasswordEnabled ||@@ -86,6 +89,17 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {});}+ Future<void> _onAutolock() async {+ await routeToPage(+ context,+ const LockScreenAutoLock(),+ ).then((value) {+ setState(() {+ autoLockTimeInMilliseconds = _lockscreenSetting.getAutoLockTime();+ });+ });+ }+Future<void> _onToggleSwitch() async {AppLock.of(context)!.setEnabled(!appLock);await _configuration.setSystemLockScreen(!appLock);@@ -96,6 +110,18 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {});}+ String _formatTime(Duration duration) {+ if (duration.inHours != 0) {+ return "${duration.inHours}hr";+ } else if (duration.inMinutes != 0) {+ return "${duration.inMinutes}m";+ } else if (duration.inSeconds != 0) {+ return "${duration.inSeconds}s";+ } else {+ return "Disable";+ }+ }+@overrideWidget build(BuildContext context) {final colorTheme = getEnteColorScheme(context);@@ -204,6 +230,25 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {trailingIconColor: colorTheme.tabIcon,onTap: () => _passwordLock(),),+ const SizedBox(+ height: 24,+ ),+ MenuItemWidget(+ captionedTextWidget: CaptionedTextWidget(+ title: "Auto lock",+ subTitle: _formatTime(+ Duration(+ milliseconds: _lockscreenSetting+ .getAutoLockTime(),+ ),+ ),+ ),+ alignCaptionedTextToLeft: true,+ singleBorderRadius: 8,+ menuItemColor: colorTheme.fillFaint,+ trailingIconColor: colorTheme.tabIcon,+ onTap: () => _onAutolock(),+ ),],): Container(),diff --git a/mobile/lib/utils/lock_screen_settings.dart b/mobile/lib/utils/lock_screen_settings.dartindex 13772d5224..e710cb55a5 100644--- a/mobile/lib/utils/lock_screen_settings.dart+++ b/mobile/lib/utils/lock_screen_settings.dart@@ -16,6 +16,7 @@ class LockScreenSettings {static const saltKey = "ls_salt";static const keyInvalidAttempts = "ls_invalid_attempts";static const lastInvalidAttemptTime = "ls_last_invalid_attempt_time";+ static const autoLockTime = "ls_auto_lock_time";late FlutterSecureStorage _secureStorage;late SharedPreferences _preferences;@@ -24,6 +25,14 @@ class LockScreenSettings {_preferences = prefs;}+ Future<void> setAutoLockTime(Duration duration) async {+ await _preferences.setInt(autoLockTime, duration.inMilliseconds);+ }++ int getAutoLockTime() {+ return _preferences.getInt(autoLockTime) ?? 0;+ }+Future<void> setLastInvalidAttemptTime(int time) async {await _preferences.setInt(lastInvalidAttemptTime, time);}