Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Migrate account settings components

aman-pilotb8c0f3393d0a
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dart
index 9b827a6a9d..a194041f9b 100644
--- a/mobile/apps/photos/lib/main.dart
+++ b/mobile/apps/photos/lib/main.dart
@@ -3,6 +3,7 @@ import 'dart:io';
import "package:adaptive_theme/adaptive_theme.dart";
import "package:computer/computer.dart";
+import "package:ente_components/ente_components.dart" as components;
import 'package:ente_crypto/ente_crypto.dart';
import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:ente_rust/ente_rust.dart";
@@ -123,6 +124,7 @@ Future<void> _runInForeground(
AdaptiveThemeMode? savedThemeMode,
MediaExtentionAction initialMediaExtensionAction,
) async {
+ components.ComponentTheme.configure(app: components.ComponentApp.photos);
return await runWithLogs(() async {
_logger.info("Starting app in foreground");
isProcessBg = false;
diff --git a/mobile/apps/photos/lib/ui/account/change_email_dialog.dart b/mobile/apps/photos/lib/ui/account/change_email_dialog.dart
index 974ad17a6f..fb007b07b9 100644
--- a/mobile/apps/photos/lib/ui/account/change_email_dialog.dart
+++ b/mobile/apps/photos/lib/ui/account/change_email_dialog.dart
@@ -1,82 +1,97 @@
+import 'package:ente_components/ente_components.dart';
import 'package:flutter/material.dart';
import "package:photos/l10n/l10n.dart";
import 'package:photos/services/account/user_service.dart';
-import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/email_util.dart';
-class ChangeEmailDialog extends StatefulWidget {
- const ChangeEmailDialog({super.key});
+Future<void> showChangeEmailBottomSheet(BuildContext context) {
+ return showBottomSheetComponent<void>(
+ context: context,
+ builder: (_) => const _ChangeEmailBottomSheet(),
+ );
+}
+
+class _ChangeEmailBottomSheet extends StatefulWidget {
+ const _ChangeEmailBottomSheet();
@override
- State<ChangeEmailDialog> createState() => _ChangeEmailDialogState();
+ State<_ChangeEmailBottomSheet> createState() =>
+ _ChangeEmailBottomSheetState();
}
-class _ChangeEmailDialogState extends State<ChangeEmailDialog> {
- String? _email;
+class _ChangeEmailBottomSheetState extends State<_ChangeEmailBottomSheet> {
+ final _emailController = TextEditingController();
+ bool _hasEmail = false;
+
+ @override
+ void dispose() {
+ _emailController.dispose();
+ super.dispose();
+ }
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
- return AlertDialog(
- title: Text(l10n.enterYourNewEmailAddress),
- content: SingleChildScrollView(
+
+ return BottomSheetComponent(
+ title: l10n.enterYourNewEmailAddress,
+ isKeyboardAware: true,
+ content: AutofillGroup(
child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
children: [
- TextFormField(
- decoration: InputDecoration(
- hintText: l10n.email,
- hintStyle: const TextStyle(
- color: Colors.white30,
- ),
- contentPadding: const EdgeInsets.all(12),
- ),
- onChanged: (value) {
+ TextInputComponent(
+ controller: _emailController,
+ hintText: l10n.email,
+ autofocus: true,
+ isClearable: true,
+ autocorrect: false,
+ keyboardType: TextInputType.emailAddress,
+ autofillHints: const [AutofillHints.email],
+ textCapitalization: TextCapitalization.none,
+ onSubmit: (_) => _verify(),
+ onChanged: (_) {
+ final hasEmail = _emailController.text.trim().isNotEmpty;
+ if (_hasEmail == hasEmail) {
+ return;
+ }
setState(() {
- _email = value;
+ _hasEmail = hasEmail;
});
},
- autocorrect: false,
- keyboardType: TextInputType.emailAddress,
- initialValue: _email,
- autofocus: true,
),
],
),
),
actions: [
- TextButton(
- child: Text(
- l10n.cancel,
- style: const TextStyle(
- color: Colors.redAccent,
- ),
- ),
- onPressed: () {
- Navigator.pop(context);
- },
- ),
- TextButton(
- child: Text(
- l10n.verify,
- style: const TextStyle(
- color: Colors.green,
- ),
- ),
- onPressed: () {
- if (!isValidEmail(_email)) {
- showErrorDialog(
- context,
- l10n.invalidEmailAddress,
- l10n.enterValidEmail,
- );
- return;
- }
- UserService.instance.sendOtt(context, _email!, isChangeEmail: true);
- },
+ ButtonComponent(
+ label: l10n.verify,
+ isDisabled: !_hasEmail,
+ onTap: () => _verify(),
),
],
);
}
+
+ Future<void> _verify() async {
+ final l10n = context.l10n;
+ final email = _emailController.text.trim();
+
+ if (!isValidEmail(email)) {
+ await showErrorBottomSheetComponent<void>(
+ context: context,
+ title: l10n.invalidEmailAddress,
+ message: l10n.enterValidEmail,
+ illustration: Image.asset('assets/warning-grey.png'),
+ );
+ return;
+ }
+
+ await UserService.instance.sendOtt(
+ context,
+ email,
+ isChangeEmail: true,
+ );
+ }
}
diff --git a/mobile/apps/photos/lib/ui/settings/account/account_settings_page.dart b/mobile/apps/photos/lib/ui/settings/account/account_settings_page.dart
index 869e9dad6f..b64d0a8ecf 100644
--- a/mobile/apps/photos/lib/ui/settings/account/account_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/account/account_settings_page.dart
@@ -7,13 +7,13 @@ import "package:photos/generated/l10n.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/account/user_service.dart";
import "package:photos/services/local_authentication_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/menu_item_widget/menu_item_widget_new.dart";
import "package:photos/ui/payment/subscription.dart";
+import "package:photos/ui/settings/components/settings_item.dart";
+import "package:photos/ui/settings/components/settings_page_scaffold.dart";
import "package:photos/utils/dialog_util.dart";
import "package:url_launcher/url_launcher_string.dart";
@@ -22,150 +22,70 @@ class AccountSettingsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
- final colorScheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
- final isDarkMode = Theme.of(context).brightness == Brightness.dark;
+ final l10n = AppLocalizations.of(context);
- final pageBackgroundColor =
- isDarkMode ? const Color(0xFF161616) : const Color(0xFFFAFAFA);
-
- return Scaffold(
- backgroundColor: pageBackgroundColor,
- body: SafeArea(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(height: 24),
- GestureDetector(
- onTap: () => Navigator.of(context).pop(),
- child: Icon(
- Icons.arrow_back,
- color: colorScheme.strokeBase,
- size: 24,
- ),
- ),
- const SizedBox(height: 24),
- Text(
- AppLocalizations.of(context).account,
- style: textTheme.h3Bold,
- ),
- const SizedBox(height: 24),
- Expanded(
- child: SingleChildScrollView(
- child: Column(
- children: [
- MenuItemWidgetNew(
- title: AppLocalizations.of(context).manageSubscription,
- leadingIconWidget: _buildIconWidget(
- context,
- HugeIcons.strokeRoundedCreditCard,
- ),
- trailingIcon: Icons.chevron_right_outlined,
- trailingIconIsMuted: true,
- showOnlyLoadingState: true,
- surfaceExecutionStates: true,
- onTap: () async => _onManageSubscriptionTapped(context),
- ),
- const SizedBox(height: 8),
- MenuItemWidgetNew(
- title: AppLocalizations.of(context).changeEmail,
- leadingIconWidget: _buildIconWidget(
- context,
- HugeIcons.strokeRoundedMail01,
- ),
- trailingIcon: Icons.chevron_right_outlined,
- trailingIconIsMuted: true,
- showOnlyLoadingState: true,
- onTap: () async => _onChangeEmailTapped(context),
- ),
- const SizedBox(height: 8),
- MenuItemWidgetNew(
- title: AppLocalizations.of(context).changePassword,
- leadingIconWidget: _buildIconWidget(
- context,
- HugeIcons.strokeRoundedLockPassword,
- ),
- trailingIcon: Icons.chevron_right_outlined,
- trailingIconIsMuted: true,
- showOnlyLoadingState: true,
- onTap: () async => _onChangePasswordTapped(context),
- ),
- const SizedBox(height: 8),
- MenuItemWidgetNew(
- title: AppLocalizations.of(context).recoveryKey,
- leadingIconWidget: _buildIconWidget(
- context,
- HugeIcons.strokeRoundedKey01,
- ),
- trailingIcon: Icons.chevron_right_outlined,
- trailingIconIsMuted: true,
- showOnlyLoadingState: true,
- onTap: () async => _onRecoveryKeyTapped(context),
- ),
- const SizedBox(height: 8),
- MenuItemWidgetNew(
- title: AppLocalizations.of(context).exportYourData,
- leadingIconWidget: _buildIconWidget(
- context,
- HugeIcons.strokeRoundedDownload04,
- ),
- trailingIcon: Icons.chevron_right_outlined,
- trailingIconIsMuted: true,
- onTap: () async {
- await launchUrlString(
- "https://ente.com/help/photos/migration/export/",
- );
- },
- ),
- const SizedBox(height: 8),
- MenuItemWidgetNew(
- title: AppLocalizations.of(context).deleteAccount,
- titleColor: colorScheme.warning700,
- leadingIconWidget: _buildIconWidget(
- context,
- HugeIcons.strokeRoundedDelete02,
- isDestructive: true,
- ),
- trailingIcon: Icons.chevron_right_outlined,
- trailingIconIsMuted: true,
- onTap: () async => _onDeleteAccountTapped(context),
- ),
- ],
- ),
- ),
- ),
- ],
- ),
+ return SettingsPageScaffold(
+ title: l10n.account,
+ children: [
+ SettingsItem(
+ title: l10n.manageSubscription,
+ icon: HugeIcons.strokeRoundedCreditCard,
+ showOnlyLoadingState: true,
+ shouldSurfaceExecutionStates: true,
+ onTap: () async => _onManageSubscriptionTapped(context),
),
- ),
- );
- }
-
- Widget _buildIconWidget(
- BuildContext context,
- List<List<dynamic>> icon, {
- bool isDestructive = false,
- }) {
- final colorScheme = getEnteColorScheme(context);
- return HugeIcon(
- icon: icon,
- color: isDestructive
- ? colorScheme.warning700
- : colorScheme.menuItemIconStroke,
- size: 20,
+ const SizedBox(height: 8),
+ SettingsItem(
+ title: l10n.changeEmail,
+ icon: HugeIcons.strokeRoundedMail01,
+ showOnlyLoadingState: true,
+ onTap: () async => _onChangeEmailTapped(context),
+ ),
+ const SizedBox(height: 8),
+ SettingsItem(
+ title: l10n.changePassword,
+ icon: HugeIcons.strokeRoundedLockPassword,
+ showOnlyLoadingState: true,
+ onTap: () async => _onChangePasswordTapped(context),
+ ),
+ const SizedBox(height: 8),
+ SettingsItem(
+ title: l10n.recoveryKey,
+ icon: HugeIcons.strokeRoundedKey01,
+ showOnlyLoadingState: true,
+ onTap: () async => _onRecoveryKeyTapped(context),
+ ),
+ const SizedBox(height: 8),
+ SettingsItem(
+ title: l10n.exportYourData,
+ icon: HugeIcons.strokeRoundedDownload04,
+ onTap: () async {
+ await launchUrlString(
+ "https://ente.com/help/photos/migration/export/",
+ );
+ },
+ ),
+ const SizedBox(height: 8),
+ SettingsItem(
+ title: l10n.deleteAccount,
+ icon: HugeIcons.strokeRoundedDelete02,
+ isDestructive: true,
+ onTap: () async => _onDeleteAccountTapped(context),
+ ),
+ ],
);
}
Future<void> _onManageSubscriptionTapped(BuildContext context) async {
try {
- final userDetails =
- await UserService.instance.getUserDetailsV2(memoryCount: false);
+ final userDetails = await UserService.instance.getUserDetailsV2(
+ memoryCount: false,
+ );
if (!context.mounted) {
return;
}
- final isFamilyMember = userDetails.isPartOfFamily() &&
+ final isFamilyMember =
+ userDetails.isPartOfFamily() &&
!(userDetails.currentFamilyMember()?.isAdmin ?? false);
if (isFamilyMember) {
await billingService.launchFamilyPortal(
@@ -196,32 +116,22 @@ class AccountSettingsPage extends StatelessWidget {
}
Future<void> _onChangeEmailTapped(BuildContext context) async {
- final hasAuthenticated =
- await LocalAuthenticationService.instance.requestLocalAuthentication(
- context,
- AppLocalizations.of(context).authToChangeYourEmail,
- );
+ final hasAuthenticated = await LocalAuthenticationService.instance
+ .requestLocalAuthentication(
+ context,
+ AppLocalizations.of(context).authToChangeYourEmail,
+ );
if (hasAuthenticated) {
- unawaited(
- showDialog(
- useRootNavigator: false,
- context: context,
- builder: (BuildContext context) {
- return const ChangeEmailDialog();
- },
- barrierColor: Colors.black.withValues(alpha: 0.85),
- barrierDismissible: false,
- ),
- );
+ unawaited(showChangeEmailBottomSheet(context));
}
}
Future<void> _onChangePasswordTapped(BuildContext context) async {
- final hasAuthenticated =
- await LocalAuthenticationService.instance.requestLocalAuthentication(
- context,
- AppLocalizations.of(context).authToChangeYourPassword,
- );
+ final hasAuthenticated = await LocalAuthenticationService.instance
+ .requestLocalAuthentication(
+ context,
+ AppLocalizations.of(context).authToChangeYourPassword,
+ );
if (hasAuthenticated) {
unawaited(
Navigator.of(context).push(
@@ -238,11 +148,11 @@ class AccountSettingsPage extends StatelessWidget {
}
Future<void> _onRecoveryKeyTapped(BuildContext context) async {
- final hasAuthenticated =
- await LocalAuthenticationService.instance.requestLocalAuthentication(
- context,
- AppLocalizations.of(context).authToViewYourRecoveryKey,
- );
+ final hasAuthenticated = await LocalAuthenticationService.instance
+ .requestLocalAuthentication(
+ context,
+ AppLocalizations.of(context).authToViewYourRecoveryKey,
+ );
if (hasAuthenticated) {
String recoveryKey;
try {
@@ -274,11 +184,11 @@ class AccountSettingsPage extends StatelessWidget {
}
Future<void> _onDeleteAccountTapped(BuildContext context) async {
- final hasAuthenticated =
- await LocalAuthenticationService.instance.requestLocalAuthentication(
- context,
- AppLocalizations.of(context).authToInitiateAccountDeletion,
- );
+ final hasAuthenticated = await LocalAuthenticationService.instance
+ .requestLocalAuthentication(
+ context,
+ AppLocalizations.of(context).authToInitiateAccountDeletion,
+ );
if (hasAuthenticated) {
unawaited(
Navigator.of(context).push(
diff --git a/mobile/apps/photos/lib/ui/settings/components/settings_item.dart b/mobile/apps/photos/lib/ui/settings/components/settings_item.dart
new file mode 100644
index 0000000000..65a395ad88
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/settings/components/settings_item.dart
@@ -0,0 +1,96 @@
+import "dart:async";
+
+import "package:ente_components/ente_components.dart";
+import "package:flutter/material.dart";
+import "package:flutter_svg/flutter_svg.dart";
+import "package:hugeicons/hugeicons.dart";
+
+class SettingsItem extends StatelessWidget {
+ const SettingsItem({
+ super.key,
+ required this.title,
+ this.subtitle,
+ this.icon,
+ this.svgIconPath,
+ this.leading,
+ this.trailing,
+ this.onTap,
+ this.onDoubleTap,
+ this.showChevron = true,
+ this.isDestructive = false,
+ this.selected = false,
+ this.showOnlyLoadingState = false,
+ this.shouldSurfaceExecutionStates = false,
+ this.titleMaxLines = 2,
+ this.subtitleMaxLines = 1,
+ });
+
+ final String title;
+ final String? subtitle;
+ final List<List<dynamic>>? icon;
+ final String? svgIconPath;
+ final Widget? leading;
+ final Widget? trailing;
+ final FutureOr<void> Function()? onTap;
+ final FutureOr<void> Function()? onDoubleTap;
+ final bool showChevron;
+ final bool isDestructive;
+ final bool selected;
+ final bool showOnlyLoadingState;
+ final bool shouldSurfaceExecutionStates;
+ final int titleMaxLines;
+ final int subtitleMaxLines;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ final effectiveTextColor = isDestructive ? colors.warning : colors.textBase;
+ final effectiveIconColor = isDestructive
+ ? colors.warning
+ : colors.textLight;
+
+ return MenuComponent(
+ title: title,
+ subtitle: subtitle,
+ titleColor: effectiveTextColor,
+ iconColor: effectiveIconColor,
+ selected: selected,
+ leading: leading ?? _buildLeading(effectiveIconColor),
+ trailing: trailing ?? (showChevron ? _chevron(colors) : null),
+ showOnlyLoadingState: showOnlyLoadingState,
+ shouldSurfaceExecutionStates: shouldSurfaceExecutionStates,
+ titleMaxLines: titleMaxLines,
+ subtitleMaxLines: subtitleMaxLines,
+ onTap: onTap,
+ onDoubleTap: onDoubleTap,
+ );
+ }
+
+ Widget? _buildLeading(Color color) {
+ if (icon != null) {
+ return HugeIcon(
+ icon: icon!,
+ color: color,
+ size: IconSizes.small,
+ strokeWidth: 1.6,
+ );
+ }
+ if (svgIconPath != null) {
+ return SvgPicture.asset(
+ svgIconPath!,
+ colorFilter: ColorFilter.mode(color, BlendMode.srcIn),
+ width: IconSizes.small,
+ height: IconSizes.small,
+ );
+ }
+ return null;
+ }
+
+ Widget _chevron(ColorTokens colors) {
+ return Icon(
+ Icons.chevron_right_outlined,
+ color: colors.textLight,
+ size: IconSizes.medium,
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/settings/components/settings_page_scaffold.dart b/mobile/apps/photos/lib/ui/settings/components/settings_page_scaffold.dart
new file mode 100644
index 0000000000..0cd3e946aa
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/settings/components/settings_page_scaffold.dart
@@ -0,0 +1,45 @@
+import "package:ente_components/ente_components.dart";
+import "package:flutter/material.dart";
+
+class SettingsPageScaffold extends StatelessWidget {
+ const SettingsPageScaffold({
+ super.key,
+ required this.title,
+ required this.children,
+ this.subtitle,
+ this.actions = const [],
+ this.controller,
+ this.padding = const EdgeInsets.fromLTRB(16, 0, 16, 16),
+ });
+
+ final String title;
+ final String? subtitle;
+ final List<Widget> actions;
+ final List<Widget> children;
+ final ScrollController? controller;
+ final EdgeInsetsGeometry padding;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+
+ return Scaffold(
+ backgroundColor: colors.backgroundBase,
+ body: AppBarComponent(
+ title: title,
+ subtitle: subtitle,
+ actions: actions,
+ controller: controller,
+ slivers: [
+ SliverSafeArea(
+ top: false,
+ sliver: SliverPadding(
+ padding: padding,
+ sliver: SliverList.list(children: children),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/pubspec.lock b/mobile/apps/photos/pubspec.lock
index af429bac3e..3a2e7db237 100644
--- a/mobile/apps/photos/pubspec.lock
+++ b/mobile/apps/photos/pubspec.lock
@@ -594,6 +594,13 @@ packages:
relative: true
source: path
version: "0.0.1"
+ ente_components:
+ dependency: "direct main"
+ description:
+ path: "../../packages/ente_components"
+ relative: true
+ source: path
+ version: "0.1.0"
ente_contacts:
dependency: "direct main"
description:
diff --git a/mobile/apps/photos/pubspec.yaml b/mobile/apps/photos/pubspec.yaml
index 2635b17de6..54623238a8 100644
--- a/mobile/apps/photos/pubspec.yaml
+++ b/mobile/apps/photos/pubspec.yaml
@@ -57,6 +57,8 @@ dependencies:
encrypt: 5.0.3
ente_cast:
path: plugins/ente_cast
+ ente_components:
+ path: ../../packages/ente_components
ente_contacts:
path: ../../packages/contacts
ente_crypto:
diff --git a/mobile/apps/photos/pubspec_overrides.yaml b/mobile/apps/photos/pubspec_overrides.yaml
index 0339f7e394..e9e6983545 100644
--- a/mobile/apps/photos/pubspec_overrides.yaml
+++ b/mobile/apps/photos/pubspec_overrides.yaml
@@ -1,4 +1,4 @@
-# melos_managed_dependency_overrides: ente_cast,ente_crypto,ente_feature_flag,onnx_dart,ffi,flutter_sodium,intl,js,media_kit,media_kit_libs_ios_video,media_kit_libs_video,media_kit_video,protobuf,watcher,win32,log_viewer,native_video_editor,ente_qr_ui,ente_icons,ente_rust,ente_pure_utils,backup_exclusion,ente_contacts,ente_qr
+# melos_managed_dependency_overrides: ente_cast,ente_crypto,ente_feature_flag,onnx_dart,ffi,flutter_sodium,intl,js,media_kit,media_kit_libs_ios_video,media_kit_libs_video,media_kit_video,protobuf,watcher,win32,log_viewer,native_video_editor,ente_qr_ui,ente_icons,ente_rust,ente_pure_utils,backup_exclusion,ente_contacts,ente_qr,ente_components
dependency_overrides:
cronet_http: 1.6.0
ente_cast:
@@ -61,3 +61,5 @@ dependency_overrides:
path: ../../packages/contacts
ente_qr:
path: plugins/ente_qr
+ ente_components:
+ path: ../../packages/ente_components