mirror of
https://github.com/ente-io/ente.git
synced 2025-05-29 14:01:19 +00:00
On desktop, now there Help menu will have an "Ente Help" option instead of "FAQ" (Unrelated: I noticed that user facing strings in the desktop app are not localized). The only place remaining after this is the sidebar on mobile (`support_section_widget.dart`), but I wasn't sure of what string to use (and how to add it to the localized strings for mobile) so I've left it unchanged.
228 lines
7.7 KiB
Dart
228 lines
7.7 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import "package:photos/generated/l10n.dart";
|
|
import 'package:photos/services/local_authentication_service.dart';
|
|
import 'package:photos/services/user_service.dart';
|
|
import 'package:photos/theme/ente_theme.dart';
|
|
import 'package:photos/ui/account/change_email_dialog.dart';
|
|
import 'package:photos/ui/account/delete_account_page.dart';
|
|
import 'package:photos/ui/account/password_entry_page.dart';
|
|
import "package:photos/ui/account/recovery_key_page.dart";
|
|
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/payment/subscription.dart";
|
|
import 'package:photos/ui/settings/common_settings.dart';
|
|
import "package:photos/utils/crypto_util.dart";
|
|
import 'package:photos/utils/dialog_util.dart';
|
|
import "package:photos/utils/navigation_util.dart";
|
|
import "package:url_launcher/url_launcher_string.dart";
|
|
|
|
class AccountSectionWidget extends StatelessWidget {
|
|
const AccountSectionWidget({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ExpandableMenuItemWidget(
|
|
title: S.of(context).account,
|
|
selectionOptionsWidget: _getSectionOptions(context),
|
|
leadingIcon: Icons.account_circle_outlined,
|
|
);
|
|
}
|
|
|
|
Column _getSectionOptions(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
sectionOptionSpacing,
|
|
MenuItemWidget(
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
title: S.of(context).manageSubscription,
|
|
),
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
trailingIconIsMuted: true,
|
|
onTap: () async {
|
|
_onManageSubscriptionTapped(context);
|
|
},
|
|
),
|
|
sectionOptionSpacing,
|
|
MenuItemWidget(
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
title: S.of(context).changeEmail,
|
|
),
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
trailingIconIsMuted: true,
|
|
showOnlyLoadingState: true,
|
|
onTap: () async {
|
|
final hasAuthenticated = await LocalAuthenticationService.instance
|
|
.requestLocalAuthentication(
|
|
context,
|
|
S.of(context).authToChangeYourEmail,
|
|
);
|
|
if (hasAuthenticated) {
|
|
// ignore: unawaited_futures
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return const ChangeEmailDialog();
|
|
},
|
|
barrierColor: Colors.black.withOpacity(0.85),
|
|
barrierDismissible: false,
|
|
);
|
|
}
|
|
},
|
|
),
|
|
sectionOptionSpacing,
|
|
MenuItemWidget(
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
title: S.of(context).changePassword,
|
|
),
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
trailingIconIsMuted: true,
|
|
showOnlyLoadingState: true,
|
|
onTap: () async {
|
|
final hasAuthenticated = await LocalAuthenticationService.instance
|
|
.requestLocalAuthentication(
|
|
context,
|
|
S.of(context).authToChangeYourPassword,
|
|
);
|
|
if (hasAuthenticated) {
|
|
// ignore: unawaited_futures
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute(
|
|
builder: (BuildContext context) {
|
|
return const PasswordEntryPage(
|
|
mode: PasswordEntryMode.update,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
sectionOptionSpacing,
|
|
MenuItemWidget(
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
title: S.of(context).recoveryKey,
|
|
),
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
trailingIconIsMuted: true,
|
|
showOnlyLoadingState: true,
|
|
onTap: () async {
|
|
final hasAuthenticated = await LocalAuthenticationService.instance
|
|
.requestLocalAuthentication(
|
|
context,
|
|
S.of(context).authToViewYourRecoveryKey,
|
|
);
|
|
if (hasAuthenticated) {
|
|
String recoveryKey;
|
|
try {
|
|
recoveryKey = await _getOrCreateRecoveryKey(context);
|
|
} catch (e) {
|
|
await showGenericErrorDialog(context: context, error: e);
|
|
return;
|
|
}
|
|
unawaited(
|
|
routeToPage(
|
|
context,
|
|
RecoveryKeyPage(
|
|
recoveryKey,
|
|
S.of(context).ok,
|
|
showAppBar: true,
|
|
onDone: () {},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
sectionOptionSpacing,
|
|
MenuItemWidget(
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
title: S.of(context).exportYourData,
|
|
),
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
trailingIconIsMuted: true,
|
|
onTap: () async {
|
|
// ignore: unawaited_futures
|
|
launchUrlString("https://help.ente.io/photos/migration/export/");
|
|
},
|
|
),
|
|
sectionOptionSpacing,
|
|
MenuItemWidget(
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
title: S.of(context).logout,
|
|
),
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
trailingIconIsMuted: true,
|
|
onTap: () async {
|
|
_onLogoutTapped(context);
|
|
},
|
|
),
|
|
sectionOptionSpacing,
|
|
MenuItemWidget(
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
title: S.of(context).deleteAccount,
|
|
),
|
|
pressedColor: getEnteColorScheme(context).fillFaint,
|
|
trailingIcon: Icons.chevron_right_outlined,
|
|
trailingIconIsMuted: true,
|
|
onTap: () async {
|
|
final hasAuthenticated = await LocalAuthenticationService.instance
|
|
.requestLocalAuthentication(
|
|
context,
|
|
S.of(context).authToInitiateAccountDeletion,
|
|
);
|
|
if (hasAuthenticated) {
|
|
unawaited(
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute(
|
|
builder: (BuildContext context) {
|
|
return const DeleteAccountPage();
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
sectionOptionSpacing,
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<String> _getOrCreateRecoveryKey(BuildContext context) async {
|
|
return CryptoUtil.bin2hex(
|
|
await UserService.instance.getOrCreateRecoveryKey(context),
|
|
);
|
|
}
|
|
|
|
void _onLogoutTapped(BuildContext context) {
|
|
showChoiceActionSheet(
|
|
context,
|
|
title: S.of(context).areYouSureYouWantToLogout,
|
|
firstButtonLabel: S.of(context).yesLogout,
|
|
isCritical: true,
|
|
firstButtonOnTap: () async {
|
|
await UserService.instance.logout(context);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _onManageSubscriptionTapped(BuildContext context) {
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute(
|
|
builder: (BuildContext context) {
|
|
return getSubscriptionPage();
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|