π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add album slideshow
AmanRajSinghMourya70cbb55ffaec
diff --git a/mobile/apps/photos/changes/album-slideshow.md b/mobile/apps/photos/changes/album-slideshow.mdnew file mode 100644index 0000000000..4b3eb35580--- /dev/null+++ b/mobile/apps/photos/changes/album-slideshow.md@@ -0,0 +1 @@+- (i) Adds album slideshow playback.diff --git a/mobile/apps/photos/lib/services/wake_lock_service.dart b/mobile/apps/photos/lib/services/wake_lock_service.dartindex 8c29609f1d..66737d7e75 100644--- a/mobile/apps/photos/lib/services/wake_lock_service.dart+++ b/mobile/apps/photos/lib/services/wake_lock_service.dart@@ -8,6 +8,7 @@ enum WakeLockFor {handlingMediaKitEdgeCase,rewindViewer,largeBackupStandbyScreen,+ albumSlideshow,}// Temporary callers must not override the across-session setting.diff --git a/mobile/apps/photos/lib/ui/viewer/album_slideshow/album_slideshow_page.dart b/mobile/apps/photos/lib/ui/viewer/album_slideshow/album_slideshow_page.dartnew file mode 100644index 0000000000..ecfb51da1d--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/album_slideshow/album_slideshow_page.dart@@ -0,0 +1,456 @@+import "dart:async";++import "package:ente_components/components/buttons/icon_button_component.dart";+import "package:ente_components/theme/icon_sizes.dart";+import "package:ente_components/theme/spacing.dart";+import "package:ente_components/theme/text_styles.dart";+import "package:ente_components/theme/theme.dart";+import "package:ente_strings/ente_strings.dart";+import "package:flutter/material.dart";+import "package:flutter/services.dart";+import "package:hugeicons/hugeicons.dart";+import "package:photos/models/file/file.dart";+import "package:photos/service_locator.dart";+import "package:photos/services/wake_lock_service.dart";+import "package:photos/ui/viewer/file/file_widget.dart";++class AlbumSlideshowPage extends StatefulWidget {+ AlbumSlideshowPage({+ required this.files,+ required this.albumName,+ super.key,+ }) {+ if (files.isEmpty) {+ throw ArgumentError("files must not be empty");+ }+ }++ final List<EnteFile> files;+ final String albumName;++ @override+ State<AlbumSlideshowPage> createState() => _AlbumSlideshowPageState();+}++class _SlideSlot {+ _SlideSlot(this._index);++ int? _index;+ bool isReady = false;++ int? get index => _index;++ set index(int? value) {+ if (_index == value) return;++ _index = value;+ isReady = false;+ }+}++class _AlbumSlideshowPageState extends State<AlbumSlideshowPage>+ with WidgetsBindingObserver, SingleTickerProviderStateMixin {+ static const Duration _slideDuration = Duration(seconds: 5);+ static const Duration _mediaReadyTimeout = Duration(seconds: 10);+ static const Duration _crossFadeDuration = Duration(milliseconds: 600);+ static const Duration _controlsHideDelay = Duration(seconds: 3);+ static final ThemeData _controlsTheme = ComponentTheme.darkTheme();++ Timer? _advanceTimer;+ Timer? _controlsHideTimer;+ late final AnimationController _crossFadeController;+ late final CurvedAnimation _crossFadeAnimation;+ late final List<_SlideSlot> _slots;+ int _currentSlotIndex = 0;+ bool _controlsVisible = true;+ bool _isPlaying = true;+ bool _accessibleNavigation = false;+ bool _wakeLockRequested = false;+ bool _isForeground = false;++ List<EnteFile> get _files => widget.files;+ int get _nextSlotIndex => 1 - _currentSlotIndex;+ int? get _nextIndex => _slots[_nextSlotIndex].index;++ int? _indexAfter(int index) {+ if (_files.length < 2) return null;+ return (index + 1) % _files.length;+ }++ bool get _isTransitioning =>+ _crossFadeController.status != AnimationStatus.dismissed;+ bool get _isCurrentSlideReady => _slots[_currentSlotIndex].isReady;++ @override+ void initState() {+ super.initState();+ WidgetsBinding.instance.addObserver(this);+ _slots = [_SlideSlot(0), _SlideSlot(_indexAfter(0))];+ _crossFadeController = AnimationController(+ vsync: this,+ duration: _crossFadeDuration,+ )..addStatusListener(_onCrossFadeStatusChanged);+ _crossFadeAnimation = CurvedAnimation(+ parent: _crossFadeController,+ curve: Curves.easeInOut,+ );+ _isForeground =+ (WidgetsBinding.instance.lifecycleState ?? AppLifecycleState.resumed) ==+ AppLifecycleState.resumed;+ _setAlbumSlideshowWakeLock(_isForeground && _isPlaying);+ WidgetsBinding.instance.addPostFrameCallback((_) {+ if (!mounted) return;+ _syncSystemUi();+ _scheduleControlsHide();+ _scheduleAdvance();+ });+ }++ @override+ void didChangeDependencies() {+ super.didChangeDependencies();+ final accessibleNavigation = MediaQuery.accessibleNavigationOf(context);+ if (_accessibleNavigation == accessibleNavigation) return;++ _accessibleNavigation = accessibleNavigation;+ if (_accessibleNavigation) {+ _controlsHideTimer?.cancel();+ } else {+ _scheduleControlsHide();+ }+ }++ @override+ void didChangeAppLifecycleState(AppLifecycleState state) {+ _isForeground = state == AppLifecycleState.resumed;+ if (_isForeground) {+ _setAlbumSlideshowWakeLock(_isPlaying);+ _syncSystemUi();+ if (_isTransitioning && _isPlaying) {+ _crossFadeController.forward();+ } else {+ _scheduleAdvance();+ }+ _scheduleControlsHide();+ } else {+ _setAlbumSlideshowWakeLock(false);+ _advanceTimer?.cancel();+ _controlsHideTimer?.cancel();+ _crossFadeController.stop();+ }+ }++ @override+ void dispose() {+ WidgetsBinding.instance.removeObserver(this);+ _advanceTimer?.cancel();+ _controlsHideTimer?.cancel();+ _crossFadeAnimation.dispose();+ _crossFadeController.dispose();+ _setAlbumSlideshowWakeLock(false);+ _setSystemUiVisible(true);+ super.dispose();+ }++ void _syncSystemUi() => _setSystemUiVisible(_controlsVisible);++ void _setAlbumSlideshowWakeLock(bool enable) {+ if (_wakeLockRequested == enable) return;++ _wakeLockRequested = enable;+ wakeLockService.updateWakeLock(+ enable: enable,+ wakeLockFor: WakeLockFor.albumSlideshow,+ );+ }++ void _setSystemUiVisible(bool visible) {+ unawaited(+ SystemChrome.setEnabledSystemUIMode(+ visible ? SystemUiMode.edgeToEdge : SystemUiMode.manual,+ overlays: visible ? SystemUiOverlay.values : const [],+ ),+ );+ }++ void _scheduleAdvance() {+ _advanceTimer?.cancel();+ if (!_isPlaying ||+ !_isForeground ||+ _isTransitioning ||+ _nextIndex == null) {+ return;+ }+ _advanceTimer = Timer(+ _isCurrentSlideReady ? _slideDuration : _mediaReadyTimeout,+ _advance,+ );+ }++ void _onSlideReady(int slotIndex, int index) {+ if (!mounted) return;++ final slot = _slots[slotIndex];+ if (slot.index != index || slot.isReady) return;++ slot.isReady = true;+ if (slotIndex == _currentSlotIndex) {+ _scheduleAdvance();+ }+ }++ void _advance() {+ if (!mounted ||+ _nextIndex == null ||+ _isTransitioning ||+ !_isPlaying ||+ !_isForeground) {+ return;+ }++ _advanceTimer?.cancel();+ _crossFadeController.forward(from: 0);+ }++ void _onCrossFadeStatusChanged(AnimationStatus status) {+ if (status != AnimationStatus.completed || !mounted) return;+ final nextSlotIndex = _nextSlotIndex;+ final nextIndex = _slots[nextSlotIndex].index;+ if (nextIndex == null) return;++ setState(() {+ _currentSlotIndex = nextSlotIndex;+ _slots[_nextSlotIndex].index = _indexAfter(nextIndex);+ _crossFadeController.value = 0;+ });+ _scheduleAdvance();+ }++ void _togglePlayback() {+ setState(() {+ _isPlaying = !_isPlaying;+ _controlsVisible = true;+ });+ _syncSystemUi();+ _setAlbumSlideshowWakeLock(_isForeground && _isPlaying);+ if (_isPlaying) {+ if (_isTransitioning) {+ _crossFadeController.forward();+ } else {+ _scheduleAdvance();+ }+ _scheduleControlsHide();+ } else {+ _advanceTimer?.cancel();+ _controlsHideTimer?.cancel();+ _crossFadeController.stop();+ }+ }++ void _toggleControls() {+ setState(() => _controlsVisible = !_controlsVisible);+ _syncSystemUi();+ if (_controlsVisible) {+ _scheduleControlsHide();+ } else {+ _controlsHideTimer?.cancel();+ }+ }++ void _scheduleControlsHide() {+ _controlsHideTimer?.cancel();+ if (!_isPlaying ||+ !_isForeground ||+ !_controlsVisible ||+ _accessibleNavigation) {+ return;+ }+ _controlsHideTimer = Timer(_controlsHideDelay, () {+ if (!mounted || _accessibleNavigation) return;+ setState(() => _controlsVisible = false);+ _syncSystemUi();+ });+ }++ Widget _buildSlides() {+ return Stack(+ fit: StackFit.expand,+ children: [+ for (var slotIndex = 0; slotIndex < _slots.length; slotIndex++)+ if (_slots[slotIndex].index != null)+ _buildSlideSlot(+ slotIndex: slotIndex,+ index: _slots[slotIndex].index!,+ opacity: slotIndex == _currentSlotIndex+ ? ReverseAnimation(_crossFadeAnimation)+ : _crossFadeAnimation,+ ),+ ],+ );+ }++ Widget _buildSlideSlot({+ required int slotIndex,+ required int index,+ required Animation<double> opacity,+ }) {+ return IgnorePointer(+ child: FadeTransition(+ key: ValueKey("album-slideshow-slot-$slotIndex-opacity"),+ opacity: opacity,+ child: SizedBox.expand(+ key: ValueKey("album-slideshow-slot-$slotIndex-$index"),+ child: FileWidget(+ _files[index],+ tagPrefix: "album_slideshow_${slotIndex}_",+ backgroundDecoration: const BoxDecoration(),+ isFromMemories: true,+ onFinalFileLoad: ({required int memoryDuration}) =>+ _onSlideReady(slotIndex, index),+ ),+ ),+ ),+ );+ }++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ final mediaBackground = colors.specialScrim.withValues(alpha: 1);+ return AnnotatedRegion<SystemUiOverlayStyle>(+ value: SystemUiOverlayStyle.light,+ child: Scaffold(+ backgroundColor: mediaBackground,+ body: Stack(+ fit: StackFit.expand,+ children: [+ _buildSlides(),+ GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: _toggleControls,+ ),+ _buildControls(context),+ ],+ ),+ ),+ );+ }++ Widget _buildControls(BuildContext context) {+ final colors = context.componentColors;+ return Theme(+ data: _controlsTheme,+ child: IgnorePointer(+ ignoring: !_controlsVisible,+ child: AnimatedOpacity(+ opacity: _controlsVisible ? 1 : 0,+ duration: const Duration(milliseconds: 200),+ curve: Curves.easeOut,+ child: Stack(+ fit: StackFit.expand,+ children: [+ Align(+ alignment: Alignment.topCenter,+ child: DecoratedBox(+ decoration: BoxDecoration(+ gradient: LinearGradient(+ begin: Alignment.topCenter,+ end: Alignment.bottomCenter,+ colors: [+ colors.specialScrim.withValues(alpha: 0.72),+ colors.specialScrim.withValues(alpha: 0.60),+ colors.specialScrim.withValues(alpha: 0),+ ],+ stops: const [0, 0.6, 1],+ ),+ ),+ child: SafeArea(+ bottom: false,+ child: Padding(+ padding: const EdgeInsets.fromLTRB(+ Spacing.lg,+ Spacing.xs,+ Spacing.lg,+ Spacing.md,+ ),+ child: SizedBox(+ height: 48,+ child: Row(+ children: [+ SizedBox(+ width: 48,+ child: Align(+ alignment: Alignment.centerLeft,+ child: IconButtonComponent(+ tooltip: context.strings.close,+ variant: IconButtonComponentVariant.unfilled,+ shouldSurfaceExecutionStates: false,+ size: 48,+ onTap: () =>+ Navigator.maybePop(context).ignore(),+ icon: const HugeIcon(+ icon: HugeIcons.strokeRoundedCancel01,+ size: IconSizes.small,+ ),+ ),+ ),+ ),+ const SizedBox(width: Spacing.sm),+ Expanded(+ child: Text(+ widget.albumName,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: TextStyles.display3.copyWith(+ color: colors.specialWhite,+ ),+ ),+ ),+ const SizedBox(width: 48),+ ],+ ),+ ),+ ),+ ),+ ),+ ),+ if (_files.length > 1)+ Center(child: _buildPlaybackButton(context)),+ ],+ ),+ ),+ ),+ );+ }++ Widget _buildPlaybackButton(BuildContext context) {+ final colors = context.componentColors;+ final label = _isPlaying+ ? context.strings.facesTimelinePlaybackPause+ : context.strings.facesTimelinePlaybackPlay;+ return DecoratedBox(+ decoration: BoxDecoration(+ color: colors.specialScrim.withValues(alpha: 0.45),+ shape: BoxShape.circle,+ ),+ child: IconButtonComponent(+ tooltip: label,+ variant: IconButtonComponentVariant.unfilled,+ shouldSurfaceExecutionStates: false,+ size: 56,+ iconSize: IconSizes.medium,+ onTap: _togglePlayback,+ icon: AnimatedSwitcher(+ duration: const Duration(milliseconds: 160),+ child: HugeIcon(+ key: ValueKey(_isPlaying),+ icon: _isPlaying+ ? HugeIcons.strokeRoundedPause+ : HugeIcons.strokeRoundedPlay,+ size: IconSizes.medium,+ ),+ ),+ ),+ );+ }+}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dartindex 979f2c3f45..675f4f7035 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart@@ -19,6 +19,7 @@ import 'package:photos/events/subscription_purchased_event.dart';import 'package:photos/models/collection/collection.dart';import 'package:photos/models/device_collection.dart';import "package:photos/models/file/file.dart";+import "package:photos/models/file/file_type.dart";import 'package:photos/models/freeable_space_info.dart';import 'package:photos/models/gallery_type.dart';import "package:photos/models/metadata/common_keys.dart";@@ -27,6 +28,7 @@ import 'package:photos/module/download/gallery.dart';import 'package:photos/service_locator.dart';import 'package:photos/services/collections_service.dart';import "package:photos/services/files_service.dart";+import "package:photos/services/ignored_files_service.dart";import "package:photos/services/review_service.dart";import "package:photos/states/location_screen_state.dart";import "package:photos/theme/ente_theme.dart";@@ -43,6 +45,7 @@ import 'package:photos/ui/sharing/album_participants_page.dart';import "package:photos/ui/sharing/manage_links_widget.dart";import 'package:photos/ui/sharing/share_collection_page.dart';import 'package:photos/ui/tools/free_space_page.dart';+import "package:photos/ui/viewer/album_slideshow/album_slideshow_page.dart";import "package:photos/ui/viewer/file/detail_page.dart";import "package:photos/ui/viewer/gallery/component/album_description_header.dart";import "package:photos/ui/viewer/gallery/gallery_app_bar_actions.dart";@@ -164,6 +167,7 @@ enum AlbumPopupAction {ownedHide,sharedHide,castAlbum,+ albumSlideshow,autoAddPhotos,sort,leave,@@ -612,6 +616,8 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {await _leaveAlbum(context);} else if (value == AlbumPopupAction.castAlbum) {await showCastSheet(context, widget.collection!);+ } else if (value == AlbumPopupAction.albumSlideshow) {+ await _startAlbumSlideshow();} else if (value == AlbumPopupAction.autoAddPhotos) {await routeToPage(context,@@ -817,6 +823,15 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {iconColor,),),+ if (_isAlbumSlideshowAvailable)+ _menuOption(+ AlbumPopupAction.albumSlideshow,+ pendingTranslation("(i) Slideshow"),+ galleryAppBarMenuIcon(+ HugeIcons.strokeRoundedPresentation03,+ iconColor,+ ),+ ),if (canAutoAdd)_menuOption(AlbumPopupAction.autoAddPhotos,@@ -907,6 +922,9 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {_isDeviceFolderBackedUp &&widget.onDisableDeviceFolderBackup != null;+ bool get _isAlbumSlideshowAvailable =>+ flagService.internalUser && widget.collection != null;+EntePopupMenuOption<AlbumPopupAction> _menuOption(AlbumPopupAction value,String label,@@ -960,6 +978,62 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {await dialog.hide();}+ Future<void> _startAlbumSlideshow() async {+ final galleryFiles = await _loadAllCollectionFiles();+ if (!mounted) return;+ if (galleryFiles == null) {+ showToast(context, context.strings.somethingWentWrong);+ return;+ }++ final ignoredIDs = await IgnoredFilesService.instance.idToIgnoreReasonMap;+ if (!mounted) return;+ final imageFiles = galleryFiles+ .where(+ (file) =>+ (file.uploadedFileID != null ||+ !IgnoredFilesService.instance.shouldSkipUpload(+ ignoredIDs,+ file,+ )) &&+ (file.fileType == FileType.image ||+ file.fileType == FileType.livePhoto),+ )+ .toList(growable: false);+ if (imageFiles.isEmpty) {+ showToast(context, context.strings.noPhotosFoundHere);+ return;+ }++ await routeToPage(+ context,+ AlbumSlideshowPage(+ files: imageFiles,+ albumName: widget.collection!.displayName,+ ),+ forceCustomPageRoute: true,+ );+ }++ Future<List<EnteFile>?> _loadAllCollectionFiles() async {+ if (widget.files != null) {+ return widget.files!;+ }++ final collection = widget.collection;+ if (collection == null) {+ return null;+ }++ final filesResult = await FilesDB.instance.getFilesInCollection(+ collection.id,+ galleryLoadStartTime,+ galleryLoadEndTime,+ asc: collection.pubMagicMetadata.asc ?? false,+ );+ return filesResult.files;+ }+void editLocation() {showEditLocationSheet(context,@@ -1217,25 +1291,14 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {Future<void> _onGalleryGuestViewClick() async {if (await LocalAuthentication().isDeviceSupported()) {- late final List<EnteFile> collectionFiles;- if (widget.files != null) {- collectionFiles = widget.files!;- } else if (widget.collection != null) {- final filesResult = await FilesDB.instance.getFilesInCollection(- widget.collection!.id,- galleryLoadStartTime,- galleryLoadEndTime,- asc: widget.collection!.pubMagicMetadata.asc ?? false,- );- collectionFiles = filesResult.files;- } else {- if (!mounted) return;+ final collectionFiles = await _loadAllCollectionFiles();+ if (!mounted) return;+ if (collectionFiles == null) {showToast(context, context.strings.somethingWentWrong);return;}if (collectionFiles.isEmpty) {- if (!mounted) return;showToast(context, context.strings.nothingToSeeHere);return;}diff --git a/mobile/packages/ente_components/lib/components/buttons/icon_button_component.dart b/mobile/packages/ente_components/lib/components/buttons/icon_button_component.dartindex 7180f82602..92d5b9cf9a 100644--- a/mobile/packages/ente_components/lib/components/buttons/icon_button_component.dart+++ b/mobile/packages/ente_components/lib/components/buttons/icon_button_component.dart@@ -29,6 +29,8 @@ class IconButtonComponent extends StatefulWidget {this.shouldSurfaceExecutionStates = true,this.shouldShowSuccessConfirmation = false,this.tooltip,+ this.size = _defaultButtonSize,+ this.iconSize = _defaultIconSize,});final Widget icon;@@ -38,6 +40,8 @@ class IconButtonComponent extends StatefulWidget {final bool shouldSurfaceExecutionStates;final bool shouldShowSuccessConfirmation;final String? tooltip;+ final double size;+ final double iconSize;@overrideState<IconButtonComponent> createState() => _IconButtonComponentState();@@ -89,8 +93,8 @@ class _IconButtonComponentState extends State<IconButtonComponent>: BorderRadius.circular(Radii.md);Widget button = SizedBox(- width: _buttonSize,- height: _buttonSize,+ width: widget.size,+ height: widget.size,child: MouseRegion(cursor: enabled ? SystemMouseCursors.click : SystemMouseCursors.basic,onEnter: (_) => _setHovered(true),@@ -109,8 +113,8 @@ class _IconButtonComponentState extends State<IconButtonComponent>key: const ValueKey('icon-button-surface'),duration: Motion.quick,curve: Curves.easeInOutCubic,- width: _buttonSize,- height: _buttonSize,+ width: widget.size,+ height: widget.size,alignment: Alignment.center,decoration: BoxDecoration(color: colors.background,@@ -159,7 +163,7 @@ class _IconButtonComponentState extends State<IconButtonComponent>turns: _loadingController,child: HugeIcon(icon: HugeIcons.strokeRoundedLoading03,- size: _iconSize,+ size: widget.iconSize,color: foreground,),);@@ -168,13 +172,13 @@ class _IconButtonComponentState extends State<IconButtonComponent>return HugeIcon(key: const ValueKey('success'),icon: HugeIcons.strokeRoundedTick02,- size: _iconSize,+ size: widget.iconSize,color: foreground,);}return IconTheme.merge(key: const ValueKey('icon'),- data: IconThemeData(size: _iconSize, color: foreground),+ data: IconThemeData(size: widget.iconSize, color: foreground),child: widget.icon,);}@@ -424,8 +428,8 @@ class _IconButtonComponentState extends State<IconButtonComponent>}}-const double _buttonSize = 36;-const double _iconSize = IconSizes.small;+const double _defaultButtonSize = 36;+const double _defaultIconSize = IconSizes.small;class _ResolvedIconButtonColors {const _ResolvedIconButtonColors({