Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Add hide-shared toggle to gallery layout sheet (#14305)

Ashilf3ee142b5c14
diff --git a/mobile/apps/photos/changes/gallery-sheet-hide-shared-items.md b/mobile/apps/photos/changes/gallery-sheet-hide-shared-items.md
new file mode 100644
index 0000000000..76b8a50507
--- /dev/null
+++ b/mobile/apps/photos/changes/gallery-sheet-hide-shared-items.md
@@ -0,0 +1 @@
+- Added the option to hide shared items from the home gallery to the gallery layout sheet.
diff --git a/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart b/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart
index fc295206b6..2a94a8f042 100644
--- a/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart
+++ b/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart
@@ -113,9 +113,10 @@ class _HomeGalleryWidgetState extends State<HomeGalleryWidget> {
.listen((event) {
localSettings.setHideSharedItemsFromHomeGallery(event.shouldHide);
_hideSharedItemsToggleDebouncer.run(() async {
- setState(() {
- _shouldHideSharedItems = event.shouldHide;
- });
+ _shouldHideSharedItems = event.shouldHide;
+ Bus.instance.fire(
+ ForceReloadHomeGalleryEvent("hideSharedItemsChanged"),
+ );
});
});
}
@@ -131,7 +132,6 @@ class _HomeGalleryWidgetState extends State<HomeGalleryWidget> {
Widget build(BuildContext context) {
final largeBackupSession = SyncService.instance.largeBackupSessionTracker;
final gallery = Gallery(
- key: ValueKey(_shouldHideSharedItems),
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) async {
final ownerID = Configuration.instance.getUserIDV2();
final hasSelectedAllForBackup =
diff --git a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart
index f5066809a2..91f9b0c14c 100644
--- a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart
+++ b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart
@@ -1,9 +1,8 @@
import "package:ente_components/ente_components.dart";
import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
-import "package:photos/core/event_bus.dart";
-import "package:photos/events/hide_shared_items_from_home_gallery_event.dart";
import "package:photos/service_locator.dart";
+import "package:photos/ui/settings/hide_shared_items_setting.dart";
import "package:photos/ui/viewer/gallery/gallery_layout_controls.dart";
class GallerySettingsScreen extends StatelessWidget {
@@ -21,22 +20,7 @@ class GallerySettingsScreen extends StatelessWidget {
const GalleryLayoutControls(showHeading: true),
if (!fromGalleryLayoutSettingsCTA && !isLocalGalleryMode) ...[
const SizedBox(height: 8),
- SettingsItem(
- title: context.strings.hideSharedItemsFromHomeGallery,
- showChevron: false,
- trailing: ToggleSwitchComponent.async(
- value: () => localSettings.hideSharedItemsFromHomeGallery,
- onChanged: () async {
- final nextValue = !localSettings.hideSharedItemsFromHomeGallery;
- await localSettings.setHideSharedItemsFromHomeGallery(
- nextValue,
- );
- Bus.instance.fire(
- HideSharedItemsFromHomeGalleryEvent(nextValue),
- );
- },
- ),
- ),
+ const HideSharedItemsSetting(),
],
],
);
diff --git a/mobile/apps/photos/lib/ui/settings/hide_shared_items_setting.dart b/mobile/apps/photos/lib/ui/settings/hide_shared_items_setting.dart
new file mode 100644
index 0000000000..01bb48fe55
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/settings/hide_shared_items_setting.dart
@@ -0,0 +1,26 @@
+import "package:ente_components/ente_components.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:flutter/material.dart";
+import "package:photos/core/event_bus.dart";
+import "package:photos/events/hide_shared_items_from_home_gallery_event.dart";
+import "package:photos/service_locator.dart";
+
+class HideSharedItemsSetting extends StatelessWidget {
+ const HideSharedItemsSetting({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return SettingsItem(
+ title: context.strings.hideSharedItemsFromHomeGallery,
+ showChevron: false,
+ trailing: ToggleSwitchComponent.async(
+ value: () => localSettings.hideSharedItemsFromHomeGallery,
+ onChanged: () async {
+ final nextValue = !localSettings.hideSharedItemsFromHomeGallery;
+ await localSettings.setHideSharedItemsFromHomeGallery(nextValue);
+ Bus.instance.fire(HideSharedItemsFromHomeGalleryEvent(nextValue));
+ },
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
index e23558681b..20209d9821 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
@@ -1,6 +1,8 @@
import "package:ente_components/ente_components.dart";
import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/ui/settings/hide_shared_items_setting.dart";
import "package:photos/ui/viewer/gallery/gallery_layout_controls.dart";
class GalleryLayoutSettings extends StatefulWidget {
@@ -35,9 +37,21 @@ class _GalleryLayoutSettingsState extends State<GalleryLayoutSettings> {
@override
Widget build(BuildContext context) {
- return BottomSheetComponent(
- title: context.strings.layout,
- content: const GalleryLayoutControls(keepHeight: true),
+ return SingleChildScrollView(
+ child: BottomSheetComponent(
+ title: context.strings.layout,
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ const GalleryLayoutControls(keepHeight: true),
+ if (!isLocalGalleryMode) ...[
+ const SizedBox(height: 8),
+ const HideSharedItemsSetting(),
+ ],
+ ],
+ ),
+ ),
);
}
}
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
index 59dab9d0b1..00f790bc7c 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
@@ -62,6 +62,48 @@ void main() {
await localSettings.setGalleryLayoutType(GalleryLayoutType.grid);
});
+ testWidgets("the gallery sheet toggle is reachable in landscape", (
+ tester,
+ ) async {
+ tester.view.physicalSize = const Size(640, 360);
+ tester.view.devicePixelRatio = 1;
+ tester.view.padding = const FakeViewPadding(bottom: 24);
+ tester.view.viewPadding = const FakeViewPadding(bottom: 24);
+ addTearDown(tester.view.reset);
+ await localSettings.setHideSharedItemsFromHomeGallery(false);
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData.copyWith(platform: TargetPlatform.iOS),
+ localizationsDelegates: StringsLocalizations.localizationsDelegates,
+ supportedLocales: StringsLocalizations.supportedLocales,
+ home: Scaffold(
+ body: Builder(
+ builder: (context) => TextButton(
+ onPressed: () => showBottomSheetComponent<void>(
+ context: context,
+ builder: (_) => const GalleryLayoutSettings(),
+ ),
+ child: const Text("Open"),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text("Open"));
+ await tester.pumpAndSettle();
+ final toggle = find.byType(ToggleSwitchComponent);
+ await tester.ensureVisible(toggle);
+ await tester.pumpAndSettle();
+ expect(tester.getRect(toggle).bottom, lessThanOrEqualTo(336));
+ await tester.tap(toggle);
+ await tester.pumpAndSettle();
+ expect(localSettings.hideSharedItemsFromHomeGallery, isTrue);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pumpAndSettle();
+ await localSettings.setHideSharedItemsFromHomeGallery(false);
+ });
+
testWidgets(
"zero-size startup recovers date headers without remounting or reloading",
(tester) async {
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/gallery_thumbnail_demand_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/gallery_thumbnail_demand_test.dart
index 60a1e42efc..abefd60e02 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/gallery_thumbnail_demand_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/gallery_thumbnail_demand_test.dart
@@ -3,6 +3,7 @@ import "dart:convert";
import "dart:io";
import "package:dio/dio.dart";
+import "package:ente_components/ente_components.dart";
import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
@@ -13,15 +14,20 @@ import "package:path_provider_platform_interface/path_provider_platform_interfac
import "package:photos/core/cache/thumbnail_in_memory_cache.dart";
import "package:photos/core/configuration.dart";
import "package:photos/core/network/network.dart";
+import "package:photos/db/files_db.dart";
import "package:photos/ente_theme_data.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/models/file_load_result.dart";
+import "package:photos/models/selected_files.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/favorites_service.dart";
import "package:photos/settings/local_settings.dart";
+import "package:photos/ui/home/home_gallery_widget.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
+import "package:photos/ui/viewer/gallery/component/group/type.dart";
import "package:photos/ui/viewer/gallery/gallery.dart";
+import "package:photos/ui/viewer/gallery/layout_settings.dart";
import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";
import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
import "package:shared_preferences/shared_preferences.dart";
@@ -32,6 +38,7 @@ void main() {
late PathProviderPlatform previousPathProvider;
late _HeldThumbnailDownloads downloads;
late Dio serviceDio;
+ var filesDBOpened = false;
const userAgentChannel = MethodChannel("ua_client_hints");
setUpAll(() async {
@@ -89,6 +96,7 @@ void main() {
});
tearDownAll(() async {
+ if (filesDBOpened) await (await FilesDB.instance.sqliteAsyncDB).close();
NetworkClient.instance.enteDio.close(force: true);
NetworkClient.instance.downloadDio.close(force: true);
NetworkClient.instance.getDio().close(force: true);
@@ -194,6 +202,77 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpAndSettle();
});
+
+ testWidgets("hiding shared items preserves the open home gallery preview", (
+ tester,
+ ) async {
+ await localSettings.setGalleryLayoutType(GalleryLayoutType.grid);
+ await localSettings.setHideSharedItemsFromHomeGallery(false);
+ await localSettings.setPhotoGridSize(4);
+ await localSettings.setGalleryGroupType(GroupType.day);
+ filesDBOpened = true;
+ await tester.runAsync(() async {
+ await FilesDB.instance.insertMultiple([
+ for (final ownerID in [1, 2])
+ EnteFile()
+ ..uploadedFileID = 9000 + ownerID
+ ..ownerID = ownerID
+ ..collectionID = 1
+ ..title = "photo-$ownerID.jpg"
+ ..fileType = FileType.image
+ ..creationTime = DateTime(2026, 10, 1).microsecondsSinceEpoch
+ ..modificationTime = DateTime(2026, 10, 1).microsecondsSinceEpoch,
+ ]);
+ // Open SQLite readers outside the widget test's fake clock.
+ await (await FilesDB.instance.sqliteAsyncDB).getAll("SELECT 1");
+ });
+ final selectedFiles = SelectedFiles();
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData.copyWith(platform: TargetPlatform.iOS),
+ localizationsDelegates: StringsLocalizations.localizationsDelegates,
+ supportedLocales: StringsLocalizations.supportedLocales,
+ home: Scaffold(body: HomeGalleryWidget(selectedFiles: selectedFiles)),
+ ),
+ );
+ Future<void> waitForFileCount(int count) async {
+ final deadline = Stopwatch()..start();
+ while (deadline.elapsed < const Duration(seconds: 5)) {
+ await tester.runAsync(
+ () => Future<void>.delayed(const Duration(milliseconds: 20)),
+ );
+ await tester.pump(const Duration(milliseconds: 200));
+ final state = tester.state<GalleryState>(find.byType(Gallery));
+ if (state.galleryGroups?.allFiles.length == count) return;
+ }
+ expect(
+ tester
+ .state<GalleryState>(find.byType(Gallery))
+ .galleryGroups
+ ?.allFiles
+ .length,
+ count,
+ );
+ }
+
+ await waitForFileCount(2);
+ await tester.tap(find.byIcon(Icons.more_vert_outlined).hitTestable().first);
+ await tester.pumpAndSettle();
+ await tester.tap(find.byType(ToggleSwitchComponent));
+ await waitForFileCount(1);
+ final gallery = tester.state<GalleryState>(find.byType(Gallery));
+ expect(gallery.galleryGroups!.allFiles.single.ownerID, 1);
+ await tester.tap(find.byKey(const ValueKey("more-photos-per-row")));
+ await tester.pumpAndSettle();
+ expect(gallery.galleryGroups!.crossAxisCount, 5);
+ await tester.tap(find.byType(ToggleSwitchComponent));
+ await waitForFileCount(2);
+ expect(find.byType(GalleryLayoutSettings), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pump(const Duration(seconds: 3));
+ selectedFiles.dispose();
+ });
}
Future<void> _waitForMountedThumbnails(