浏览代码

Add setting to enable Magic Search

vishnukvmd 1 年之前
父节点
当前提交
30139f1b97

+ 5 - 0
lib/generated/intl/messages_en.dart

@@ -807,6 +807,11 @@ class MessageLookup extends MessageLookupByLibrary {
             MessageLookupByLibrary.simpleMessage(
                 "Long-press on an item to view in full-screen"),
         "lostDevice": MessageLookupByLibrary.simpleMessage("Lost device?"),
+        "machineLearning":
+            MessageLookupByLibrary.simpleMessage("Machine learning"),
+        "magicSearch": MessageLookupByLibrary.simpleMessage("Magic search"),
+        "magicSearchDescription": MessageLookupByLibrary.simpleMessage(
+            "Please note that this will result in a higher bandwidth and battery usage until all items are indexed."),
         "manage": MessageLookupByLibrary.simpleMessage("Manage"),
         "manageDeviceStorage":
             MessageLookupByLibrary.simpleMessage("Manage device storage"),

+ 30 - 0
lib/generated/l10n.dart

@@ -2857,6 +2857,36 @@ class S {
     );
   }
 
+  /// `Machine learning`
+  String get machineLearning {
+    return Intl.message(
+      'Machine learning',
+      name: 'machineLearning',
+      desc: '',
+      args: [],
+    );
+  }
+
+  /// `Magic search`
+  String get magicSearch {
+    return Intl.message(
+      'Magic search',
+      name: 'magicSearch',
+      desc: '',
+      args: [],
+    );
+  }
+
+  /// `Please note that this will result in a higher bandwidth and battery usage until all items are indexed.`
+  String get magicSearchDescription {
+    return Intl.message(
+      'Please note that this will result in a higher bandwidth and battery usage until all items are indexed.',
+      name: 'magicSearchDescription',
+      desc: '',
+      args: [],
+    );
+  }
+
   /// `Select folders for backup`
   String get selectFoldersForBackup {
     return Intl.message(

+ 3 - 0
lib/l10n/intl_en.arb

@@ -406,6 +406,9 @@
   },
   "photoGridSize": "Photo grid size",
   "manageDeviceStorage": "Manage device storage",
+  "machineLearning": "Machine learning",
+  "magicSearch": "Magic search",
+  "magicSearchDescription": "Please note that this will result in a higher bandwidth and battery usage until all items are indexed.",
   "selectFoldersForBackup": "Select folders for backup",
   "selectedFoldersWillBeEncryptedAndBackedUp": "Selected folders will be encrypted and backed up",
   "unselectAll": "Unselect all",

+ 22 - 0
lib/ui/settings/advanced_settings_screen.dart

@@ -10,6 +10,7 @@ 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/machine_learning_settings_page.dart";
 import 'package:photos/ui/tools/debug/app_storage_viewer.dart';
 import 'package:photos/ui/viewer/gallery/photo_grid_size_picker_page.dart';
 import 'package:photos/utils/local_settings.dart';
@@ -65,6 +66,27 @@ class _AdvancedSettingsScreenState extends State<AdvancedSettingsScreen> {
                       children: [
                         Column(
                           children: [
+                            MenuItemWidget(
+                              captionedTextWidget: CaptionedTextWidget(
+                                title: S.of(context).machineLearning,
+                              ),
+                              menuItemColor: colorScheme.fillFaint,
+                              trailingWidget: Icon(
+                                Icons.chevron_right_outlined,
+                                color: colorScheme.strokeBase,
+                              ),
+                              singleBorderRadius: 8,
+                              alignCaptionedTextToLeft: true,
+                              onTap: () async {
+                                routeToPage(
+                                  context,
+                                  const MachineLearningSettingsPage(),
+                                );
+                              },
+                            ),
+                            const SizedBox(
+                              height: 24,
+                            ),
                             GestureDetector(
                               onTap: () {
                                 routeToPage(

+ 92 - 0
lib/ui/settings/machine_learning_settings_page.dart

@@ -0,0 +1,92 @@
+import "package:flutter/material.dart";
+import "package:photos/generated/l10n.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/menu_item_widget/menu_item_widget.dart";
+import "package:photos/ui/components/menu_section_description_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/utils/local_settings.dart";
+
+class MachineLearningSettingsPage extends StatelessWidget {
+  const MachineLearningSettingsPage({super.key});
+
+  @override
+  Widget build(BuildContext context) {
+    final colorScheme = getEnteColorScheme(context);
+    return Scaffold(
+      body: CustomScrollView(
+        primary: false,
+        slivers: <Widget>[
+          TitleBarWidget(
+            flexibleSpaceTitle: TitleBarTitleWidget(
+              title: S.of(context).machineLearning,
+            ),
+            actionIcons: [
+              IconButtonWidget(
+                icon: Icons.close_outlined,
+                iconButtonType: IconButtonType.secondary,
+                onTap: () {
+                  Navigator.pop(context);
+                  Navigator.pop(context);
+                  Navigator.pop(context);
+                },
+              ),
+            ],
+          ),
+          SliverList(
+            delegate: SliverChildBuilderDelegate(
+              (delegateBuildContext, index) {
+                return Padding(
+                  padding: const EdgeInsets.symmetric(horizontal: 16),
+                  child: Padding(
+                    padding: const EdgeInsets.symmetric(vertical: 20),
+                    child: Column(
+                      mainAxisSize: MainAxisSize.min,
+                      children: [
+                        Column(
+                          children: [
+                            Column(
+                              children: [
+                                MenuItemWidget(
+                                  captionedTextWidget: CaptionedTextWidget(
+                                    title: S.of(context).magicSearch,
+                                  ),
+                                  menuItemColor: colorScheme.fillFaint,
+                                  trailingWidget: ToggleSwitchWidget(
+                                    value: () => LocalSettings.instance
+                                        .hasEnabledMagicSearch(),
+                                    onChanged: () {
+                                      return LocalSettings.instance
+                                          .setShouldEnableMagicSearch(
+                                        !LocalSettings.instance
+                                            .hasEnabledMagicSearch(),
+                                      );
+                                    },
+                                  ),
+                                  singleBorderRadius: 8,
+                                  alignCaptionedTextToLeft: true,
+                                  isGestureDetectorDisabled: true,
+                                ),
+                                MenuSectionDescriptionWidget(
+                                  content: S.of(context).magicSearchDescription,
+                                ),
+                              ],
+                            ),
+                          ],
+                        ),
+                      ],
+                    ),
+                  ),
+                );
+              },
+              childCount: 1,
+            ),
+          ),
+        ],
+      ),
+    );
+  }
+}

+ 12 - 0
lib/utils/local_settings.dart

@@ -13,6 +13,7 @@ class LocalSettings {
   static final LocalSettings instance = LocalSettings._privateConstructor();
   static const kCollectionSortPref = "collection_sort_pref";
   static const kPhotoGridSize = "photo_grid_size";
+  static const kEnableMagicSearch = "enable_magic_search";
 
   late SharedPreferences _prefs;
 
@@ -39,4 +40,15 @@ class LocalSettings {
   Future<void> setPhotoGridSize(int value) async {
     await _prefs.setInt(kPhotoGridSize, value);
   }
+
+  bool hasEnabledMagicSearch() {
+    if (_prefs.containsKey(kEnableMagicSearch)) {
+      return _prefs.getBool(kEnableMagicSearch)!;
+    }
+    return false;
+  }
+
+  Future<void> setShouldEnableMagicSearch(bool value) async {
+    await _prefs.setBool(kEnableMagicSearch, value);
+  }
 }