Skip to content

armgit / ente

Public Imported from GitHub
0

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

Preserve fullscreen during video playback

ashilkn283fe66e71a1
diff --git a/mobile/apps/photos/lib/states/detail_page_state.dart b/mobile/apps/photos/lib/states/detail_page_state.dart
index b4770b4e38..ae0ead02c0 100644
--- a/mobile/apps/photos/lib/states/detail_page_state.dart
+++ b/mobile/apps/photos/lib/states/detail_page_state.dart
@@ -1,6 +1,16 @@
import "package:flutter/material.dart";
import "package:flutter/services.dart";
+enum FullScreenRequestReason {
+ userInteraction,
+ playbackStateChange,
+}
+
+typedef FullScreenRequestCallback = void Function(
+ bool shouldEnable,
+ FullScreenRequestReason reason,
+);
+
class InheritedDetailPageState extends InheritedWidget {
final enableFullScreenNotifier = ValueNotifier(false);
InheritedDetailPageState({
@@ -14,12 +24,29 @@ class InheritedDetailPageState extends InheritedWidget {
static InheritedDetailPageState? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<InheritedDetailPageState>();
- void toggleFullScreen({bool? shouldEnable}) {
- if (shouldEnable != null) {
- if (enableFullScreenNotifier.value == shouldEnable) return;
+ void toggleFullScreenByUser() {
+ _applyFullScreenState(!enableFullScreenNotifier.value);
+ }
+
+ void requestFullScreen({
+ required bool shouldEnable,
+ required FullScreenRequestReason reason,
+ }) {
+ if (!shouldEnable && reason != FullScreenRequestReason.userInteraction) {
+ return;
+ }
+ if (enableFullScreenNotifier.value == shouldEnable) {
+ return;
+ }
+ _applyFullScreenState(shouldEnable);
+ }
+
+ void _applyFullScreenState(bool shouldEnable) {
+ if (enableFullScreenNotifier.value == shouldEnable) {
+ return;
}
- enableFullScreenNotifier.value = !enableFullScreenNotifier.value;
- if (enableFullScreenNotifier.value) {
+ enableFullScreenNotifier.value = shouldEnable;
+ if (shouldEnable) {
Future.delayed(const Duration(milliseconds: 200), () {
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
diff --git a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
index 7820b0a722..d9bf3a2f4e 100644
--- a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
@@ -444,8 +444,8 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
backgroundDecoration:
const BoxDecoration(color: Colors.transparent),
isFromMemories: true,
- playbackCallback: (isPlaying) {
- _toggleAnimation(pause: !isPlaying);
+ playbackCallback: (shouldEnable, _) {
+ _toggleAnimation(pause: !shouldEnable);
},
onFinalFileLoad: ({required int memoryDuration}) {
onFinalFileLoad(memoryDuration);
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
index 844b65631d..85f299272c 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
@@ -308,10 +308,12 @@ class _BodyState extends State<_Body> {
});
}
},
- playbackCallback: (isPlaying) {
+ playbackCallback: (shouldEnable, reason) {
Future.delayed(Duration.zero, () {
- InheritedDetailPageState.of(context)
- .toggleFullScreen(shouldEnable: isPlaying);
+ InheritedDetailPageState.of(context).requestFullScreen(
+ shouldEnable: shouldEnable,
+ reason: reason,
+ );
});
},
backgroundDecoration: const BoxDecoration(color: Colors.black),
@@ -319,7 +321,7 @@ class _BodyState extends State<_Body> {
return GestureDetector(
onTap: () {
file.fileType != FileType.video
- ? InheritedDetailPageState.of(context).toggleFullScreen()
+ ? InheritedDetailPageState.of(context).toggleFullScreenByUser()
: null;
},
child: fileContent,
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
index 8d5e029720..9a1d2dfaa7 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/file_type.dart';
+import "package:photos/states/detail_page_state.dart";
import "package:photos/ui/viewer/file/video_widget.dart";
import "package:photos/ui/viewer/file/zoomable_live_image_new.dart";
@@ -9,7 +10,7 @@ class FileWidget extends StatelessWidget {
final EnteFile file;
final String tagPrefix;
final Function(bool)? shouldDisableScroll;
- final Function(bool)? playbackCallback;
+ final FullScreenRequestCallback? playbackCallback;
final BoxDecoration? backgroundDecoration;
final bool? autoPlay;
final bool? isFromMemories;
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget.dart
index fa9468d94a..ff1265d125 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget.dart
@@ -12,6 +12,7 @@ import "package:photos/models/file/file.dart";
import "package:photos/models/preview/playlist_data.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/video_preview_service.dart";
+import "package:photos/states/detail_page_state.dart";
import "package:photos/theme/colors.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/notification/toast.dart";
@@ -22,7 +23,7 @@ import "package:photos/utils/standalone/data.dart";
class VideoWidget extends StatefulWidget {
final EnteFile file;
final String? tagPrefix;
- final Function(bool)? playbackCallback;
+ final FullScreenRequestCallback? playbackCallback;
final Function({required int memoryDuration})? onFinalFileLoad;
final bool isFromMemories;
@@ -91,7 +92,10 @@ class _VideoWidgetState extends State<VideoWidget> {
if (!isPreviewLoadable) {
return;
}
- widget.playbackCallback?.call(false);
+ widget.playbackCallback?.call(
+ false,
+ FullScreenRequestReason.playbackStateChange,
+ );
final data = await VideoPreviewService.instance
.getPlaylist(widget.file)
.onError((error, stackTrace) {
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
index 0b649112a2..bef4f39654 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
@@ -18,6 +18,7 @@ import "package:photos/module/download/task.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/files_service.dart";
import "package:photos/services/wake_lock_service.dart";
+import "package:photos/states/detail_page_state.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/actions/file/file_actions.dart";
@@ -31,7 +32,7 @@ import "package:photos/utils/file_util.dart";
class VideoWidgetMediaKit extends StatefulWidget {
final EnteFile file;
final String? tagPrefix;
- final Function(bool)? playbackCallback;
+ final FullScreenRequestCallback? playbackCallback;
final bool isFromMemories;
final void Function() onStreamChange;
final File? preview;
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart
index 2412a60aab..d6de7f8ba7 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart
@@ -3,6 +3,7 @@ import "dart:async";
import "package:flutter/material.dart";
import "package:media_kit_video/media_kit_video.dart";
import "package:photos/models/file/file.dart";
+import "package:photos/states/detail_page_state.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/actions/file/file_actions.dart";
@@ -14,7 +15,7 @@ import "package:photos/utils/standalone/debouncer.dart";
class VideoWidget extends StatefulWidget {
final EnteFile file;
final VideoController controller;
- final Function(bool)? playbackCallback;
+ final FullScreenRequestCallback? playbackCallback;
final bool isFromMemories;
final void Function() onStreamChange;
final bool isPreviewPlayer;
@@ -51,7 +52,10 @@ class _VideoWidgetState extends State<VideoWidget> {
if (isPlaying && !_isSeekingNotifier.value) {
_hideControlsDebouncer.run(() async {
showControlsNotifier.value = false;
- widget.playbackCallback?.call(true);
+ widget.playbackCallback?.call(
+ true,
+ FullScreenRequestReason.playbackStateChange,
+ );
});
}
});
@@ -76,7 +80,10 @@ class _VideoWidgetState extends State<VideoWidget> {
if (widget.controller.player.state.playing) {
_hideControlsDebouncer.run(() async {
showControlsNotifier.value = false;
- widget.playbackCallback?.call(true);
+ widget.playbackCallback?.call(
+ true,
+ FullScreenRequestReason.playbackStateChange,
+ );
});
}
}
@@ -107,12 +114,16 @@ class _VideoWidgetState extends State<VideoWidget> {
if (widget.playbackCallback != null) {
widget.playbackCallback!(
!showControlsNotifier.value,
+ FullScreenRequestReason.userInteraction,
);
}
},
onLongPress: () {
if (widget.isFromMemories) {
- widget.playbackCallback?.call(false);
+ widget.playbackCallback?.call(
+ false,
+ FullScreenRequestReason.userInteraction,
+ );
if (widget.controller.player.state.playing) {
widget.controller.player.pause();
}
@@ -120,7 +131,10 @@ class _VideoWidgetState extends State<VideoWidget> {
},
onLongPressUp: () {
if (widget.isFromMemories) {
- widget.playbackCallback?.call(true);
+ widget.playbackCallback?.call(
+ true,
+ FullScreenRequestReason.userInteraction,
+ );
if (!widget.controller.player.state.playing) {
widget.controller.player.play();
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
index 3e52a36791..bafda8e939 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
@@ -22,6 +22,7 @@ import "package:photos/module/download/task.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/files_service.dart";
import "package:photos/services/wake_lock_service.dart";
+import "package:photos/states/detail_page_state.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/actions/file/file_actions.dart";
@@ -41,7 +42,7 @@ import "package:visibility_detector/visibility_detector.dart";
class VideoWidgetNative extends StatefulWidget {
final EnteFile file;
final String? tagPrefix;
- final Function(bool)? playbackCallback;
+ final FullScreenRequestCallback? playbackCallback;
final bool isFromMemories;
final void Function()? onStreamChange;
final PlaylistData? playlistData;
@@ -306,20 +307,28 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
: () {
_showControls.value = !_showControls.value;
if (widget.playbackCallback != null) {
- widget
- .playbackCallback!(!_showControls.value);
+ widget.playbackCallback!(
+ !_showControls.value,
+ FullScreenRequestReason.userInteraction,
+ );
}
_elTooltipController.hide();
},
onLongPress: () {
if (widget.isFromMemories) {
- widget.playbackCallback?.call(false);
+ widget.playbackCallback?.call(
+ false,
+ FullScreenRequestReason.userInteraction,
+ );
_controller?.pause();
}
},
onLongPressUp: () {
if (widget.isFromMemories) {
- widget.playbackCallback?.call(true);
+ widget.playbackCallback?.call(
+ true,
+ FullScreenRequestReason.userInteraction,
+ );
_controller?.play();
}
},
@@ -506,7 +515,10 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
}
_showControls.value = false;
if (widget.playbackCallback != null) {
- widget.playbackCallback!(true);
+ widget.playbackCallback!(
+ true,
+ FullScreenRequestReason.playbackStateChange,
+ );
}
}
});
@@ -533,14 +545,20 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
}
_showControls.value = false;
if (widget.playbackCallback != null) {
- widget.playbackCallback!(true);
+ widget.playbackCallback!(
+ true,
+ FullScreenRequestReason.playbackStateChange,
+ );
}
}
});
}
} else {
if (widget.playbackCallback != null && mounted) {
- widget.playbackCallback!(false);
+ widget.playbackCallback!(
+ false,
+ FullScreenRequestReason.playbackStateChange,
+ );
}
}