Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add user setting to enable or disable swipe-to-select

ashilkn0c2f631f6b96
diff --git a/mobile/apps/photos/lib/events/swipe_to_select_enabled_event.dart b/mobile/apps/photos/lib/events/swipe_to_select_enabled_event.dart
new file mode 100644
index 0000000000..f30f296e27
--- /dev/null
+++ b/mobile/apps/photos/lib/events/swipe_to_select_enabled_event.dart
@@ -0,0 +1,7 @@
+import "package:photos/events/event.dart";
+
+class SwipeToSelectEnabledEvent extends Event {
+ final bool isEnabled;
+
+ SwipeToSelectEnabledEvent(this.isEnabled);
+}
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arb
index 660278a6fa..dbbc7ab8c2 100644
--- a/mobile/apps/photos/lib/l10n/intl_en.arb
+++ b/mobile/apps/photos/lib/l10n/intl_en.arb
@@ -1612,6 +1612,7 @@
"legacyInvite": "{email} has invited you to be a trusted contact",
"authToManageLegacy": "Please authenticate to manage your trusted contacts",
"hideSharedItemsFromHomeGallery": "Hide shared items from home gallery",
+ "swipeToSelect": "Swipe to select",
"gallery": "Gallery",
"joinAlbum": "Join album",
"joinAlbumSubtext": "to view and add your photos",
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
index 29fe965964..eefc187807 100644
--- a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
+++ b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
@@ -364,7 +364,7 @@ class GalleryGroups {
// Only add dummy files if swipe-to-select feature is enabled
// Dummy files are used for gesture tracking in swipe-to-select
- if (!limitSelectionToOne) {
+ if (localSettings.isSwipeToSelectEnabled && !limitSelectionToOne) {
// Add dummy files to fill the last row if needed
final incompleteRowCount = groupFiles.length % crossAxisCount;
if (incompleteRowCount != 0) {
@@ -390,7 +390,7 @@ class GalleryGroups {
endCreationTime: lastFile.creationTime!
);
- if (!limitSelectionToOne) {
+ if (localSettings.isSwipeToSelectEnabled && !limitSelectionToOne) {
_allFilesWithDummies.addAll(groupFiles);
}
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 4fda8cbb18..362aa69652 100644
--- a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart
+++ b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart
@@ -1,6 +1,7 @@
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/events/swipe_to_select_enabled_event.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/service_locator.dart";
import "package:photos/theme/ente_theme.dart";
@@ -160,6 +161,34 @@ class _GallerySettingsScreenState extends State<GallerySettingsScreen> {
},
),
),
+ const SizedBox(
+ height: 24,
+ ),
+ widget.fromGalleryLayoutSettingsCTA
+ ? const SizedBox.shrink()
+ : MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title:
+ AppLocalizations.of(context).swipeToSelect,
+ ),
+ menuItemColor: colorScheme.fillFaint,
+ singleBorderRadius: 8,
+ alignCaptionedTextToLeft: true,
+ trailingWidget: ToggleSwitchWidget(
+ value: () =>
+ localSettings.isSwipeToSelectEnabled,
+ onChanged: () async {
+ final prevSetting =
+ localSettings.isSwipeToSelectEnabled;
+ await localSettings
+ .setSwipeToSelectEnabled(!prevSetting);
+
+ Bus.instance.fire(
+ SwipeToSelectEnabledEvent(!prevSetting),
+ );
+ },
+ ),
+ ),
],
),
);
diff --git a/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart b/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
index bfc4af340b..8e1022aa15 100644
--- a/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
@@ -96,26 +96,23 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
),
);
- _controller!
- .initialize()
- .then((_) {
- // Apply metadata rotation to the video player
- if (_quarterTurnsForRotationCorrection != null &&
- _quarterTurnsForRotationCorrection! != 0) {
- final rotationDegrees = _quarterTurnsForRotationCorrection! * 90;
- _controller!.video.value = _controller!.video.value.copyWith(
- rotationCorrection: rotationDegrees,
- );
- }
- setState(() {});
- })
- .catchError(
- (error) {
- // handle minimum duration bigger than video duration error
- Navigator.pop(context);
- },
- test: (e) => e is VideoMinDurationError,
+ _controller!.initialize().then((_) {
+ // Apply metadata rotation to the video player
+ if (_quarterTurnsForRotationCorrection != null &&
+ _quarterTurnsForRotationCorrection! != 0) {
+ final rotationDegrees = _quarterTurnsForRotationCorrection! * 90;
+ _controller!.video.value = _controller!.video.value.copyWith(
+ rotationCorrection: rotationDegrees,
);
+ }
+ setState(() {});
+ }).catchError(
+ (error) {
+ // handle minimum duration bigger than video duration error
+ Navigator.pop(context);
+ },
+ test: (e) => e is VideoMinDurationError,
+ );
});
}
@@ -142,8 +139,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
child: ValueListenableBuilder<bool>(
valueListenable: _isExporting,
builder: (context, isExporting, _) {
- final isReady =
- _controller != null &&
+ final isReady = _controller != null &&
_controller!.initialized &&
_quarterTurnsForRotationCorrection != null;
@@ -210,7 +206,8 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
children: [
Text(
"Native (i)",
- style: getEnteTextTheme(context).mini
+ style: getEnteTextTheme(context)
+ .mini
.copyWith(color: colorScheme.textMuted),
),
const SizedBox(width: 4),
@@ -430,7 +427,10 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
}
if (lastError != null) {
- Error.throwWithStackTrace(lastError, lastStackTrace ?? StackTrace.current);
+ Error.throwWithStackTrace(
+ lastError,
+ lastStackTrace ?? StackTrace.current,
+ );
}
throw Exception("Unknown native export failure");
}
@@ -496,7 +496,10 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
}
if (lastError != null) {
- Error.throwWithStackTrace(lastError, lastStackTrace ?? StackTrace.current);
+ Error.throwWithStackTrace(
+ lastError,
+ lastStackTrace ?? StackTrace.current,
+ );
}
throw Exception("Unknown FFmpeg export failure");
}
@@ -542,8 +545,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
return;
}
- final fileName =
- path.basenameWithoutExtension(widget.file.title!) +
+ final fileName = path.basenameWithoutExtension(widget.file.title!) +
"_edited_" +
DateTime.now().microsecondsSinceEpoch.toString() +
".mp4";
@@ -695,22 +697,22 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
class _VideoEditorSubPageRoute extends PageRouteBuilder<void> {
_VideoEditorSubPageRoute(this.child)
- : super(
- fullscreenDialog: true,
- transitionDuration: const Duration(milliseconds: 220),
- reverseTransitionDuration: const Duration(milliseconds: 180),
- pageBuilder: (_, __, ___) => child,
- transitionsBuilder: (_, animation, __, child) {
- return FadeTransition(
- opacity: CurvedAnimation(
- parent: animation,
- curve: Curves.easeOutCubic,
- reverseCurve: Curves.easeInCubic,
- ),
- child: child,
- );
- },
- );
+ : super(
+ fullscreenDialog: true,
+ transitionDuration: const Duration(milliseconds: 220),
+ reverseTransitionDuration: const Duration(milliseconds: 180),
+ pageBuilder: (_, __, ___) => child,
+ transitionsBuilder: (_, animation, __, child) {
+ return FadeTransition(
+ opacity: CurvedAnimation(
+ parent: animation,
+ curve: Curves.easeOutCubic,
+ reverseCurve: Curves.easeInCubic,
+ ),
+ child: child,
+ );
+ },
+ );
final Widget child;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/dummy_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/dummy_file_widget.dart
index 2a820cb41a..e409238d25 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/dummy_file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/dummy_file_widget.dart
@@ -1,6 +1,7 @@
import "package:flutter/material.dart";
import "package:photos/models/file/dummy_file.dart";
import "package:photos/models/selected_files.dart";
+import "package:photos/service_locator.dart";
import "package:photos/ui/viewer/gallery/component/swipe_selectable_file_widget.dart";
/// A widget that displays a dummy placeholder in the gallery grid.
@@ -19,7 +20,8 @@ class DummyFileWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
- final shouldEnableSwipeSelection = !limitSelectionToOne;
+ final shouldEnableSwipeSelection =
+ localSettings.isSwipeToSelectEnabled && !limitSelectionToOne;
const Widget dummyContent = SizedBox.expand();
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
index d62d3cb7e7..a7d5dc453e 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
@@ -6,6 +6,7 @@ import "package:photos/core/constants.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/gallery_type.dart";
import "package:photos/models/selected_files.dart";
+import "package:photos/service_locator.dart";
import "package:photos/services/app_lifecycle_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/touch_cross_detector.dart";
@@ -62,7 +63,8 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
@override
Widget build(BuildContext context) {
// Check if swipe selection should be enabled
- final shouldEnableSwipeSelection = !widget.limitSelectionToOne;
+ final shouldEnableSwipeSelection =
+ localSettings.isSwipeToSelectEnabled && !widget.limitSelectionToOne;
final Widget fileContent = _buildFileContent(context);
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index 03e2761dc9..8a79b4540d 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -304,7 +304,8 @@ class GalleryState extends State<Gallery> {
widget.selectedFiles?.addListener(_selectedFilesListener);
- if (widget.galleryType == GalleryType.homepage) {
+ if (localSettings.isSwipeToSelectEnabled &&
+ widget.galleryType == GalleryType.homepage) {
_swipeActiveNotifier.addListener(() {
Bus.instance.fire(
HomepageSwipeToSelectInProgressEvent(
@@ -486,7 +487,9 @@ class GalleryState extends State<Gallery> {
}
void _updateSwipeHelper() {
- if (widget.selectedFiles != null && _allFilesWithDummies.isNotEmpty) {
+ if (localSettings.isSwipeToSelectEnabled &&
+ widget.selectedFiles != null &&
+ _allFilesWithDummies.isNotEmpty) {
// Dispose existing helper if present
_swipeHelper?.dispose();
// Use allFilesWithDummies to match the rendered grid structure.
@@ -601,7 +604,8 @@ class GalleryState extends State<Gallery> {
}
final widthAvailable = MediaQuery.sizeOf(context).width;
- final shouldEnableSwipeSelection = widget.limitSelectionToOne == false;
+ final shouldEnableSwipeSelection = localSettings.isSwipeToSelectEnabled &&
+ widget.limitSelectionToOne == false;
if (groupHeaderExtent == null) {
final photoGridSize = localSettings.getPhotoGridSize();
diff --git a/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart b/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart
index 129db23e62..13036784a6 100644
--- a/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart
+++ b/mobile/apps/photos/lib/ui/wrapped/wrapped_viewer_page.dart
@@ -768,8 +768,7 @@ class _WrappedViewerPageState extends State<WrappedViewerPage>
key: _cardBoundaryKey,
child: _MediaPreviewController(
onPreviewStart: _showMediaPreview,
- onPreviewTapDown:
- _handlePreviewTapDown,
+ onPreviewTapDown: _handlePreviewTapDown,
onPreviewTapCancel:
_handlePreviewTapCancel,
child: PageView.builder(
@@ -777,8 +776,10 @@ class _WrappedViewerPageState extends State<WrappedViewerPage>
controller: _pageController,
onPageChanged: _handlePageChanged,
itemCount: cardCount,
- itemBuilder:
- (BuildContext context, int index) {
+ itemBuilder: (
+ BuildContext context,
+ int index,
+ ) {
final WrappedCard card =
_cards[index];
return _StoryCard(
@@ -1381,8 +1382,8 @@ class _MediaPreviewController extends InheritedWidget {
final VoidCallback onPreviewTapCancel;
static _MediaPreviewController? maybeOf(BuildContext context) {
- return context.dependOnInheritedWidgetOfExactType<
- _MediaPreviewController>();
+ return context
+ .dependOnInheritedWidgetOfExactType<_MediaPreviewController>();
}
@override
@@ -1466,8 +1467,9 @@ class _MediaPreviewOverlay extends StatelessWidget {
builder: (BuildContext context, BoxConstraints constraints) {
final double boxWidth = constraints.maxWidth;
final double boxHeight = constraints.maxHeight;
- final double imageAspect =
- file.width > 0 && file.height > 0 ? file.width / file.height : 3 / 4;
+ final double imageAspect = file.width > 0 && file.height > 0
+ ? file.width / file.height
+ : 3 / 4;
double width = boxWidth;
double height = width / imageAspect;
if (height > boxHeight) {
diff --git a/mobile/apps/photos/lib/utils/local_settings.dart b/mobile/apps/photos/lib/utils/local_settings.dart
index 90f8307777..77401f9e7c 100644
--- a/mobile/apps/photos/lib/utils/local_settings.dart
+++ b/mobile/apps/photos/lib/utils/local_settings.dart
@@ -41,6 +41,7 @@ class LocalSettings {
"has_configured_links_in_app_permission";
static const _hideSharedItemsFromHomeGalleryTag =
"hide_shared_items_from_home_gallery";
+ static const _kSwipeToSelectEnabled = "ls.swipe_to_select_enabled";
static const kCollectionViewType = "collection_view_type";
static const kCollectionSortDirection = "collection_sort_direction";
static const kShowLocalIDOverThumbnails = "show_local_id_over_thumbnails";
@@ -244,6 +245,13 @@ class LocalSettings {
bool get hideSharedItemsFromHomeGallery =>
_prefs.getBool(_hideSharedItemsFromHomeGalleryTag) ?? false;
+ Future<void> setSwipeToSelectEnabled(bool value) async {
+ await _prefs.setBool(_kSwipeToSelectEnabled, value);
+ }
+
+ bool get isSwipeToSelectEnabled =>
+ _prefs.getBool(_kSwipeToSelectEnabled) ?? true;
+
bool get showLocalIDOverThumbnails =>
_prefs.getBool(kShowLocalIDOverThumbnails) ?? false;