Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Add search functionality to settings screen

Neeraj Guptafcd884678f29
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arb
index 651c1ef862..1591a04372 100644
--- a/mobile/apps/photos/lib/l10n/intl_en.arb
+++ b/mobile/apps/photos/lib/l10n/intl_en.arb
@@ -2499,5 +2499,7 @@
"type": "int"
}
}
- }
+ },
+ "searchSettings": "Search settings",
+ "suggestions": "Suggestions"
}
diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_item.dart b/mobile/apps/photos/lib/ui/settings/search/settings_search_item.dart
new file mode 100644
index 0000000000..8f9dc1e201
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/settings/search/settings_search_item.dart
@@ -0,0 +1,70 @@
+import "package:flutter/material.dart";
+
+/// Represents a searchable settings item
+class SettingsSearchItem {
+ /// The title of the settings item
+ final String title;
+
+ /// Optional subtitle for more context
+ final String? subtitle;
+
+ /// Icon data for the item
+ final List<List<dynamic>>? icon;
+
+ /// The page/section path for navigation breadcrumb
+ final String sectionPath;
+
+ /// Whether this item represents a nested page
+ final bool isSubPage;
+
+ /// The route builder to navigate to this setting
+ final Widget Function(BuildContext context) routeBuilder;
+
+ /// Optional keywords for better search matching
+ final List<String> keywords;
+
+ const SettingsSearchItem({
+ required this.title,
+ this.subtitle,
+ this.icon,
+ required this.sectionPath,
+ required this.routeBuilder,
+ this.isSubPage = false,
+ this.keywords = const [],
+ });
+
+ /// Check if this item matches the search query
+ bool matchesQuery(String query) {
+ final normalizedQuery = query.toLowerCase().trim();
+ if (normalizedQuery.isEmpty) return false;
+
+ // Check title
+ if (title.toLowerCase().contains(normalizedQuery)) return true;
+
+ // Check subtitle
+ if (subtitle?.toLowerCase().contains(normalizedQuery) ?? false) return true;
+
+ // Check section path
+ if (sectionPath.toLowerCase().contains(normalizedQuery)) return true;
+
+ // Check keywords
+ for (final keyword in keywords) {
+ if (keyword.toLowerCase().contains(normalizedQuery)) return true;
+ }
+
+ return false;
+ }
+}
+
+/// Represents a quick suggestion shown when search is empty
+class SettingsSearchSuggestion {
+ final String title;
+ final List<List<dynamic>>? icon;
+ final VoidCallback onTap;
+
+ const SettingsSearchSuggestion({
+ required this.title,
+ this.icon,
+ required this.onTap,
+ });
+}
diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_page.dart b/mobile/apps/photos/lib/ui/settings/search/settings_search_page.dart
new file mode 100644
index 0000000000..df42aee4b9
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/settings/search/settings_search_page.dart
@@ -0,0 +1,327 @@
+import "package:ente_pure_utils/ente_pure_utils.dart";
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:photos/generated/l10n.dart";
+import "package:photos/theme/colors.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/theme/text_style.dart";
+import "package:photos/ui/settings/search/settings_search_item.dart";
+import "package:photos/ui/settings/search/settings_search_registry.dart";
+
+class SettingsSearchPage extends StatefulWidget {
+ const SettingsSearchPage({super.key});
+
+ @override
+ State<SettingsSearchPage> createState() => _SettingsSearchPageState();
+}
+
+class _SettingsSearchPageState extends State<SettingsSearchPage> {
+ final TextEditingController _searchController = TextEditingController();
+ final FocusNode _searchFocusNode = FocusNode();
+ String _searchQuery = "";
+ List<SettingsSearchItem>? _allItems;
+ List<SettingsSearchItem> _filteredItems = [];
+
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ _searchFocusNode.requestFocus();
+ });
+ }
+
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+ // Only initialize once
+ _allItems ??= SettingsSearchRegistry.getSearchableItems(context);
+ }
+
+ @override
+ void dispose() {
+ _searchController.dispose();
+ _searchFocusNode.dispose();
+ super.dispose();
+ }
+
+ void _onSearchChanged(String query) {
+ setState(() {
+ _searchQuery = query;
+ if (query.isEmpty || _allItems == null) {
+ _filteredItems = [];
+ } else {
+ _filteredItems =
+ _allItems!.where((item) => item.matchesQuery(query)).toList();
+ }
+ });
+ }
+
+ void _clearSearch() {
+ _searchController.clear();
+ _onSearchChanged("");
+ }
+
+ void _navigateToSetting(Widget Function(BuildContext) routeBuilder) {
+ Navigator.of(context).pop();
+ routeToPage(context, routeBuilder(context));
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(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: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _buildSearchBar(colorScheme, textTheme),
+ Expanded(
+ child: _searchQuery.isEmpty
+ ? _buildSuggestions(colorScheme, textTheme)
+ : _buildSearchResults(colorScheme, textTheme),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _buildSearchBar(EnteColorScheme colorScheme, EnteTextTheme textTheme) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
+ child: Container(
+ height: 48,
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ child: Row(
+ children: [
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12),
+ child: Icon(
+ Icons.search_rounded,
+ size: 24,
+ color: colorScheme.textMuted,
+ ),
+ ),
+ Expanded(
+ child: TextField(
+ controller: _searchController,
+ focusNode: _searchFocusNode,
+ onChanged: _onSearchChanged,
+ style: textTheme.small.copyWith(color: colorScheme.textBase),
+ cursorColor: colorScheme.textBase,
+ decoration: InputDecoration(
+ hintText: AppLocalizations.of(context).searchSettings,
+ hintStyle: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ ),
+ border: InputBorder.none,
+ enabledBorder: InputBorder.none,
+ focusedBorder: InputBorder.none,
+ contentPadding: EdgeInsets.zero,
+ ),
+ ),
+ ),
+ if (_searchQuery.isNotEmpty)
+ GestureDetector(
+ onTap: _clearSearch,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12),
+ child: Icon(
+ Icons.cancel_rounded,
+ size: 16,
+ color: colorScheme.textMuted,
+ ),
+ ),
+ )
+ else
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12),
+ child: Icon(
+ Icons.close_rounded,
+ size: 16,
+ color: colorScheme.textMuted,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _buildSuggestions(
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+ ) {
+ final suggestions = SettingsSearchRegistry.getSuggestions(
+ context,
+ (routeBuilder) => _navigateToSetting(routeBuilder),
+ );
+
+ // Group suggestions into rows of 2
+ final List<List<SettingsSearchSuggestion>> rows = [];
+ for (int i = 0; i < suggestions.length; i += 2) {
+ rows.add(
+ suggestions.sublist(
+ i,
+ i + 2 > suggestions.length ? suggestions.length : i + 2,
+ ),
+ );
+ }
+
+ return SingleChildScrollView(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 8),
+ Text(
+ AppLocalizations.of(context).suggestions,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textBase,
+ fontWeight: FontWeight.w500,
+ ),
+ ),
+ const SizedBox(height: 12),
+ ...rows.map(
+ (row) => Padding(
+ padding: const EdgeInsets.only(bottom: 8),
+ child: Row(
+ children: row
+ .map(
+ (suggestion) => Padding(
+ padding: const EdgeInsets.only(right: 8),
+ child: _buildSuggestionChip(
+ suggestion,
+ colorScheme,
+ textTheme,
+ ),
+ ),
+ )
+ .toList(),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _buildSuggestionChip(
+ SettingsSearchSuggestion suggestion,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+ ) {
+ return GestureDetector(
+ onTap: suggestion.onTap,
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 13, vertical: 12),
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ child: Text(
+ suggestion.title,
+ style: textTheme.mini.copyWith(
+ color: colorScheme.textMuted,
+ fontWeight: FontWeight.w500,
+ ),
+ ),
+ ),
+ );
+ }
+
+ Widget _buildSearchResults(
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+ ) {
+ if (_filteredItems.isEmpty) {
+ return Center(
+ child: Padding(
+ padding: const EdgeInsets.all(32),
+ child: Text(
+ AppLocalizations.of(context).noResultsFound,
+ style: textTheme.body.copyWith(color: colorScheme.textMuted),
+ ),
+ ),
+ );
+ }
+
+ return ListView.builder(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ itemCount: _filteredItems.length,
+ itemBuilder: (context, index) {
+ final item = _filteredItems[index];
+ return _buildSearchResultItem(item, colorScheme, textTheme);
+ },
+ );
+ }
+
+ Widget _buildSearchResultItem(
+ SettingsSearchItem item,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+ ) {
+ return GestureDetector(
+ onTap: () => _navigateToSetting(item.routeBuilder),
+ child: Container(
+ margin: const EdgeInsets.only(bottom: 8),
+ padding: const EdgeInsets.all(16),
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ child: Row(
+ children: [
+ if (item.icon != null) ...[
+ HugeIcon(
+ icon: item.icon!,
+ color: colorScheme.menuItemIconStroke,
+ size: 20,
+ ),
+ const SizedBox(width: 12),
+ ],
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ item.title,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textBase,
+ ),
+ ),
+ if (item.isSubPage) ...[
+ const SizedBox(height: 2),
+ Text(
+ item.sectionPath,
+ style: textTheme.mini.copyWith(
+ color: colorScheme.textMuted,
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ Icon(
+ Icons.chevron_right_outlined,
+ size: 20,
+ color: colorScheme.strokeMuted,
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
new file mode 100644
index 0000000000..653a207156
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
@@ -0,0 +1,262 @@
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:photos/core/configuration.dart";
+import "package:photos/generated/l10n.dart";
+import "package:photos/ui/settings/about/about_us_page.dart";
+import "package:photos/ui/settings/account/account_settings_page.dart";
+import "package:photos/ui/settings/appearance/appearance_settings_page.dart";
+import "package:photos/ui/settings/backup/backup_settings_page.dart";
+import "package:photos/ui/settings/backup/free_space_options.dart";
+import "package:photos/ui/settings/gallery_settings_screen.dart";
+import "package:photos/ui/settings/ml/machine_learning_settings_page.dart";
+import "package:photos/ui/settings/search/settings_search_item.dart";
+import "package:photos/ui/settings/security/security_settings_page.dart";
+import "package:photos/ui/settings/support/help_support_page.dart";
+
+/// Registry that provides all searchable settings items
+class SettingsSearchRegistry {
+ static List<SettingsSearchItem> getSearchableItems(BuildContext context) {
+ final l10n = AppLocalizations.of(context);
+ final hasLoggedIn = Configuration.instance.isLoggedIn();
+ final items = <SettingsSearchItem>[];
+
+ // Account settings
+ if (hasLoggedIn) {
+ items.add(
+ SettingsSearchItem(
+ title: l10n.account,
+ sectionPath: l10n.account,
+ icon: HugeIcons.strokeRoundedUser,
+ routeBuilder: (_) => const AccountSettingsPage(),
+ keywords: ["email", "password", "delete", "subscription"],
+ ),
+ );
+ }
+
+ // Backup settings
+ if (hasLoggedIn) {
+ items.add(
+ SettingsSearchItem(
+ title: l10n.backup,
+ sectionPath: l10n.backup,
+ icon: HugeIcons.strokeRoundedCloudUpload,
+ routeBuilder: (_) => const BackupSettingsPage(),
+ keywords: ["sync", "upload", "photos", "videos"],
+ ),
+ );
+ }
+
+ // Security settings
+ items.add(
+ SettingsSearchItem(
+ title: l10n.security,
+ sectionPath: l10n.security,
+ icon: HugeIcons.strokeRoundedSecurityCheck,
+ routeBuilder: (_) => const SecuritySettingsPage(),
+ keywords: [
+ "lock",
+ "pin",
+ "biometric",
+ "fingerprint",
+ "face id",
+ "2fa",
+ "two factor",
+ "authentication",
+ "recovery key",
+ ],
+ ),
+ );
+
+ // Appearance settings
+ items.add(
+ SettingsSearchItem(
+ title: l10n.appearance,
+ sectionPath: l10n.appearance,
+ icon: HugeIcons.strokeRoundedPaintBoard,
+ routeBuilder: (_) => const AppearanceSettingsPage(),
+ keywords: ["theme", "dark mode", "light mode", "app icon"],
+ ),
+ );
+
+ // Gallery settings (under Appearance)
+ items.add(
+ SettingsSearchItem(
+ title: l10n.gallery,
+ subtitle: l10n.appearance,
+ sectionPath: "${l10n.appearance} > ${l10n.gallery}",
+ icon: HugeIcons.strokeRoundedDashboardSquare02,
+ routeBuilder: (_) => const GallerySettingsScreen(
+ fromGalleryLayoutSettingsCTA: false,
+ ),
+ isSubPage: true,
+ keywords: ["grid size", "group by", "layout"],
+ ),
+ );
+
+ // Grid Size setting
+ items.add(
+ SettingsSearchItem(
+ title: l10n.photoGridSize,
+ subtitle: l10n.gallery,
+ sectionPath: "${l10n.appearance} > ${l10n.gallery}",
+ icon: HugeIcons.strokeRoundedDashboardSquare02,
+ routeBuilder: (_) => const GallerySettingsScreen(
+ fromGalleryLayoutSettingsCTA: false,
+ ),
+ isSubPage: true,
+ keywords: ["grid", "size", "columns", "thumbnail"],
+ ),
+ );
+
+ // Group By setting
+ items.add(
+ SettingsSearchItem(
+ title: l10n.groupBy,
+ subtitle: l10n.gallery,
+ sectionPath: "${l10n.appearance} > ${l10n.gallery}",
+ icon: HugeIcons.strokeRoundedDashboardSquare02,
+ routeBuilder: (_) => const GallerySettingsScreen(
+ fromGalleryLayoutSettingsCTA: false,
+ ),
+ isSubPage: true,
+ keywords: ["group", "day", "month", "year"],
+ ),
+ );
+
+ // Machine Learning settings
+ if (hasLoggedIn) {
+ items.add(
+ SettingsSearchItem(
+ title: l10n.machineLearning,
+ sectionPath: l10n.machineLearning,
+ icon: HugeIcons.strokeRoundedMagicWand01,
+ routeBuilder: (_) => const MachineLearningSettingsPage(),
+ keywords: [
+ "ml",
+ "ai",
+ "faces",
+ "people",
+ "magic search",
+ "similar images",
+ "duplicates",
+ ],
+ ),
+ );
+ }
+
+ // Free up space
+ if (hasLoggedIn) {
+ items.add(
+ SettingsSearchItem(
+ title: l10n.freeUpSpace,
+ sectionPath: l10n.freeUpSpace,
+ icon: HugeIcons.strokeRoundedRocket01,
+ routeBuilder: (_) => const FreeUpSpaceOptionsScreen(),
+ keywords: [
+ "storage",
+ "space",
+ "clean",
+ "delete",
+ "local",
+ "device",
+ ],
+ ),
+ );
+
+ // Remove duplicates (under Free up space)
+ items.add(
+ SettingsSearchItem(
+ title: l10n.removeDuplicates,
+ subtitle: l10n.freeUpSpace,
+ sectionPath: l10n.freeUpSpace,
+ icon: HugeIcons.strokeRoundedRocket01,
+ routeBuilder: (_) => const FreeUpSpaceOptionsScreen(),
+ isSubPage: true,
+ keywords: [
+ "duplicate",
+ "duplicates",
+ "same",
+ "identical",
+ "copy",
+ "copies",
+ ],
+ ),
+ );
+
+ // Similar images (under Free up space)
+ items.add(
+ SettingsSearchItem(
+ title: l10n.similarImages,
+ subtitle: l10n.freeUpSpace,
+ sectionPath: l10n.freeUpSpace,
+ icon: HugeIcons.strokeRoundedRocket01,
+ routeBuilder: (_) => const FreeUpSpaceOptionsScreen(),
+ isSubPage: true,
+ keywords: [
+ "similar",
+ "alike",
+ "resembling",
+ "cleanup",
+ ],
+ ),
+ );
+ }
+
+ // Help & Support
+ items.add(
+ SettingsSearchItem(
+ title: l10n.support,
+ sectionPath: l10n.support,
+ icon: HugeIcons.strokeRoundedHelpCircle,
+ routeBuilder: (_) => const HelpSupportPage(),
+ keywords: ["help", "faq", "contact", "feedback", "bug"],
+ ),
+ );
+
+ // About
+ items.add(
+ SettingsSearchItem(
+ title: l10n.about,
+ sectionPath: l10n.about,
+ icon: HugeIcons.strokeRoundedInformationCircle,
+ routeBuilder: (_) => const AboutUsPage(),
+ keywords: ["version", "privacy", "terms", "license"],
+ ),
+ );
+
+ return items;
+ }
+
+ /// Get suggestions shown when search is empty
+ static List<SettingsSearchSuggestion> getSuggestions(
+ BuildContext context,
+ void Function(Widget Function(BuildContext) routeBuilder) onNavigate,
+ ) {
+ final l10n = AppLocalizations.of(context);
+ final hasLoggedIn = Configuration.instance.isLoggedIn();
+
+ return [
+ // App Icon suggestion
+ SettingsSearchSuggestion(
+ title: l10n.appIcon,
+ onTap: () => onNavigate((_) => const AppearanceSettingsPage()),
+ ),
+ // App lock suggestion
+ SettingsSearchSuggestion(
+ title: l10n.appLock,
+ onTap: () => onNavigate((_) => const SecuritySettingsPage()),
+ ),
+ // Remove duplicates suggestion
+ if (hasLoggedIn)
+ SettingsSearchSuggestion(
+ title: l10n.removeDuplicates,
+ onTap: () => onNavigate((_) => const FreeUpSpaceOptionsScreen()),
+ ),
+ // Help suggestion
+ SettingsSearchSuggestion(
+ title: l10n.help,
+ onTap: () => onNavigate((_) => const HelpSupportPage()),
+ ),
+ ];
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/settings_page.dart b/mobile/apps/photos/lib/ui/settings_page.dart
index 4167ecbae6..5a22e6c966 100644
--- a/mobile/apps/photos/lib/ui/settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings_page.dart
@@ -32,6 +32,7 @@ import "package:photos/ui/settings/inherited_settings_state.dart";
import "package:photos/ui/settings/memories_settings_screen.dart";
import "package:photos/ui/settings/ml/machine_learning_settings_page.dart";
import "package:photos/ui/settings/notification_settings_screen.dart";
+import "package:photos/ui/settings/search/settings_search_page.dart";
import "package:photos/ui/settings/security/security_settings_page.dart";
import "package:photos/ui/settings/storage_card_widget.dart";
import "package:photos/ui/settings/streaming/video_streaming_settings_page.dart";
@@ -151,24 +152,46 @@ class _SettingsBody extends StatelessWidget {
),
),
),
- if (localSettings.enableDatabaseLogging)
- GestureDetector(
- onTap: () {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) => const LogViewerPage(),
+ Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ GestureDetector(
+ onTap: () {
+ Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) => const SettingsSearchPage(),
+ ),
+ );
+ },
+ child: Container(
+ padding: const EdgeInsets.all(8),
+ child: Icon(
+ Icons.search_rounded,
+ size: 20,
+ color: colorScheme.textMuted,
),
- );
- },
- child: Container(
- padding: const EdgeInsets.all(8),
- child: Icon(
- Icons.bug_report,
- size: 20,
- color: colorScheme.textMuted,
),
),
- ),
+ if (localSettings.enableDatabaseLogging)
+ GestureDetector(
+ onTap: () {
+ Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) => const LogViewerPage(),
+ ),
+ );
+ },
+ child: Container(
+ padding: const EdgeInsets.all(8),
+ child: Icon(
+ Icons.bug_report,
+ size: 20,
+ color: colorScheme.textMuted,
+ ),
+ ),
+ ),
+ ],
+ ),
],
);
}