Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Auto lock implemented and UI fixes

Aman Raj Singh Mouryafd2c22dc5ff4
diff --git a/mobile/lib/events/app_lock_update_event.dart b/mobile/lib/events/app_lock_update_event.dart
new file mode 100644
index 0000000000..48383344fa
--- /dev/null
+++ b/mobile/lib/events/app_lock_update_event.dart
@@ -0,0 +1,14 @@
+import "package:photos/events/event.dart";
+
+enum AppLockUpdateType {
+ none,
+ device,
+ pin,
+ password,
+}
+
+class AppLockUpdateEvent extends Event {
+ final AppLockUpdateType type;
+
+ AppLockUpdateEvent(this.type);
+}
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 e15bf8ba86..362f745d27 100644
--- a/mobile/lib/ui/settings/lock_screen/lock_screen_options.dart
+++ b/mobile/lib/ui/settings/lock_screen/lock_screen_options.dart
@@ -1,5 +1,7 @@
import "package:flutter/material.dart";
import "package:photos/core/configuration.dart";
+import "package:photos/core/event_bus.dart";
+import "package:photos/events/app_lock_update_event.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/components/captioned_text_widget.dart";
@@ -51,6 +53,12 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
Future<void> _deviceLock() async {
await _lockscreenSetting.removePinAndPassword();
await _initializeSettings();
+ await _lockscreenSetting.setAppLockType("Device lock");
+ Bus.instance.fire(
+ AppLockUpdateEvent(
+ AppLockUpdateType.device,
+ ),
+ );
}
Future<void> _pinLock() async {
@@ -64,6 +72,12 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
setState(() {
_initializeSettings();
if (result) {
+ Bus.instance.fire(
+ AppLockUpdateEvent(
+ AppLockUpdateType.pin,
+ ),
+ );
+ _lockscreenSetting.setAppLockType("Pin");
appLock = isPinEnabled ||
isPasswordEnabled ||
_configuration.shouldShowSystemLockScreen();
@@ -82,6 +96,12 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
setState(() {
_initializeSettings();
if (result) {
+ Bus.instance.fire(
+ AppLockUpdateEvent(
+ AppLockUpdateType.password,
+ ),
+ );
+ _lockscreenSetting.setAppLockType("Password");
appLock = isPinEnabled ||
isPasswordEnabled ||
_configuration.shouldShowSystemLockScreen();
@@ -104,6 +124,12 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
AppLock.of(context)!.setEnabled(!appLock);
await _configuration.setSystemLockScreen(!appLock);
await _lockscreenSetting.removePinAndPassword();
+ await _lockscreenSetting.setAppLockType(appLock ? "None" : "Device lock");
+ Bus.instance.fire(
+ AppLockUpdateEvent(
+ appLock ? AppLockUpdateType.none : AppLockUpdateType.device,
+ ),
+ );
setState(() {
_initializeSettings();
appLock = !appLock;
@@ -112,11 +138,11 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
String _formatTime(Duration duration) {
if (duration.inHours != 0) {
- return "${duration.inHours}hr";
+ return "in ${duration.inHours} hour${duration.inHours > 1 ? 's' : ''}";
} else if (duration.inMinutes != 0) {
- return "${duration.inMinutes}m";
+ return "in ${duration.inMinutes} minute${duration.inMinutes > 1 ? 's' : ''}";
} else if (duration.inSeconds != 0) {
- return "${duration.inSeconds}s";
+ return "in ${duration.inSeconds} second${duration.inSeconds > 1 ? 's' : ''}";
} else {
return "Disable";
}
@@ -180,6 +206,7 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
),
appLock
? Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
children: [
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
@@ -238,8 +265,8 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
title: "Auto lock",
subTitle: _formatTime(
Duration(
- milliseconds: _lockscreenSetting
- .getAutoLockTime(),
+ milliseconds:
+ autoLockTimeInMilliseconds,
),
),
),
@@ -249,6 +276,18 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
trailingIconColor: colorTheme.tabIcon,
onTap: () => _onAutolock(),
),
+ Padding(
+ padding: const EdgeInsets.only(
+ top: 14,
+ left: 14,
+ right: 12,
+ ),
+ child: Text(
+ "Require ${_lockscreenSetting.getAppLockType()} if away for some time .",
+ style: textTheme.miniFaint,
+ textAlign: TextAlign.left,
+ ),
+ ),
],
)
: Container(),
diff --git a/mobile/lib/ui/settings/security_section_widget.dart b/mobile/lib/ui/settings/security_section_widget.dart
index afb4f21abb..60471593f2 100644
--- a/mobile/lib/ui/settings/security_section_widget.dart
+++ b/mobile/lib/ui/settings/security_section_widget.dart
@@ -7,6 +7,7 @@ import "package:logging/logging.dart";
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/ente_theme_data.dart';
+import "package:photos/events/app_lock_update_event.dart";
import 'package:photos/events/two_factor_status_change_event.dart';
import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
@@ -26,6 +27,7 @@ import "package:photos/ui/settings/lock_screen/lock_screen_options.dart";
import "package:photos/utils/auth_util.dart";
import "package:photos/utils/crypto_util.dart";
import "package:photos/utils/dialog_util.dart";
+import "package:photos/utils/lock_screen_settings.dart";
import "package:photos/utils/navigation_util.dart";
import "package:photos/utils/toast_util.dart";
@@ -38,13 +40,22 @@ class SecuritySectionWidget extends StatefulWidget {
class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
final _config = Configuration.instance;
-
+ late String appLockSubtitle;
late StreamSubscription<TwoFactorStatusChangeEvent>
_twoFactorStatusChangeEvent;
+ late StreamSubscription<AppLockUpdateEvent> _appLockUpdateEvent;
final Logger _logger = Logger('SecuritySectionWidget');
@override
void initState() {
super.initState();
+ appLockSubtitle = LockScreenSettings.instance.getAppLockType();
+ _appLockUpdateEvent = Bus.instance.on<AppLockUpdateEvent>().listen((event) {
+ if (mounted) {
+ setState(() {
+ appLockSubtitle = LockScreenSettings.instance.getAppLockType();
+ });
+ }
+ });
_twoFactorStatusChangeEvent =
Bus.instance.on<TwoFactorStatusChangeEvent>().listen((event) async {
if (mounted) {
@@ -55,6 +66,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
@override
void dispose() {
+ _appLockUpdateEvent.cancel();
_twoFactorStatusChangeEvent.cancel();
super.dispose();
}
@@ -143,6 +155,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: S.of(context).appLock,
+ subTitle: appLockSubtitle,
),
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
diff --git a/mobile/lib/utils/lock_screen_settings.dart b/mobile/lib/utils/lock_screen_settings.dart
index 29a9ff1bf7..6487fb47f0 100644
--- a/mobile/lib/utils/lock_screen_settings.dart
+++ b/mobile/lib/utils/lock_screen_settings.dart
@@ -17,6 +17,7 @@ class LockScreenSettings {
static const keyInvalidAttempts = "ls_invalid_attempts";
static const lastInvalidAttemptTime = "ls_last_invalid_attempt_time";
static const autoLockTime = "ls_auto_lock_time";
+ static const appLockType = "ls_app_lock_type";
late FlutterSecureStorage _secureStorage;
late SharedPreferences _preferences;
final List<Duration> autoLockDurations = const [
@@ -33,6 +34,14 @@ class LockScreenSettings {
_preferences = prefs;
}
+ Future<void> setAppLockType(String lockType) async {
+ await _preferences.setString(appLockType, lockType);
+ }
+
+ String getAppLockType() {
+ return _preferences.getString(appLockType) ?? "None";
+ }
+
Future<void> setAutoLockTime(Duration duration) async {
await _preferences.setInt(autoLockTime, duration.inMilliseconds);
}