mirror of
https://github.com/ente-io/ente.git
synced 2025-08-14 10:16:10 +00:00
[mob][photos] function of the lockscreen completed
This commit is contained in:
@@ -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
|
||||
|
@@ -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;
|
||||
} 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,10 +106,23 @@ class LocalAuthenticationService {
|
||||
),
|
||||
],
|
||||
);
|
||||
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();
|
||||
final result = await requestAuthentication(
|
||||
@@ -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)!
|
||||
|
@@ -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(
|
||||
@@ -37,8 +58,69 @@ class LockScreenOption extends StatelessWidget {
|
||||
Column(
|
||||
children: [
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: S.of(context).noDeviceLimit,
|
||||
captionedTextWidget: const CaptionedTextWidget(
|
||||
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,
|
||||
isTopBorderRadiusRemoved: false,
|
||||
@@ -46,28 +128,23 @@ class LockScreenOption extends StatelessWidget {
|
||||
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: '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(
|
||||
captionedTextWidget:
|
||||
const CaptionedTextWidget(
|
||||
title: 'PIN lock',
|
||||
),
|
||||
alignCaptionedTextToLeft: true,
|
||||
@@ -76,20 +153,31 @@ class LockScreenOption extends StatelessWidget {
|
||||
menuItemColor: colorScheme.fillFaint,
|
||||
trailingIconIsMuted: true,
|
||||
trailingIcon: Icons.chevron_right_outlined,
|
||||
onTap: () => Navigator.of(context).push(
|
||||
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(
|
||||
captionedTextWidget:
|
||||
const CaptionedTextWidget(
|
||||
title: 'Password lock',
|
||||
),
|
||||
alignCaptionedTextToLeft: true,
|
||||
@@ -98,16 +186,27 @@ class LockScreenOption extends StatelessWidget {
|
||||
menuItemColor: colorScheme.fillFaint,
|
||||
trailingIconIsMuted: true,
|
||||
trailingIcon: Icons.chevron_right_outlined,
|
||||
onTap: () => Navigator.of(context).push(
|
||||
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(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@@ -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(),
|
||||
),
|
||||
|
@@ -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 {
|
||||
|
@@ -43,6 +43,7 @@ class _LockScreenOptionPinState extends State<LockScreenOptionPin> {
|
||||
super.dispose();
|
||||
_pinController.dispose();
|
||||
_focusNode.dispose();
|
||||
print("PIN");
|
||||
}
|
||||
|
||||
Future<bool> confirmPinAuth(String code) async {
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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,
|
||||
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
|
||||
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(
|
||||
|
Reference in New Issue
Block a user