[mob][auth] Added Auto lock UI
This commit is contained in:
141
auth/lib/ui/settings/lock_screen/lock_screen_auto_lock.dart
Normal file
141
auth/lib/ui/settings/lock_screen/lock_screen_auto_lock.dart
Normal file
@@ -0,0 +1,141 @@
|
||||
import 'package:ente_auth/theme/ente_theme.dart';
|
||||
import 'package:ente_auth/ui/components/captioned_text_widget.dart';
|
||||
import 'package:ente_auth/ui/components/divider_widget.dart';
|
||||
import 'package:ente_auth/ui/components/menu_item_widget.dart';
|
||||
import 'package:ente_auth/ui/components/separators.dart';
|
||||
import 'package:ente_auth/ui/components/title_bar_title_widget.dart';
|
||||
import 'package:ente_auth/ui/components/title_bar_widget.dart';
|
||||
import 'package:ente_auth/utils/lock_screen_settings.dart';
|
||||
import 'package:flutter/material.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 autoLockDurations = LockScreenSettings.instance.autoLockDurations;
|
||||
List<Widget> items = [];
|
||||
late Duration currentAutoLockTime;
|
||||
@override
|
||||
void initState() {
|
||||
for (Duration autoLockDuration in autoLockDurations) {
|
||||
if (autoLockDuration.inMilliseconds ==
|
||||
LockScreenSettings.instance.getAutoLockTime()) {
|
||||
currentAutoLockTime = autoLockDuration;
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import "dart:async";
|
||||
|
||||
import "package:ente_auth/core/configuration.dart";
|
||||
import "package:ente_auth/theme/ente_theme.dart";
|
||||
import "package:ente_auth/ui/components/captioned_text_widget.dart";
|
||||
@@ -6,10 +8,12 @@ import "package:ente_auth/ui/components/menu_item_widget.dart";
|
||||
import "package:ente_auth/ui/components/title_bar_title_widget.dart";
|
||||
import "package:ente_auth/ui/components/title_bar_widget.dart";
|
||||
import "package:ente_auth/ui/components/toggle_switch_widget.dart";
|
||||
import "package:ente_auth/ui/settings/lock_screen/lock_screen_auto_lock.dart";
|
||||
import "package:ente_auth/ui/settings/lock_screen/lock_screen_password.dart";
|
||||
import "package:ente_auth/ui/settings/lock_screen/lock_screen_pin.dart";
|
||||
import "package:ente_auth/ui/tools/app_lock.dart";
|
||||
import "package:ente_auth/utils/lock_screen_settings.dart";
|
||||
import "package:ente_auth/utils/navigation_util.dart";
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
class LockScreenOptions extends StatefulWidget {
|
||||
@@ -95,6 +99,22 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _onAutoLock() async {
|
||||
routeToPage(context, LockScreenAutoLock());
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorTheme = getEnteColorScheme(context);
|
||||
|
||||
@@ -10,6 +10,16 @@ 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";
|
||||
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),
|
||||
];
|
||||
|
||||
late SharedPreferences _preferences;
|
||||
|
||||
@@ -17,6 +27,14 @@ class LockScreenSettings {
|
||||
_preferences = await SharedPreferences.getInstance();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user