π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][settings] Refactor settings UI components for improved structure and consistency
AmanRajSinghMouryae8971fb7339c
diff --git a/mobile/apps/photos/lib/ui/settings/app_icon_selection_screen.dart b/mobile/apps/photos/lib/ui/settings/app_icon_selection_screen.dartindex ca145ce70c..9acec8e8a2 100644--- a/mobile/apps/photos/lib/ui/settings/app_icon_selection_screen.dart+++ b/mobile/apps/photos/lib/ui/settings/app_icon_selection_screen.dart@@ -1,3 +1,4 @@+import "package:ente_components/ente_components.dart";import "package:figma_squircle/figma_squircle.dart";import "package:flutter/material.dart";import "package:launcher_icon_switcher/launcher_icon_switcher.dart";@@ -5,9 +6,7 @@ import "package:logging/logging.dart";import "package:photos/l10n/l10n.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/common/loading_widget.dart";-import "package:photos/ui/components/buttons/icon_button_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/settings/components/settings_page_scaffold.dart";enum AppIcon {iconGreen("Default", "IconGreen", "assets/launcher_icon/icon-green.png"),@@ -18,7 +17,8 @@ enum AppIcon {"Ducky","IconDuckyHuggingE","assets/launcher_icon/icon-ducky-hugging-e.png",- );+ )+ ;final String name;final String id;@@ -45,74 +45,40 @@ class _AppIconSelectionScreenState extends State<AppIconSelectionScreen> {AppIcon.values.map((e) => e.id).toList(),AppIcon.iconGreen.id,);- _iconSwitcher.getCurrentIcon().then(- (icon) {- _logger.info("Current icon is " + icon);- setState(() {- _currentIcon = icon;+ _iconSwitcher+ .getCurrentIcon()+ .then((icon) {+ _logger.info("Current icon is " + icon);+ setState(() {+ _currentIcon = icon;+ });+ })+ .onError((error, stackTrace) {+ _logger.severe("Error getting current icon", error, stackTrace);});- },- ).onError(- (error, stackTrace) {- _logger.severe("Error getting current icon", error, stackTrace);- },- );}@overrideWidget build(BuildContext context) {- return Scaffold(- body: CustomScrollView(- primary: false,- slivers: <Widget>[- TitleBarWidget(- flexibleSpaceTitle: TitleBarTitleWidget(- title: context.l10n.appIcon,- ),- actionIcons: [- IconButtonWidget(- icon: Icons.close_outlined,- iconButtonType: IconButtonType.secondary,- onTap: () {- // TODO: Implement Navigator.popUntil, else if we move the- // screen to a different route, the button will not work as- // expected- Navigator.pop(context);- Navigator.pop(context);- Navigator.pop(context);- },+ return SettingsPageScaffold(+ title: context.l10n.appIcon,+ children: _currentIcon == null+ ? [+ SizedBox(+ height: MediaQuery.sizeOf(context).height / 2,+ child: EnteLoadingWidget(+ color: context.componentColors.strokeDark,+ ),),+ ]+ : [+ for (final icon in AppIcon.values)+ _AppIconTile(icon, icon.id == _currentIcon, () {+ if (icon.id != _currentIcon) {+ _changeIcon(icon.id);+ }+ }),],- ),- _currentIcon != null- ? SliverPadding(- padding: const EdgeInsets.symmetric(horizontal: 16),- sliver: SliverList(- delegate: SliverChildBuilderDelegate(- (delegateBuildContext, index) {- final icon = AppIcon.values[index];- final isCurrentIcon = icon.id == _currentIcon;- return _AppIconTile(- icon,- isCurrentIcon,- () {- if (!isCurrentIcon) {- _changeIcon(icon.id);- }- },- );- },- childCount: AppIcon.values.length,- ),- ),- )- : SliverToBoxAdapter(- child: EnteLoadingWidget(- color: getEnteColorScheme(context).strokeMuted,- ),- ),- ],- ),);}@@ -138,6 +104,7 @@ class _AppIconTile extends StatelessWidget {@overrideWidget build(BuildContext context) {+ final colors = context.componentColors;return Padding(padding: const EdgeInsets.symmetric(vertical: 8),child: GestureDetector(@@ -146,10 +113,8 @@ class _AppIconTile extends StatelessWidget {},child: Container(decoration: BoxDecoration(- color: getEnteColorScheme(context).fillFaint,- borderRadius: const BorderRadius.all(- Radius.circular(8),- ),+ color: colors.fillLight,+ borderRadius: const BorderRadius.all(Radius.circular(Radii.sm)),),padding: const EdgeInsets.symmetric(horizontal: 8),child: Row(@@ -185,9 +150,7 @@ class _AppIconTile extends StatelessWidget {child: Image(width: 60,height: 60,- image: AssetImage(- appIcon.path,- ),+ image: AssetImage(appIcon.path),),),const SizedBox(width: 12),@@ -199,8 +162,10 @@ class _AppIconTile extends StatelessWidget {key: ValueKey(isSelected),appIcon.name,style: isSelected- ? getEnteTextTheme(context).bodyBold- : getEnteTextTheme(context).bodyFaint,+ ? TextStyles.bodyBold.copyWith(+ color: colors.textBase,+ )+ : TextStyles.body.copyWith(color: colors.textLight),),),],diff --git a/mobile/apps/photos/lib/ui/settings/appearance/appearance_settings_page.dart b/mobile/apps/photos/lib/ui/settings/appearance/appearance_settings_page.dartindex 2bb42e40c6..9802dd25b2 100644--- a/mobile/apps/photos/lib/ui/settings/appearance/appearance_settings_page.dart+++ b/mobile/apps/photos/lib/ui/settings/appearance/appearance_settings_page.dart@@ -1,6 +1,7 @@import "dart:io";import "package:adaptive_theme/adaptive_theme.dart";+import "package:ente_components/ente_components.dart";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/foundation.dart";import "package:flutter/material.dart";@@ -8,9 +9,9 @@ import "package:hugeicons/hugeicons.dart";import "package:photos/app.dart";import "package:photos/generated/l10n.dart";import "package:photos/l10n/l10n.dart";-import "package:photos/theme/ente_theme.dart";-import "package:photos/ui/components/menu_item_widget/menu_item_widget_new.dart";import "package:photos/ui/settings/app_icon_selection_screen.dart";+import "package:photos/ui/settings/components/settings_item.dart";+import "package:photos/ui/settings/components/settings_page_scaffold.dart";import "package:photos/ui/settings/gallery_settings_screen.dart";import "package:photos/ui/settings/language_picker.dart";@@ -37,123 +38,58 @@ class _AppearanceSettingsPageState extends State<AppearanceSettingsPage> {@overrideWidget build(BuildContext context) {- final colorScheme = getEnteColorScheme(context);- final textTheme = getEnteTextTheme(context);+ final l10n = AppLocalizations.of(context);final isDarkMode = Theme.of(context).brightness == Brightness.dark;- 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).appearance,- style: textTheme.h3Bold,- ),- const SizedBox(height: 24),- Expanded(- child: SingleChildScrollView(- child: Column(- children: [- if (Platform.isAndroid || kDebugMode) ...[- MenuItemWidgetNew(- title: AppLocalizations.of(context).theme,- leadingIconWidget: _buildIconWidget(- context,- isDarkMode- ? HugeIcons.strokeRoundedMoon02- : HugeIcons.strokeRoundedSun03,- ),- trailingIcon: Icons.chevron_right_outlined,- trailingIconIsMuted: true,- onTap: () async => _showThemePicker(context),- ),- const SizedBox(height: 8),- ],- MenuItemWidgetNew(- title: context.l10n.appIcon,- leadingIconWidget: _buildIconWidget(- context,- HugeIcons.strokeRoundedImage02,- ),- trailingIcon: Icons.chevron_right_outlined,- trailingIconIsMuted: true,- onTap: () async {- await routeToPage(- context,- const AppIconSelectionScreen(),- );- },- ),- const SizedBox(height: 8),- MenuItemWidgetNew(- title: AppLocalizations.of(context).language,- leadingIconWidget: _buildIconWidget(- context,- HugeIcons.strokeRoundedTranslation,- ),- trailingIcon: Icons.chevron_right_outlined,- trailingIconIsMuted: true,- onTap: () async => _onLanguageTap(context),- ),- const SizedBox(height: 8),- MenuItemWidgetNew(- title: AppLocalizations.of(context).gallery,- leadingIconWidget: _buildIconWidget(- context,- HugeIcons.strokeRoundedImage01,- ),- trailingIcon: Icons.chevron_right_outlined,- trailingIconIsMuted: true,- onTap: () async {- await routeToPage(- context,- const GallerySettingsScreen(- fromGalleryLayoutSettingsCTA: false,- ),- );- },- ),- ],- ),- ),- ),- ],+ return SettingsPageScaffold(+ title: l10n.appearance,+ children: [+ if (Platform.isAndroid || kDebugMode) ...[+ SettingsItem(+ title: l10n.theme,+ icon: isDarkMode+ ? HugeIcons.strokeRoundedMoon02+ : HugeIcons.strokeRoundedSun03,+ onTap: () async => _showThemePicker(context),),+ const SizedBox(height: 8),+ ],+ SettingsItem(+ title: context.l10n.appIcon,+ icon: HugeIcons.strokeRoundedImage02,+ onTap: () async {+ await routeToPage(+ context,+ const AppIconSelectionScreen(),+ );+ },),- ),- );- }-- Widget _buildIconWidget(BuildContext context, List<List<dynamic>> icon) {- final colorScheme = getEnteColorScheme(context);- return HugeIcon(- icon: icon,- color: colorScheme.menuItemIconStroke,- size: 20,+ const SizedBox(height: 8),+ SettingsItem(+ title: l10n.language,+ icon: HugeIcons.strokeRoundedTranslation,+ onTap: () async => _onLanguageTap(context),+ ),+ const SizedBox(height: 8),+ SettingsItem(+ title: l10n.gallery,+ icon: HugeIcons.strokeRoundedImage01,+ onTap: () async {+ await routeToPage(+ context,+ const GallerySettingsScreen(+ fromGalleryLayoutSettingsCTA: false,+ ),+ );+ },+ ),+ ],);}Future<void> _showThemePicker(BuildContext context) async {- await showModalBottomSheet(+ await showBottomSheetComponent<void>(context: context,- backgroundColor: Colors.transparent,builder: (context) => _ThemePickerSheet(currentThemeMode: _currentThemeMode,onThemeChanged: (themeMode) {@@ -193,95 +129,55 @@ class _ThemePickerSheet extends StatelessWidget {@overrideWidget build(BuildContext context) {- final colorScheme = getEnteColorScheme(context);- final textTheme = getEnteTextTheme(context);- final isDarkMode = Theme.of(context).brightness == Brightness.dark;-- final sheetColor =- isDarkMode ? const Color(0xFF1E1E1E) : const Color(0xFFFFFFFF);-- return Container(- decoration: BoxDecoration(- color: sheetColor,- borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),- ),- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- const SizedBox(height: 8),- Container(- width: 36,- height: 4,- decoration: BoxDecoration(- color: colorScheme.strokeMuted,- borderRadius: BorderRadius.circular(2),- ),- ),- const SizedBox(height: 16),- Text(- AppLocalizations.of(context).theme,- style: textTheme.largeBold,- ),- const SizedBox(height: 16),- _ThemeOption(+ return BottomSheetComponent(+ title: AppLocalizations.of(context).theme,+ showCloseButton: false,+ content: MenuGroupComponent(+ items: [+ _themeOption(+ context,title: AppLocalizations.of(context).lightTheme,isSelected: currentThemeMode == AdaptiveThemeMode.light,- onTap: () {- onThemeChanged(AdaptiveThemeMode.light);- Navigator.pop(context);- },+ onTap: () => _selectTheme(context, AdaptiveThemeMode.light),),- _ThemeOption(+ _themeOption(+ context,title: AppLocalizations.of(context).darkTheme,isSelected: currentThemeMode == AdaptiveThemeMode.dark,- onTap: () {- onThemeChanged(AdaptiveThemeMode.dark);- Navigator.pop(context);- },+ onTap: () => _selectTheme(context, AdaptiveThemeMode.dark),),- _ThemeOption(+ _themeOption(+ context,title: AppLocalizations.of(context).systemTheme,isSelected: currentThemeMode == AdaptiveThemeMode.system,- onTap: () {- onThemeChanged(AdaptiveThemeMode.system);- Navigator.pop(context);- },+ onTap: () => _selectTheme(context, AdaptiveThemeMode.system),),- SizedBox(height: MediaQuery.of(context).padding.bottom + 16),],),);}-}-class _ThemeOption extends StatelessWidget {- final String title;- final bool isSelected;- final VoidCallback onTap;-- const _ThemeOption({- required this.title,- required this.isSelected,- required this.onTap,- });-- @override- Widget build(BuildContext context) {- final colorScheme = getEnteColorScheme(context);- final textTheme = getEnteTextTheme(context);-- return ListTile(- title: Text(- title,- style: textTheme.body,- ),+ MenuComponent _themeOption(+ BuildContext context, {+ required String title,+ required bool isSelected,+ required VoidCallback onTap,+ }) {+ return MenuComponent(+ title: title,trailing: isSelected- ? Icon(- Icons.check,- color: colorScheme.primary500,+ ? HugeIcon(+ icon: HugeIcons.strokeRoundedTick02,+ color: context.componentColors.primary,+ size: IconSizes.medium,): null,onTap: onTap,);}++ void _selectTheme(BuildContext context, AdaptiveThemeMode themeMode) {+ onThemeChanged(themeMode);+ Navigator.pop(context);+ }}diff --git a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dartindex 8fdbb89556..b22bee0d9f 100644--- a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart+++ b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart@@ -1,14 +1,14 @@-import "package:ente_pure_utils/ente_pure_utils.dart";+import "package:ente_components/ente_components.dart";import "package:flutter/material.dart";+import "package:photos/core/constants.dart";import "package:photos/core/event_bus.dart";+import "package:photos/events/force_reload_home_gallery_event.dart";import "package:photos/events/hide_shared_items_from_home_gallery_event.dart";import "package:photos/generated/l10n.dart";import "package:photos/service_locator.dart";-import "package:photos/theme/ente_theme.dart";-import "package:photos/ui/components/menu_item_widget/menu_item_widget_new.dart";-import "package:photos/ui/components/toggle_switch_widget.dart";-import "package:photos/ui/viewer/gallery/gallery_group_type_picker_page.dart";-import "package:photos/ui/viewer/gallery/photo_grid_size_picker_page.dart";+import "package:photos/ui/settings/components/settings_item.dart";+import "package:photos/ui/settings/components/settings_page_scaffold.dart";+import "package:photos/ui/viewer/gallery/component/group/type.dart";class GallerySettingsScreen extends StatefulWidget {final bool fromGalleryLayoutSettingsCTA;@@ -34,113 +34,149 @@ class _GallerySettingsScreenState extends State<GallerySettingsScreen> {@overrideWidget 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 SettingsPageScaffold(+ title: l10n.gallery,+ children: [+ SettingsItem(+ title: l10n.photoGridSize,+ trailing: _trailingLabel(context, _photoGridSize.toString()),+ onTap: () async => _showPhotoGridSizeSheet(context),+ ),+ const SizedBox(height: 8),+ SettingsItem(+ title: l10n.groupBy,+ trailing: _trailingLabel(context, _groupType),+ onTap: () async => _showGroupTypeSheet(context),+ ),+ if (!widget.fromGalleryLayoutSettingsCTA && !isLocalGalleryMode) ...[+ const SizedBox(height: 8),+ SettingsItem(+ title: l10n.hideSharedItemsFromHomeGallery,+ showChevron: false,+ trailing: ToggleSwitchComponent.async(+ value: () => localSettings.hideSharedItemsFromHomeGallery,+ onChanged: () async {+ final prevSetting =+ localSettings.hideSharedItemsFromHomeGallery;+ await localSettings.setHideSharedItemsFromHomeGallery(+ !prevSetting,+ );- 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).gallery,- style: textTheme.h3Bold,+ Bus.instance.fire(+ HideSharedItemsFromHomeGalleryEvent(!prevSetting),+ );+ },+ ),+ ),+ ],+ ],+ );+ }++ Widget _trailingLabel(BuildContext context, String label) {+ final colors = context.componentColors;+ return Text(+ label,+ style: TextStyles.mini.copyWith(color: colors.textLight),+ );+ }++ Future<void> _showPhotoGridSizeSheet(BuildContext context) async {+ final l10n = AppLocalizations.of(context);+ await showBottomSheetComponent<void>(+ context: context,+ builder: (sheetContext) => BottomSheetComponent(+ title: l10n.photoGridSize,+ content: MenuGroupComponent(+ items: [+ for (+ int gridSize = photoGridSizeMin;+ gridSize <= photoGridSizeMax;+ gridSize+++ )+ MenuComponent(+ key: ValueKey(gridSize),+ title: "$gridSize",+ trailing: _photoGridSize == gridSize+ ? Icon(+ Icons.check,+ color: sheetContext.componentColors.primary,+ )+ : null,+ onTap: () async {+ await _setPhotoGridSize(gridSize);+ if (sheetContext.mounted) {+ Navigator.of(sheetContext).pop();+ }+ },),- const SizedBox(height: 24),- Expanded(- child: SingleChildScrollView(- child: Column(- children: [- MenuItemWidgetNew(- title: AppLocalizations.of(context).photoGridSize,- trailingWidget: Text(- _photoGridSize.toString(),- style: textTheme.small,- ),- trailingIcon: Icons.chevron_right_outlined,- trailingIconIsMuted: true,- onTap: () async {- await routeToPage(- context,- const PhotoGridSizePickerPage(),- );- setState(() {- _photoGridSize = localSettings.getPhotoGridSize();- });- },- ),- const SizedBox(height: 8),- MenuItemWidgetNew(- title: AppLocalizations.of(context).groupBy,- trailingWidget: Text(- _groupType,- style: textTheme.small,- ),- trailingIcon: Icons.chevron_right_outlined,- trailingIconIsMuted: true,- onTap: () async {- await routeToPage(- context,- const GalleryGroupTypePickerPage(),- );- setState(() {- _groupType =- localSettings.getGalleryGroupType().name;- });- },- ),- if (!widget.fromGalleryLayoutSettingsCTA &&- !isLocalGalleryMode) ...[- const SizedBox(height: 8),- MenuItemWidgetNew(- title: AppLocalizations.of(- context,- ).hideSharedItemsFromHomeGallery,- trailingWidget: ToggleSwitchWidget(- value: () =>- localSettings.hideSharedItemsFromHomeGallery,- onChanged: () async {- final prevSetting =- localSettings.hideSharedItemsFromHomeGallery;- await localSettings- .setHideSharedItemsFromHomeGallery(- !prevSetting,- );+ ],+ ),+ ),+ );+ }++ Future<void> _setPhotoGridSize(int gridSize) async {+ await localSettings.setPhotoGridSize(gridSize);+ if (mounted) {+ setState(() {+ _photoGridSize = gridSize;+ });+ }+ Bus.instance.fire(+ ForceReloadHomeGalleryEvent("grid size changed"),+ );+ }- Bus.instance.fire(- HideSharedItemsFromHomeGalleryEvent(- !prevSetting,- ),- );- },- ),- ),- ],- ],- ),- ),+ Future<void> _showGroupTypeSheet(BuildContext context) async {+ final l10n = AppLocalizations.of(context);+ final currentGroupType = localSettings.getGalleryGroupType();+ await showBottomSheetComponent<void>(+ context: context,+ builder: (sheetContext) => BottomSheetComponent(+ title: l10n.groupBy,+ content: MenuGroupComponent(+ items: [+ for (final groupType in _groupTypes)+ MenuComponent(+ key: ValueKey(groupType.name),+ title: groupType.getLocalizedName(sheetContext),+ trailing: currentGroupType == groupType+ ? Icon(+ Icons.check,+ color: sheetContext.componentColors.primary,+ )+ : null,+ onTap: () async {+ await _setGroupType(groupType);+ if (sheetContext.mounted) {+ Navigator.of(sheetContext).pop();+ }+ },),- ],- ),+ ],),),);}++ List<GroupType> get _groupTypes {+ return GroupType.values+ .where((type) => type != GroupType.size && type != GroupType.none)+ .toList();+ }++ Future<void> _setGroupType(GroupType groupType) async {+ await localSettings.setGalleryGroupType(groupType);+ if (mounted) {+ setState(() {+ _groupType = groupType.name;+ });+ }+ Bus.instance.fire(+ ForceReloadHomeGalleryEvent("group type changed"),+ );+ }}diff --git a/mobile/apps/photos/lib/ui/settings/theme_switch_widget.dart b/mobile/apps/photos/lib/ui/settings/theme_switch_widget.dartdeleted file mode 100644index 3914dd007a..0000000000--- a/mobile/apps/photos/lib/ui/settings/theme_switch_widget.dart+++ /dev/null@@ -1,96 +0,0 @@-import 'package:adaptive_theme/adaptive_theme.dart';-import 'package:flutter/material.dart';-import 'package:photos/ente_theme_data.dart';-import "package:photos/generated/l10n.dart";-import 'package:photos/theme/ente_theme.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/settings/common_settings.dart';--class ThemeSwitchWidget extends StatefulWidget {- const ThemeSwitchWidget({super.key});-- @override- State<ThemeSwitchWidget> createState() => _ThemeSwitchWidgetState();-}--class _ThemeSwitchWidgetState extends State<ThemeSwitchWidget> {- AdaptiveThemeMode? currentThemeMode;-- @override- void initState() {- super.initState();- AdaptiveTheme.getThemeMode().then(- (value) {- currentThemeMode = value ?? AdaptiveThemeMode.system;- debugPrint('theme value $value');- if (mounted) {- setState(() => {});- }- },- );- }-- @override- void dispose() {- super.dispose();- }-- @override- Widget build(BuildContext context) {- return ExpandableMenuItemWidget(- title: AppLocalizations.of(context).theme,- selectionOptionsWidget: _getSectionOptions(context),- leadingIcon: Theme.of(context).brightness == Brightness.light- ? Icons.light_mode_outlined- : Icons.dark_mode_outlined,- );- }-- Widget _getSectionOptions(BuildContext context) {- return Column(- children: [- sectionOptionSpacing,- _menuItem(context, AdaptiveThemeMode.light),- sectionOptionSpacing,- _menuItem(context, AdaptiveThemeMode.dark),- sectionOptionSpacing,- _menuItem(context, AdaptiveThemeMode.system),- sectionOptionSpacing,- ],- );- }-- Widget _menuItem(BuildContext context, AdaptiveThemeMode themeMode) {- late String themeName;- switch (themeMode) {- case AdaptiveThemeMode.light:- themeName = AppLocalizations.of(context).lightTheme;- break;- case AdaptiveThemeMode.dark:- themeName = AppLocalizations.of(context).darkTheme;- break;- case AdaptiveThemeMode.system:- themeName = AppLocalizations.of(context).systemTheme;- break;- }- return MenuItemWidget(- captionedTextWidget: CaptionedTextWidget(- title: themeName,- textStyle: Theme.of(context).colorScheme.enteTheme.textTheme.body,- ),- pressedColor: getEnteColorScheme(context).fillFaint,- isExpandable: false,- trailingIcon: currentThemeMode == themeMode ? Icons.check : null,- trailingExtraMargin: 4,- onTap: () async {- AdaptiveTheme.of(context).setThemeMode(themeMode);- currentThemeMode = themeMode;- if (mounted) {- setState(() {});- }- },- );- }-}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_group_type_picker_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_group_type_picker_page.dartdeleted file mode 100644index 7798303d4b..0000000000--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_group_type_picker_page.dart+++ /dev/null@@ -1,137 +0,0 @@-import 'package:flutter/material.dart';-import 'package:photos/core/event_bus.dart';-import 'package:photos/events/force_reload_home_gallery_event.dart';-import "package:photos/generated/l10n.dart";-import "package:photos/service_locator.dart";-import 'package:photos/theme/ente_theme.dart';-import "package:photos/ui/components/buttons/icon_button_widget.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/viewer/gallery/component/group/type.dart';-import 'package:photos/utils/separators_util.dart';--class GalleryGroupTypePickerPage extends StatelessWidget {- const GalleryGroupTypePickerPage({super.key});-- @override- Widget build(BuildContext context) {- return Scaffold(- body: CustomScrollView(- primary: false,- slivers: <Widget>[- TitleBarWidget(- flexibleSpaceTitle: TitleBarTitleWidget(- title: AppLocalizations.of(context).groupBy,- ),- actionIcons: [- IconButtonWidget(- icon: Icons.close_outlined,- iconButtonType: IconButtonType.secondary,- onTap: () {- Navigator.pop(context);- Navigator.pop(context);- Navigator.pop(context);- },- ),- ],- ),- SliverList(- delegate: SliverChildBuilderDelegate(- (context, index) {- return const Padding(- padding: EdgeInsets.symmetric(- horizontal: 16,- vertical: 20,- ),- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- ClipRRect(- borderRadius: BorderRadius.all(Radius.circular(8)),- child: ItemsWidget(),- ),- ],- ),- );- },- childCount: 1,- ),- ),- const SliverPadding(padding: EdgeInsets.symmetric(vertical: 12)),- ],- ),- );- }-}--class ItemsWidget extends StatefulWidget {- const ItemsWidget({super.key});-- @override- State<ItemsWidget> createState() => _ItemsWidgetState();-}--class _ItemsWidgetState extends State<ItemsWidget> {- late GroupType currentGroupType;- List<Widget> items = [];- final groupTypes = GroupType.values- .where(- (type) => type != GroupType.size && type != GroupType.none,- )- .toList();-- @override- void initState() {- super.initState();- currentGroupType = localSettings.getGalleryGroupType();- }-- @override- Widget build(BuildContext context) {- items.clear();- for (final groupType in groupTypes) {- items.add(- _menuItemForPicker(groupType),- );- }- items = addSeparators(- items,- DividerWidget(- dividerType: DividerType.menuNoIcon,- bgColor: getEnteColorScheme(context).fillFaint,- ),- );- return Column(- mainAxisSize: MainAxisSize.min,- children: items,- );- }-- Widget _menuItemForPicker(GroupType groupType) {- return MenuItemWidget(- key: ValueKey(groupType.name),- menuItemColor: getEnteColorScheme(context).fillFaint,- captionedTextWidget: CaptionedTextWidget(- title: groupType.getLocalizedName(context),- ),- trailingIcon: currentGroupType == groupType ? Icons.check : null,- alignCaptionedTextToLeft: true,- isTopBorderRadiusRemoved: true,- isBottomBorderRadiusRemoved: true,- showOnlyLoadingState: true,- onTap: () async {- await localSettings.setGalleryGroupType(groupType).then(- (value) => setState(() {- currentGroupType = groupType;- }),- );- Bus.instance.fire(- ForceReloadHomeGalleryEvent("group type changed"),- );- },- );- }-}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/photo_grid_size_picker_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/photo_grid_size_picker_page.dartdeleted file mode 100644index 42264180e2..0000000000--- a/mobile/apps/photos/lib/ui/viewer/gallery/photo_grid_size_picker_page.dart+++ /dev/null@@ -1,137 +0,0 @@-import 'package:flutter/material.dart';-import 'package:photos/core/constants.dart';-import 'package:photos/core/event_bus.dart';-import 'package:photos/events/force_reload_home_gallery_event.dart';-import "package:photos/generated/l10n.dart";-import "package:photos/service_locator.dart";-import 'package:photos/theme/ente_theme.dart';-import "package:photos/ui/components/buttons/icon_button_widget.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/utils/separators_util.dart';--class PhotoGridSizePickerPage extends StatelessWidget {- const PhotoGridSizePickerPage({super.key});-- @override- Widget build(BuildContext context) {- return Scaffold(- body: CustomScrollView(- primary: false,- slivers: <Widget>[- TitleBarWidget(- flexibleSpaceTitle: TitleBarTitleWidget(- title: AppLocalizations.of(context).photoGridSize,- ),- actionIcons: [- IconButtonWidget(- icon: Icons.close_outlined,- iconButtonType: IconButtonType.secondary,- onTap: () {- Navigator.pop(context);- Navigator.pop(context);- Navigator.pop(context);- },- ),- ],- ),- SliverList(- delegate: SliverChildBuilderDelegate(- (context, index) {- return const Padding(- padding: EdgeInsets.symmetric(- horizontal: 16,- vertical: 20,- ),- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- ClipRRect(- borderRadius: BorderRadius.all(Radius.circular(8)),- child: ItemsWidget(),- ),- ],- ),- );- },- childCount: 1,- ),- ),- const SliverPadding(padding: EdgeInsets.symmetric(vertical: 12)),- ],- ),- );- }-}--class ItemsWidget extends StatefulWidget {- const ItemsWidget({super.key});-- @override- State<ItemsWidget> createState() => _ItemsWidgetState();-}--class _ItemsWidgetState extends State<ItemsWidget> {- late int currentGridSize;- List<Widget> items = [];- final List<int> gridSizes = [];- @override- void initState() {- currentGridSize = localSettings.getPhotoGridSize();- for (int gridSize = photoGridSizeMin;- gridSize <= photoGridSizeMax;- gridSize++) {- gridSizes.add(gridSize);- }- super.initState();- }-- @override- Widget build(BuildContext context) {- items.clear();- for (int girdSize in gridSizes) {- items.add(- _menuItemForPicker(girdSize),- );- }- items = addSeparators(- items,- DividerWidget(- dividerType: DividerType.menuNoIcon,- bgColor: getEnteColorScheme(context).fillFaint,- ),- );- return Column(- mainAxisSize: MainAxisSize.min,- children: items,- );- }-- Widget _menuItemForPicker(int gridSize) {- return MenuItemWidget(- key: ValueKey(gridSize),- menuItemColor: getEnteColorScheme(context).fillFaint,- captionedTextWidget: CaptionedTextWidget(- title: "$gridSize",- ),- trailingIcon: currentGridSize == gridSize ? Icons.check : null,- alignCaptionedTextToLeft: true,- isTopBorderRadiusRemoved: true,- isBottomBorderRadiusRemoved: true,- showOnlyLoadingState: true,- onTap: () async {- await localSettings.setPhotoGridSize(gridSize).then(- (value) => setState(() {- currentGridSize = gridSize;- }),- );- Bus.instance.fire(- ForceReloadHomeGalleryEvent("grid size changed"),- );- },- );- }-}diff --git a/mobile/packages/ente_components/lib/components/menu_component.dart b/mobile/packages/ente_components/lib/components/menu_component.dartindex fcb6b8ae42..ed72eee2e5 100644--- a/mobile/packages/ente_components/lib/components/menu_component.dart+++ b/mobile/packages/ente_components/lib/components/menu_component.dart@@ -1,4 +1,5 @@import 'dart:async';+import 'dart:math' as math;import 'package:ente_components/models/component_execution_state.dart';import 'package:ente_components/src/components/menu_component_surface_style.dart';@@ -16,6 +17,8 @@ const double _leadingSlotSize = 36;const double _trailingSlotSize = 36;const Duration _loadingDelay = Duration(milliseconds: 300);const Duration _successDisplayDuration = Duration(seconds: 1);+const int _maxTitleLines = 2;+const int _maxCombinedTextLines = 3;/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=4055-18734&m=dev/// Section: List items / Menu Item@@ -36,7 +39,7 @@ class MenuComponent extends StatefulWidget {this.shouldSurfaceExecutionStates = false,this.shouldShowSuccessConfirmation = false,this.titleMaxLines = 2,- this.subtitleMaxLines = 1,+ this.subtitleMaxLines = 2,this.titleColor,this.iconColor,});@@ -138,30 +141,40 @@ class _MenuComponentState extends State<MenuComponent> {const SizedBox(width: Spacing.md),],Expanded(- child: Column(- mainAxisAlignment: MainAxisAlignment.center,- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Text(- widget.title,- maxLines: widget.titleMaxLines,- overflow: TextOverflow.ellipsis,- style: TextStyles.body.copyWith(- color: widget.titleColor ?? colors.textBase,- ),- ),- if (widget.subtitle != null) ...[- const SizedBox(height: Spacing.xs),- Text(- widget.subtitle!,- maxLines: widget.subtitleMaxLines,- overflow: TextOverflow.ellipsis,- style: TextStyles.mini.copyWith(- color: colors.textLight,+ child: LayoutBuilder(+ builder: (context, constraints) {+ final titleMaxLines = _effectiveTitleMaxLines;+ final subtitleMaxLines = _effectiveSubtitleMaxLines(+ context,+ constraints.maxWidth,+ titleMaxLines,+ );+ return Column(+ mainAxisAlignment: MainAxisAlignment.center,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ widget.title,+ maxLines: titleMaxLines,+ overflow: TextOverflow.ellipsis,+ style: TextStyles.body.copyWith(+ color: widget.titleColor ?? colors.textBase,+ ),),- ),- ],- ],+ if (widget.subtitle != null) ...[+ const SizedBox(height: Spacing.xs),+ Text(+ widget.subtitle!,+ maxLines: subtitleMaxLines,+ overflow: TextOverflow.ellipsis,+ style: TextStyles.mini.copyWith(+ color: colors.textLight,+ ),+ ),+ ],+ ],+ );+ },),),if (shouldReserveTrailingSlot) ...[@@ -214,6 +227,54 @@ class _MenuComponentState extends State<MenuComponent> {bool get _isBusy => _executionState == ComponentExecutionState.inProgress;+ int get _effectiveTitleMaxLines {+ return math.min(_positiveLineCount(widget.titleMaxLines), _maxTitleLines);+ }++ int _effectiveSubtitleMaxLines(+ BuildContext context,+ double maxWidth,+ int titleMaxLines,+ ) {+ if (widget.subtitle == null) {+ return 0;+ }+ final requestedSubtitleLines = _positiveLineCount(widget.subtitleMaxLines);+ final titleLineCount = _measuredTitleLineCount(+ context,+ maxWidth,+ titleMaxLines,+ );+ final remainingLines = _maxCombinedTextLines - titleLineCount;+ return math.min(requestedSubtitleLines, math.max(1, remainingLines));+ }++ int _measuredTitleLineCount(+ BuildContext context,+ double maxWidth,+ int titleMaxLines,+ ) {+ if (!maxWidth.isFinite || maxWidth <= 0) {+ return titleMaxLines;+ }++ final painter = TextPainter(+ text: TextSpan(text: widget.title, style: TextStyles.body),+ maxLines: titleMaxLines,+ textDirection: Directionality.maybeOf(context) ?? TextDirection.ltr,+ textScaler: MediaQuery.textScalerOf(context),+ locale: Localizations.maybeLocaleOf(context),+ )..layout(maxWidth: maxWidth);+ return math.max(+ 1,+ math.min(titleMaxLines, painter.computeLineMetrics().length),+ );+ }++ int _positiveLineCount(int value) {+ return math.max(1, value);+ }+void _handleDoubleTap() {final onDoubleTap = widget.onDoubleTap;if (onDoubleTap == null) {diff --git a/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart b/mobile/packages/ente_components/test/components/app_surface_widgets_test.dartindex f8dfb3b150..b7c317c545 100644--- a/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart+++ b/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart@@ -67,7 +67,7 @@ void main() {final decoration = surface.decoration! as BoxDecoration;expect(decoration.border, isNotNull);expect(tester.widget<Text>(find.text('Camera uploads')).maxLines, 2);- expect(tester.widget<Text>(find.text('Enabled on Wi-Fi')).maxLines, 1);+ expect(tester.widget<Text>(find.text('Enabled on Wi-Fi')).maxLines, 2);expect(tester.widget<Text>(find.text('Camera uploads')).style?.color,ColorTokens.light.warning,@@ -421,6 +421,28 @@ void main() {await tester.pump(const Duration(milliseconds: 200));});+ testWidgets('MenuComponent allows two subtitle lines for one-line titles', (+ tester,+ ) async {+ const subtitle =+ 'This subtitle can use two lines when the title fits on one line';++ await pumpComponent(+ tester,+ const MenuComponent(+ title: 'Camera uploads',+ subtitle: subtitle,+ leading: Icon(Icons.image_outlined),+ trailing: Icon(Icons.chevron_right),+ ),+ width: 320,+ );++ expect(tester.widget<Text>(find.text('Camera uploads')).maxLines, 2);+ expect(tester.widget<Text>(find.text(subtitle)).maxLines, 2);+ expect(tester.getSize(find.byType(MenuComponent)).height, greaterThan(60));+ });+testWidgets('MenuComponent long text uses two title lines and one subtitle line', (tester,) async {@@ -632,6 +654,47 @@ void main() {expect(scrollController.offset, closeTo(0, 1));});+ testWidgets('AppBarComponent updates header colors when theme changes', (+ tester,+ ) async {+ Widget buildWithTheme(ThemeMode themeMode) {+ return MaterialApp(+ theme: ComponentTheme.lightTheme(),+ darkTheme: ComponentTheme.darkTheme(),+ themeMode: themeMode,+ home: const MediaQuery(+ data: MediaQueryData(),+ child: Scaffold(+ body: AppBarComponent(+ title: 'Appearance',+ slivers: [+ SliverToBoxAdapter(+ child: SizedBox(height: 80, child: Text('Theme')),+ ),+ ],+ ),+ ),+ ),+ );+ }++ Color headerColor() {+ final headerBackground = find.descendant(+ of: find.byType(SliverPersistentHeader),+ matching: find.byType(ColoredBox),+ );+ return tester.widget<ColoredBox>(headerBackground.first).color;+ }++ await tester.pumpWidget(buildWithTheme(ThemeMode.light));+ await tester.pump();+ expect(headerColor(), ColorTokens.light.backgroundBase);++ await tester.pumpWidget(buildWithTheme(ThemeMode.dark));+ await tester.pumpAndSettle();+ expect(headerColor(), ColorTokens.dark.backgroundBase);+ });+testWidgets('SliverAppBarComponent adapts vertical space for large text', (tester,) async {