[mob][photos] function of the lockscreen completed

This commit is contained in:
Aman Raj Singh Mourya
2024-06-09 00:41:32 +05:30
parent d2b6ca53f8
commit 53b1dc9b67
8 changed files with 235 additions and 147 deletions

View File

@@ -175,6 +175,14 @@ class Configuration {
await _preferences.remove(password); 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 // _cleanUpStaleFiles deletes all files in the temp directory that are older
// than kTempFolderDeletionTimeBuffer except the the temp encrypted files for upload. // than kTempFolderDeletionTimeBuffer except the the temp encrypted files for upload.
// Those file are deleted by file uploader after the upload is complete or those // Those file are deleted by file uploader after the upload is complete or those

View File

@@ -7,7 +7,6 @@ import "package:photos/generated/l10n.dart";
import "package:photos/ui/components/buttons/button_widget.dart"; import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/dialog_widget.dart"; import "package:photos/ui/components/dialog_widget.dart";
import "package:photos/ui/components/models/button_type.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_password.dart";
import "package:photos/ui/settings/TEMP/lock_screen_option_pin.dart"; import "package:photos/ui/settings/TEMP/lock_screen_option_pin.dart";
import 'package:photos/ui/tools/app_lock.dart'; import 'package:photos/ui/tools/app_lock.dart';
@@ -42,13 +41,7 @@ class LocalAuthenticationService {
return true; return true;
} }
Future<bool> requestLocalAuthForLockScreen( Future<bool> requestEnteAuthForLockScreen(BuildContext context) async {
BuildContext context,
bool shouldEnableLockScreen,
String infoMessage,
String errorDialogContent, [
String errorDialogTitle = "",
]) async {
final String? savedPin = await _configuration.loadSavedPin(); final String? savedPin = await _configuration.loadSavedPin();
final String? savedPassword = await _configuration.loadSavedPassword(); final String? savedPassword = await _configuration.loadSavedPassword();
@@ -64,13 +57,6 @@ class LocalAuthenticationService {
), ),
); );
if (result) { if (result) {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return const LockScreenOption();
},
),
);
return true; return true;
} else { } else {
await showDialogWidget( 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( final result = await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
@@ -102,13 +89,6 @@ class LocalAuthenticationService {
), ),
); );
if (result) { if (result) {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return const LockScreenOption();
},
),
);
return true; return true;
} else { } else {
await showDialogWidget( await showDialogWidget(
@@ -126,10 +106,23 @@ 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()) { if (await _isLocalAuthSupportedOnDevice()) {
AppLock.of(context)!.disable(); AppLock.of(context)!.disable();
final result = await requestAuthentication( final result = await requestAuthentication(
@@ -140,15 +133,7 @@ class LocalAuthenticationService {
AppLock.of(context)!.setEnabled(shouldEnableLockScreen); AppLock.of(context)!.setEnabled(shouldEnableLockScreen);
await Configuration.instance await Configuration.instance
.setShouldShowLockScreen(shouldEnableLockScreen); .setShouldShowLockScreen(shouldEnableLockScreen);
if (shouldEnableLockScreen) {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return const LockScreenOption();
},
),
);
}
return true; return true;
} else { } else {
AppLock.of(context)! AppLock.of(context)!

View File

@@ -1,17 +1,38 @@
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:photos/core/configuration.dart";
import "package:photos/generated/l10n.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/theme/ente_theme.dart";
import "package:photos/ui/components/captioned_text_widget.dart"; import "package:photos/ui/components/captioned_text_widget.dart";
import "package:photos/ui/components/divider_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/menu_item_widget/menu_item_widget.dart";
import "package:photos/ui/components/title_bar_title_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/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_password.dart";
import "package:photos/ui/settings/TEMP/lock_screen_option_pin.dart"; import "package:photos/ui/settings/TEMP/lock_screen_option_pin.dart";
class LockScreenOption extends StatelessWidget { class LockScreenOption extends StatefulWidget {
const LockScreenOption({super.key}); 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context); final colorScheme = getEnteColorScheme(context);
@@ -19,9 +40,9 @@ class LockScreenOption extends StatelessWidget {
body: CustomScrollView( body: CustomScrollView(
primary: false, primary: false,
slivers: <Widget>[ slivers: <Widget>[
TitleBarWidget( const TitleBarWidget(
flexibleSpaceTitle: TitleBarTitleWidget( flexibleSpaceTitle: TitleBarTitleWidget(
title: S.of(context).lockscreen, title: 'App lock',
), ),
), ),
SliverList( SliverList(
@@ -37,8 +58,69 @@ class LockScreenOption extends StatelessWidget {
Column( Column(
children: [ children: [
MenuItemWidget( MenuItemWidget(
captionedTextWidget: CaptionedTextWidget( captionedTextWidget: const CaptionedTextWidget(
title: S.of(context).noDeviceLimit, title: 'App lock',
),
alignCaptionedTextToLeft: true,
isTopBorderRadiusRemoved: false,
isBottomBorderRadiusRemoved: false,
menuItemColor: colorScheme.fillFaint,
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, alignCaptionedTextToLeft: true,
isTopBorderRadiusRemoved: false, isTopBorderRadiusRemoved: false,
@@ -46,28 +128,23 @@ class LockScreenOption extends StatelessWidget {
menuItemColor: colorScheme.fillFaint, menuItemColor: colorScheme.fillFaint,
trailingIconIsMuted: true, trailingIconIsMuted: true,
trailingIcon: Icons.chevron_right_outlined, trailingIcon: Icons.chevron_right_outlined,
onTap: () async {
setState(() {
_configuration.removePinAndPassword();
isPasswordEnabled =
_configuration.isPasswordSet();
isPinEnabled =
_configuration.isPinSet();
});
},
), ),
DividerWidget( DividerWidget(
dividerType: DividerType.menuNoIcon, dividerType: DividerType.menuNoIcon,
bgColor: colorScheme.fillFaint, bgColor: colorScheme.fillFaint,
), ),
MenuItemWidget( MenuItemWidget(
captionedTextWidget: const CaptionedTextWidget( captionedTextWidget:
title: 'Device Lock', const CaptionedTextWidget(
),
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: 'PIN lock',
), ),
alignCaptionedTextToLeft: true, alignCaptionedTextToLeft: true,
@@ -76,20 +153,31 @@ class LockScreenOption extends StatelessWidget {
menuItemColor: colorScheme.fillFaint, menuItemColor: colorScheme.fillFaint,
trailingIconIsMuted: true, trailingIconIsMuted: true,
trailingIcon: Icons.chevron_right_outlined, trailingIcon: Icons.chevron_right_outlined,
onTap: () => Navigator.of(context).push( onTap: () async {
await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
return const LockScreenOptionPin(); return const LockScreenOptionPin();
}, },
), ),
), );
setState(() {
isPasswordEnabled =
_configuration.isPasswordSet();
isPinEnabled =
_configuration.isPinSet();
appLock =
isPinEnabled || isPasswordEnabled;
});
},
), ),
DividerWidget( DividerWidget(
dividerType: DividerType.menuNoIcon, dividerType: DividerType.menuNoIcon,
bgColor: colorScheme.fillFaint, bgColor: colorScheme.fillFaint,
), ),
MenuItemWidget( MenuItemWidget(
captionedTextWidget: const CaptionedTextWidget( captionedTextWidget:
const CaptionedTextWidget(
title: 'Password lock', title: 'Password lock',
), ),
alignCaptionedTextToLeft: true, alignCaptionedTextToLeft: true,
@@ -98,16 +186,27 @@ class LockScreenOption extends StatelessWidget {
menuItemColor: colorScheme.fillFaint, menuItemColor: colorScheme.fillFaint,
trailingIconIsMuted: true, trailingIconIsMuted: true,
trailingIcon: Icons.chevron_right_outlined, trailingIcon: Icons.chevron_right_outlined,
onTap: () => Navigator.of(context).push( onTap: () async {
await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
return const LockScreenOptionPassword(); return const LockScreenOptionPassword();
}, },
), ),
), );
setState(() {
isPasswordEnabled =
_configuration.isPasswordSet();
isPinEnabled =
_configuration.isPinSet();
appLock =
isPinEnabled || isPasswordEnabled;
});
},
), ),
], ],
), )
: Container(),
], ],
), ),
), ),

