Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] function of the lockscreen completed

Aman Raj Singh Mourya53b1dc9b674a
diff --git a/mobile/lib/core/configuration.dart b/mobile/lib/core/configuration.dart
index 67c7299f0b..99df803869 100644
--- a/mobile/lib/core/configuration.dart
+++ b/mobile/lib/core/configuration.dart
@@ -175,6 +175,14 @@ class Configuration {
await _preferences.remove(password);
}
+ bool isPinSet() {
+ return _preferences.containsKey(pin);
+ }
+
+ bool isPasswordSet() {
+ return _preferences.containsKey(password);
+ }
+
// _cleanUpStaleFiles deletes all files in the temp directory that are older
// than kTempFolderDeletionTimeBuffer except the the temp encrypted files for upload.
// Those file are deleted by file uploader after the upload is complete or those
diff --git a/mobile/lib/services/local_authentication_service.dart b/mobile/lib/services/local_authentication_service.dart
index 9655d2da1a..0747048494 100644
--- a/mobile/lib/services/local_authentication_service.dart
+++ b/mobile/lib/services/local_authentication_service.dart
@@ -7,7 +7,6 @@ import "package:photos/generated/l10n.dart";
import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/dialog_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
-import "package:photos/ui/settings/TEMP/lock_screen_option.dart";
import "package:photos/ui/settings/TEMP/lock_screen_option_password.dart";
import "package:photos/ui/settings/TEMP/lock_screen_option_pin.dart";
import 'package:photos/ui/tools/app_lock.dart';
@@ -42,13 +41,7 @@ class LocalAuthenticationService {
return true;
}
- Future<bool> requestLocalAuthForLockScreen(
- BuildContext context,
- bool shouldEnableLockScreen,
- String infoMessage,
- String errorDialogContent, [
- String errorDialogTitle = "",
- ]) async {
+ Future<bool> requestEnteAuthForLockScreen(BuildContext context) async {
final String? savedPin = await _configuration.loadSavedPin();
final String? savedPassword = await _configuration.loadSavedPassword();
@@ -64,13 +57,6 @@ class LocalAuthenticationService {
),
);
if (result) {
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return const LockScreenOption();
- },
- ),
- );
return true;
} else {
await showDialogWidget(
@@ -88,9 +74,10 @@ class LocalAuthenticationService {
),
],
);
+ return false;
}
- return false;
- } else if (savedPin != null) {
+ }
+ if (savedPin != null) {
final result = await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
@@ -102,13 +89,6 @@ class LocalAuthenticationService {
),
);
if (result) {
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return const LockScreenOption();
- },
- ),
- );
return true;
} else {
await showDialogWidget(
@@ -126,9 +106,22 @@ class LocalAuthenticationService {
),
],
);
+ return false;
}
- return false;
}
+ return false;
+ }
+
+ Future<bool> requestLocalAuthForLockScreen(
+ BuildContext context,
+ bool shouldEnableLockScreen,
+ String infoMessage,
+ String errorDialogContent, [
+ String errorDialogTitle = "",
+ ]) async {
+ // if (await requestEnteAuthForLockScreen(context)) {
+ // return true;
+ // }
if (await _isLocalAuthSupportedOnDevice()) {
AppLock.of(context)!.disable();
@@ -140,15 +133,7 @@ class LocalAuthenticationService {
AppLock.of(context)!.setEnabled(shouldEnableLockScreen);
await Configuration.instance
.setShouldShowLockScreen(shouldEnableLockScreen);
- if (shouldEnableLockScreen) {
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return const LockScreenOption();
- },
- ),
- );
- }
+
return true;
} else {
AppLock.of(context)!
diff --git a/mobile/lib/ui/settings/TEMP/lock_screen_option.dart b/mobile/lib/ui/settings/TEMP/lock_screen_option.dart
index be7d5749cf..863ecdfaaf 100644
--- a/mobile/lib/ui/settings/TEMP/lock_screen_option.dart
+++ b/mobile/lib/ui/settings/TEMP/lock_screen_option.dart
@@ -1,17 +1,38 @@
import "package:flutter/material.dart";
+import "package:photos/core/configuration.dart";
import "package:photos/generated/l10n.dart";
+import "package:photos/services/local_authentication_service.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/ui/components/toggle_switch_widget.dart";
import "package:photos/ui/settings/TEMP/lock_screen_option_password.dart";
import "package:photos/ui/settings/TEMP/lock_screen_option_pin.dart";
-class LockScreenOption extends StatelessWidget {
+class LockScreenOption extends StatefulWidget {
const LockScreenOption({super.key});
+ @override
+ State<LockScreenOption> createState() => _LockScreenOptionState();
+}
+
+class _LockScreenOptionState extends State<LockScreenOption> {
+ final Configuration _configuration = Configuration.instance;
+ bool? appLock;
+ bool isPinEnabled = false;
+ bool isPasswordEnabled = false;
+
+ @override
+ void initState() {
+ isPasswordEnabled = _configuration.isPasswordSet();
+ isPinEnabled = _configuration.isPinSet();
+ appLock = isPinEnabled || isPasswordEnabled;
+ super.initState();
+ }
+
@override
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
@@ -19,9 +40,9 @@ class LockScreenOption extends StatelessWidget {
body: CustomScrollView(
primary: false,
slivers: <Widget>[
- TitleBarWidget(
+ const TitleBarWidget(
flexibleSpaceTitle: TitleBarTitleWidget(
- title: S.of(context).lockscreen,
+ title: 'App lock',
),
),
SliverList(
@@ -36,78 +57,156 @@ class LockScreenOption extends StatelessWidget {
children: [
Column(
children: [
- MenuItemWidget(
- captionedTextWidget: CaptionedTextWidget(
- title: S.of(context).noDeviceLimit,
- ),
- alignCaptionedTextToLeft: true,
- isTopBorderRadiusRemoved: false,
- isBottomBorderRadiusRemoved: true,
- menuItemColor: colorScheme.fillFaint,
- trailingIconIsMuted: true,
- trailingIcon: Icons.chevron_right_outlined,
- ),
- DividerWidget(
- dividerType: DividerType.menuNoIcon,
- bgColor: colorScheme.fillFaint,
- ),
- MenuItemWidget(
- captionedTextWidget: const CaptionedTextWidget(
- title: 'Device Lock',
- ),
- alignCaptionedTextToLeft: true,
- isTopBorderRadiusRemoved: true,
- isBottomBorderRadiusRemoved: true,
- menuItemColor: colorScheme.fillFaint,
- trailingIconIsMuted: true,
- trailingIcon: Icons.chevron_right_outlined,
- ),
- DividerWidget(
- dividerType: DividerType.menuNoIcon,
- bgColor: colorScheme.fillFaint,
- ),
MenuItemWidget(
captionedTextWidget: const CaptionedTextWidget(
- title: 'PIN lock',
+ title: 'App lock',
),
alignCaptionedTextToLeft: true,
- isTopBorderRadiusRemoved: true,
- isBottomBorderRadiusRemoved: true,
- menuItemColor: colorScheme.fillFaint,
- trailingIconIsMuted: true,
- trailingIcon: Icons.chevron_right_outlined,
- onTap: () => Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return const LockScreenOptionPin();
- },
- ),
- ),
- ),
- DividerWidget(
- dividerType: DividerType.menuNoIcon,
- bgColor: colorScheme.fillFaint,
- ),
- MenuItemWidget(
- captionedTextWidget: const CaptionedTextWidget(
- title: 'Password lock',
- ),
- alignCaptionedTextToLeft: true,
- isTopBorderRadiusRemoved: true,
+ isTopBorderRadiusRemoved: false,
isBottomBorderRadiusRemoved: false,
menuItemColor: colorScheme.fillFaint,
- trailingIconIsMuted: true,
- trailingIcon: Icons.chevron_right_outlined,
- onTap: () => Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return const LockScreenOptionPassword();
- },
- ),
+ trailingWidget: ToggleSwitchWidget(
+ value: () => appLock!,
+ onChanged: () async {
+ bool result;
+ if ((isPinEnabled || isPasswordEnabled) &&
+ appLock == true) {
+ result = await LocalAuthenticationService
+ .instance
+ .requestEnteAuthForLockScreen(context);
+ await _configuration.removePinAndPassword();
+ isPasswordEnabled =
+ _configuration.isPasswordSet();
+ isPinEnabled = _configuration.isPinSet();
+ }
+ // else if ((isPasswordEnabled ||
+ // isPinEnabled) &&
+ // appLock == false) {
+ // await _configuration.removePinAndPassword();
+ // result = true;
+ // }
+ else {
+ result = await LocalAuthenticationService
+ .instance
+ .requestLocalAuthForLockScreen(
+ context,
+ !_configuration.shouldShowLockScreen(),
+ S
+ .of(context)
+ .authToChangeLockscreenSetting,
+ S.of(context).lockScreenEnablePreSteps,
+ );
+ await _configuration.removePinAndPassword();
+ isPasswordEnabled =
+ _configuration.isPasswordSet();
+ isPinEnabled = _configuration.isPinSet();
+ }
+ setState(() {
+ if (result) {
+ appLock = !appLock!;
+ }
+ });
+ },
),
),
],
),
+ appLock!
+ ? Column(
+ children: [
+ const SizedBox(
+ height: 24,
+ ),
+ MenuItemWidget(
+ captionedTextWidget:
+ const CaptionedTextWidget(
+ title: 'Device Lock',
+ ),
+ alignCaptionedTextToLeft: true,
+ isTopBorderRadiusRemoved: false,
+ isBottomBorderRadiusRemoved: true,
+ menuItemColor: colorScheme.fillFaint,
+ trailingIconIsMuted: true,
+ trailingIcon: Icons.chevron_right_outlined,
+ onTap: () async {
+ setState(() {
+ _configuration.removePinAndPassword();
+ isPasswordEnabled =
+ _configuration.isPasswordSet();
+ isPinEnabled =
+ _configuration.isPinSet();
+ });
+ },
+ ),
+ DividerWidget(
+ dividerType: DividerType.menuNoIcon,
+ bgColor: colorScheme.fillFaint,
+ ),
+ MenuItemWidget(
+ captionedTextWidget:
+ const CaptionedTextWidget(
+ title: 'PIN lock',
+ ),
+ alignCaptionedTextToLeft: true,
+ isTopBorderRadiusRemoved: true,
+ isBottomBorderRadiusRemoved: true,
+ menuItemColor: colorScheme.fillFaint,
+ trailingIconIsMuted: true,
+ trailingIcon: Icons.chevron_right_outlined,
+ onTap: () async {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return const LockScreenOptionPin();
+ },
+ ),
+ );
+ setState(() {
+ isPasswordEnabled =
+ _configuration.isPasswordSet();
+ isPinEnabled =
+ _configuration.isPinSet();
+ appLock =
+ isPinEnabled || isPasswordEnabled;
+ });
+ },
+ ),
+ DividerWidget(
+ dividerType: DividerType.menuNoIcon,
+ bgColor: colorScheme.fillFaint,
+ ),
+ MenuItemWidget(
+ captionedTextWidget:
+ const CaptionedTextWidget(
+ title: 'Password lock',
+ ),
+ alignCaptionedTextToLeft: true,
+ isTopBorderRadiusRemoved: true,
+ isBottomBorderRadiusRemoved: false,
+ menuItemColor: colorScheme.fillFaint,
+ trailingIconIsMuted: true,
+ trailingIcon: Icons.chevron_right_outlined,
+ onTap: () async {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return const LockScreenOptionPassword();
+ },
+ ),
+ );
+ setState(() {
+ isPasswordEnabled =
+ _configuration.isPasswordSet();
+ isPinEnabled =
+ _configuration.isPinSet();
+ appLock =
+ isPinEnabled || isPasswordEnabled;
+ });
+ },
+ ),
+ ],
+ )
+ : Container(),
],
),
),
diff --git a/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart b/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart
index 55370af64d..8e66baf67d 100644
--- a/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart
+++ b/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart
@@ -9,8 +9,12 @@ import "package:photos/ui/components/models/button_type.dart";
import "package:photos/ui/components/text_input_widget.dart";
class LockScreenOptionConfirmPassword extends StatefulWidget {
- const LockScreenOptionConfirmPassword({super.key, required this.password});
+ const LockScreenOptionConfirmPassword({
+ super.key,
+ required this.password,
+ });
final String password;
+
@override
State<LockScreenOptionConfirmPassword> createState() =>
_LockScreenOptionConfirmPasswordState();
@@ -18,7 +22,6 @@ class LockScreenOptionConfirmPassword extends StatefulWidget {
class _LockScreenOptionConfirmPasswordState
extends State<LockScreenOptionConfirmPassword> {
- String _confirmPassword = "";
final _confirmPasswordController = TextEditingController(text: null);
final Configuration _configuration = Configuration.instance;
final _focusNode = FocusNode();
@@ -34,14 +37,14 @@ class _LockScreenOptionConfirmPasswordState
@override
void dispose() {
- super.dispose();
_focusNode.dispose();
- _confirmPasswordController.dispose();
+ // print("CONFIRM DISPOSE");
+ super.dispose();
}
Future<void> _confirmPasswordMatch() async {
- if (widget.password == _confirmPassword) {
- await _configuration.savePassword(_confirmPassword);
+ if (widget.password == _confirmPasswordController.text) {
+ await _configuration.savePassword(_confirmPasswordController.text);
await showDialogWidget(
context: context,
title: 'Password has been set',
@@ -136,11 +139,6 @@ class _LockScreenOptionConfirmPasswordState
textEditingController: _confirmPasswordController,
prefixIcon: Icons.lock_outline,
isPasswordInput: true,
- onChange: (String p0) {
- setState(() {
- _confirmPassword = p0;
- });
- },
),
),
const Spacer(),
@@ -148,9 +146,7 @@ class _LockScreenOptionConfirmPasswordState
padding: const EdgeInsets.all(18.0),
child: ButtonWidget(
labelText: 'Next',
- buttonType: _confirmPassword.length > 3
- ? ButtonType.primary
- : ButtonType.secondary,
+ buttonType: ButtonType.secondary,
buttonSize: ButtonSize.large,
onTap: () => _confirmPasswordMatch(),
),
diff --git a/mobile/lib/ui/settings/TEMP/lock_screen_option_password.dart b/mobile/lib/ui/settings/TEMP/lock_screen_option_password.dart
index ce443a9355..f1552fcda6 100644
--- a/mobile/lib/ui/settings/TEMP/lock_screen_option_password.dart
+++ b/mobile/lib/ui/settings/TEMP/lock_screen_option_password.dart
@@ -37,8 +37,9 @@ class _LockScreenOptionPasswordState extends State<LockScreenOptionPassword> {
@override
void dispose() {
super.dispose();
- _passwordController.dispose();
+ // _passwordController.dispose();
_focusNode.dispose();
+ // print("DISPOSE");
}
Future<bool> confirmPasswordAuth(String code) async {
diff --git a/mobile/lib/ui/settings/TEMP/lock_screen_option_pin.dart b/mobile/lib/ui/settings/TEMP/lock_screen_option_pin.dart
index f04579d23a..f4b87b4488 100644
--- a/mobile/lib/ui/settings/TEMP/lock_screen_option_pin.dart
+++ b/mobile/lib/ui/settings/TEMP/lock_screen_option_pin.dart
@@ -43,6 +43,7 @@ class _LockScreenOptionPinState extends State<LockScreenOptionPin> {
super.dispose();
_pinController.dispose();
_focusNode.dispose();
+ print("PIN");
}
Future<bool> confirmPinAuth(String code) async {
diff --git a/mobile/lib/ui/settings/TEMP/lock_screen_option_pin_setting.dart b/mobile/lib/ui/settings/TEMP/lock_screen_option_pin_setting.dart
deleted file mode 100644
index e5d940d36d..0000000000
--- a/mobile/lib/ui/settings/TEMP/lock_screen_option_pin_setting.dart
+++ /dev/null
@@ -1,17 +0,0 @@
-import "package:flutter/widgets.dart";
-
-class LockScreenOptionPinSetting extends StatefulWidget {
- const LockScreenOptionPinSetting({super.key});
-
- @override
- State<LockScreenOptionPinSetting> createState() =>
- _LockScreenOptionPinSettingState();
-}
-
-class _LockScreenOptionPinSettingState
- extends State<LockScreenOptionPinSetting> {
- @override
- Widget build(BuildContext context) {
- return const Placeholder();
- }
-}
diff --git a/mobile/lib/ui/settings/security_section_widget.dart b/mobile/lib/ui/settings/security_section_widget.dart
index bad5306942..35e1d3fb72 100644
--- a/mobile/lib/ui/settings/security_section_widget.dart
+++ b/mobile/lib/ui/settings/security_section_widget.dart
@@ -21,6 +21,7 @@ import 'package:photos/ui/components/captioned_text_widget.dart';
import 'package:photos/ui/components/expandable_menu_item_widget.dart';
import 'package:photos/ui/components/menu_item_widget/menu_item_widget.dart';
import 'package:photos/ui/components/toggle_switch_widget.dart';
+import "package:photos/ui/settings/TEMP/lock_screen_option.dart";
import 'package:photos/ui/settings/common_settings.dart';
import "package:photos/utils/crypto_util.dart";
import "package:photos/utils/dialog_util.dart";
@@ -140,24 +141,38 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
}
children.addAll([
MenuItemWidget(
- captionedTextWidget: CaptionedTextWidget(
- title: S.of(context).lockscreen,
- ),
- trailingWidget: ToggleSwitchWidget(
- value: () => _config.shouldShowLockScreen(),
- onChanged: () async {
- await LocalAuthenticationService.instance
- .requestLocalAuthForLockScreen(
- context,
- !_config.shouldShowLockScreen(),
- S.of(context).authToChangeLockscreenSetting,
- S.of(context).lockScreenEnablePreSteps,
- );
-
- ///try here also once about the material page route
- },
+ captionedTextWidget: const CaptionedTextWidget(
+ title: 'App lock',
),
+ onTap: () async {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return const LockScreenOption();
+ },
+ ),
+ );
+ },
),
+ // MenuItemWidget(
+ // captionedTextWidget: const CaptionedTextWidget(
+ // title: 'App lock',
+ // ),
+ // trailingWidget: ToggleSwitchWidget(
+ // value: () => _config.shouldShowLockScreen(),
+ // onChanged: () async {
+ // await LocalAuthenticationService.instance
+ // .requestLocalAuthForLockScreen(
+ // context,
+ // !_config.shouldShowLockScreen(),
+ // S.of(context).authToChangeLockscreenSetting,
+ // S.of(context).lockScreenEnablePreSteps,
+ // );
+
+ // ///try here also once about the material page route
+ // },
+ // ),
+ // ),
sectionOptionSpacing,
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(