View File

@@ -9,8 +9,12 @@ import "package:photos/ui/components/models/button_type.dart";
import "package:photos/ui/components/text_input_widget.dart"; import "package:photos/ui/components/text_input_widget.dart";
class LockScreenOptionConfirmPassword extends StatefulWidget { class LockScreenOptionConfirmPassword extends StatefulWidget {
const LockScreenOptionConfirmPassword({super.key, required this.password}); const LockScreenOptionConfirmPassword({
super.key,
required this.password,
});
final String password; final String password;
@override @override
State<LockScreenOptionConfirmPassword> createState() => State<LockScreenOptionConfirmPassword> createState() =>
_LockScreenOptionConfirmPasswordState(); _LockScreenOptionConfirmPasswordState();
@@ -18,7 +22,6 @@ class LockScreenOptionConfirmPassword extends StatefulWidget {
class _LockScreenOptionConfirmPasswordState class _LockScreenOptionConfirmPasswordState
extends State<LockScreenOptionConfirmPassword> { extends State<LockScreenOptionConfirmPassword> {
String _confirmPassword = "";
final _confirmPasswordController = TextEditingController(text: null); final _confirmPasswordController = TextEditingController(text: null);
final Configuration _configuration = Configuration.instance; final Configuration _configuration = Configuration.instance;
final _focusNode = FocusNode(); final _focusNode = FocusNode();
@@ -34,14 +37,14 @@ class _LockScreenOptionConfirmPasswordState
@override @override
void dispose() { void dispose() {
super.dispose();
_focusNode.dispose(); _focusNode.dispose();
_confirmPasswordController.dispose(); // print("CONFIRM DISPOSE");
super.dispose();
} }
Future<void> _confirmPasswordMatch() async { Future<void> _confirmPasswordMatch() async {
if (widget.password == _confirmPassword) { if (widget.password == _confirmPasswordController.text) {
await _configuration.savePassword(_confirmPassword); await _configuration.savePassword(_confirmPasswordController.text);
await showDialogWidget( await showDialogWidget(
context: context, context: context,
title: 'Password has been set', title: 'Password has been set',
@@ -136,11 +139,6 @@ class _LockScreenOptionConfirmPasswordState
textEditingController: _confirmPasswordController, textEditingController: _confirmPasswordController,
prefixIcon: Icons.lock_outline, prefixIcon: Icons.lock_outline,
isPasswordInput: true, isPasswordInput: true,
onChange: (String p0) {
setState(() {
_confirmPassword = p0;
});
},
), ),
), ),
const Spacer(), const Spacer(),
@@ -148,9 +146,7 @@ class _LockScreenOptionConfirmPasswordState
padding: const EdgeInsets.all(18.0), padding: const EdgeInsets.all(18.0),
child: ButtonWidget( child: ButtonWidget(
labelText: 'Next', labelText: 'Next',
buttonType: _confirmPassword.length > 3 buttonType: ButtonType.secondary,
? ButtonType.primary
: ButtonType.secondary,
buttonSize: ButtonSize.large, buttonSize: ButtonSize.large,
onTap: () => _confirmPasswordMatch(), onTap: () => _confirmPasswordMatch(),
), ),

View File

@@ -37,8 +37,9 @@ class _LockScreenOptionPasswordState extends State<LockScreenOptionPassword> {
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
_passwordController.dispose(); // _passwordController.dispose();
_focusNode.dispose(); _focusNode.dispose();
// print("DISPOSE");
} }
Future<bool> confirmPasswordAuth(String code) async { Future<bool> confirmPasswordAuth(String code) async {

View File

@@ -43,6 +43,7 @@ class _LockScreenOptionPinState extends State<LockScreenOptionPin> {
super.dispose(); super.dispose();
_pinController.dispose(); _pinController.dispose();
_focusNode.dispose(); _focusNode.dispose();
print("PIN");
} }
Future<bool> confirmPinAuth(String code) async { Future<bool> confirmPinAuth(String code) async {

View File

@@ -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();
}
}

View File

@@ -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/expandable_menu_item_widget.dart';
import 'package:photos/ui/components/menu_item_widget/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/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/ui/settings/common_settings.dart';
import "package:photos/utils/crypto_util.dart"; import "package:photos/utils/crypto_util.dart";
import "package:photos/utils/dialog_util.dart"; import "package:photos/utils/dialog_util.dart";
@@ -140,24 +141,38 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
} }
children.addAll([ children.addAll([
MenuItemWidget( MenuItemWidget(
captionedTextWidget: CaptionedTextWidget( captionedTextWidget: const CaptionedTextWidget(
title: S.of(context).lockscreen, title: 'App lock',
), ),
trailingWidget: ToggleSwitchWidget( onTap: () async {
value: () => _config.shouldShowLockScreen(), await Navigator.of(context).push(
onChanged: () async { MaterialPageRoute(
await LocalAuthenticationService.instance builder: (BuildContext context) {
.requestLocalAuthForLockScreen( return const LockScreenOption();
context,
!_config.shouldShowLockScreen(),
S.of(context).authToChangeLockscreenSetting,
S.of(context).lockScreenEnablePreSteps,
);
///try here also once about the material page route
}, },
), ),
);
},
), ),
// 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, sectionOptionSpacing,
MenuItemWidget( MenuItemWidget(
captionedTextWidget: CaptionedTextWidget( captionedTextWidget: CaptionedTextWidget(