Skip to content

armgit / ente

Public Imported from GitHub
0

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

Merge branch 'main' of github.com:fosszil/ente into feat/long-press-2x

aaqilc2aae12d5600
diff --cc mobile/apps/photos/lib/ui/viewer/file/video_double_tap_seek.dart
index 0000000000,74c6097c08..8d582ca431
mode 000000,100644..100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_double_tap_seek.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_double_tap_seek.dart
@@@ -1,0 -1,206 +1,209 @@@
+ import "dart:async";
+
+ import "package:flutter/material.dart";
+ import "package:hugeicons/hugeicons.dart";
+ import "package:photos/theme/colors.dart";
+ import "package:photos/theme/ente_theme.dart";
+
+ const kDefaultSeekDuration = Duration(seconds: 5);
+
+ class DoubleTapSeekOverlay extends StatefulWidget {
+ final bool Function() enabled;
+ final Duration Function() position;
+ final Duration Function() duration;
+ final Duration Function(Duration) seekBy;
+ final VoidCallback? onSingleTap;
+ final VoidCallback? onSeekInteraction;
+ final GestureLongPressCallback? onLongPress;
+ final GestureLongPressUpCallback? onLongPressUp;
++ final VoidCallback? onLongPressCancel;
+
+ const DoubleTapSeekOverlay({
+ required this.enabled,
+ required this.position,
+ required this.duration,
+ required this.seekBy,
+ this.onSeekInteraction,
+ this.onSingleTap,
+ this.onLongPress,
+ this.onLongPressUp,
++ this.onLongPressCancel,
+ super.key,
+ });
+
+ @override
+ State<DoubleTapSeekOverlay> createState() => _DoubleTapSeekOverlayState();
+ }
+
+ class _DoubleTapSeekOverlayState extends State<DoubleTapSeekOverlay>
+ with SingleTickerProviderStateMixin {
+ Timer? _badgeHideTimer;
+ bool _showBadge = false;
+ bool _badgeForward = true;
+ int _accumulatedSeconds = 0;
+ DateTime? _lastDoubleTapTime;
+ bool? _lastDirection;
+ Duration? _lastSeekTarget;
+ TapDownDetails? _doubleTapDetails;
+ int _seekGeneration = 0;
+ late final AnimationController _badgeAnimation;
+
+ @override
+ void initState() {
+ super.initState();
+ _badgeAnimation = AnimationController(
+ vsync: this,
+ duration: const Duration(milliseconds: 180),
+ );
+ }
+
+ @override
+ void dispose() {
+ _badgeHideTimer?.cancel();
+ _badgeAnimation.dispose();
+ super.dispose();
+ }
+
+ void _handleDoubleTap(TapDownDetails details) {
+ if (!widget.enabled()) return;
+
+ final renderBox = context.findRenderObject() as RenderBox?;
+ final width = renderBox?.size.width ?? MediaQuery.of(context).size.width;
+ final isForward = details.localPosition.dx >= width / 2;
+
+ if (widget.duration() <= Duration.zero) return;
+
+ final now = DateTime.now();
+ final isFastSequence =
+ _lastDoubleTapTime != null &&
+ now.difference(_lastDoubleTapTime!).inMilliseconds <= 750 &&
+ _lastDirection == isForward;
+
+ final position = widget.position();
+ final target = widget.seekBy(
+ isForward ? kDefaultSeekDuration : -kDefaultSeekDuration,
+ );
+ if (isFastSequence && target == _lastSeekTarget) {
+ _lastDoubleTapTime = now;
+ _showSeekBadge(isForward);
+ return;
+ }
+ if (target == position) {
+ if (_showBadge) {
+ _lastDoubleTapTime = now;
+ _showSeekBadge(isForward);
+ }
+ return;
+ }
+ final requestedSeconds = kDefaultSeekDuration.inSeconds;
+
+ if (isFastSequence) {
+ _accumulatedSeconds += requestedSeconds;
+ } else {
+ _accumulatedSeconds = requestedSeconds;
+ _lastDirection = isForward;
+ }
+ _lastDoubleTapTime = now;
+ _lastSeekTarget = target;
+ _seekGeneration++;
+
+ widget.onSeekInteraction?.call();
+ _showSeekBadge(isForward);
+ }
+
+ void _showSeekBadge(bool forward) {
+ _badgeHideTimer?.cancel();
+ final generation = _seekGeneration;
+ setState(() {
+ _badgeForward = forward;
+ _showBadge = true;
+ });
+ _badgeAnimation.forward(from: 0);
+ _badgeHideTimer = Timer(const Duration(milliseconds: 750), () {
+ if (!mounted || generation != _seekGeneration) return;
+ setState(() {
+ _showBadge = false;
+ _lastDoubleTapTime = null;
+ _lastSeekTarget = null;
+ });
+ });
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Stack(
+ fit: StackFit.expand,
+ children: [
+ GestureDetector(
+ behavior: HitTestBehavior.translucent,
+ onTap: widget.onSingleTap,
+ onDoubleTapDown: (details) => _doubleTapDetails = details,
+ onDoubleTapCancel: () => _doubleTapDetails = null,
+ onDoubleTap: () {
+ if (_doubleTapDetails != null) {
+ _handleDoubleTap(_doubleTapDetails!);
+ _doubleTapDetails = null;
+ }
+ },
+ onLongPress: widget.onLongPress,
+ onLongPressUp: widget.onLongPressUp,
++ onLongPressCancel: widget.onLongPressCancel,
+ child: Container(constraints: const BoxConstraints.expand()),
+ ),
+ SafeArea(
+ top: false,
+ bottom: false,
+ child: Align(
+ alignment: _badgeForward
+ ? Alignment.centerRight
+ : Alignment.centerLeft,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 24),
+ child: IgnorePointer(
+ child: AnimatedOpacity(
+ opacity: _showBadge ? 1 : 0,
+ duration: const Duration(milliseconds: 180),
+ child: ScaleTransition(
+ scale: Tween<double>(begin: 0.8, end: 1).animate(
+ CurvedAnimation(
+ parent: _badgeAnimation,
+ curve: Curves.easeOutQuad,
+ ),
+ ),
+ child: Container(
+ width: 54,
+ height: 54,
+ decoration: BoxDecoration(
+ color: Colors.black.withValues(alpha: 0.3),
+ shape: BoxShape.circle,
+ border: Border.all(color: strokeFaintDark, width: 1),
+ ),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ HugeIcon(
+ icon: _badgeForward
+ ? HugeIcons.strokeRoundedArrowRightDouble
+ : HugeIcons.strokeRoundedArrowLeftDouble,
+ size: 20,
+ color: textBaseDark,
+ ),
+ Text(
+ "${_accumulatedSeconds}s",
+ style: getEnteTextTheme(
+ context,
+ ).tiny.copyWith(color: textBaseDark),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+ }
diff --cc mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit_common.dart
index 6de5a8cad4,d539641696..11c8b68e0f
--- 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
@@@ -42,12 -45,13 +45,15 @@@ class VideoWidget extends StatefulWidge
}
class _VideoWidgetState extends State<VideoWidget> {
+ final _logger = Logger("VideoWidget");
final showControlsNotifier = ValueNotifier<bool>(true);
final _hideControlsDebouncer = Debouncer(const Duration(milliseconds: 2000));
- final _isSeekingNotifier = ValueNotifier<bool>(false);
+ late final VideoSeekController _seekController;
+ bool _isSeekInteractionActive = false;
late final StreamSubscription<bool> _isPlayingStreamSubscription;
+ bool _isLongPressSpeedActive = false;
+ OverlayEntry? _longPressSpeedIndicatorEntry;
+ late final StreamSubscription<bool> _completedStreamSubscription;
@override
void initState() {
@@@ -86,23 -108,11 +111,26 @@@
widget.controller.player.setRate(widget.playbackSpeed.value);
}
+ void _startLongPressSpeed() {
+ if (_isLongPressSpeedActive) return;
+ _isLongPressSpeedActive = true;
+ _longPressSpeedIndicatorEntry = showVideoLongPressSpeedIndicator(context);
+ widget.controller.player.setRate(kVideoLongPressPlaybackSpeed).ignore();
+ }
+
+ void _restorePlaybackSpeed() {
+ if (!_isLongPressSpeedActive) return;
+ _isLongPressSpeedActive = false;
+ _longPressSpeedIndicatorEntry?.remove();
+ _longPressSpeedIndicatorEntry = null;
+ widget.controller.player.setRate(widget.playbackSpeed.value).ignore();
+ }
+
- void isSeekingListener() {
- if (_isSeekingNotifier.value) {
+ void _onSeekInteractionChanged() {
+ final isInteracting = _seekController.state.isInteracting;
+ if (_isSeekInteractionActive == isInteracting) return;
+ _isSeekInteractionActive = isInteracting;
+ if (isInteracting) {
_hideControlsDebouncer.cancelDebounceTimer();
} else {
if (widget.controller.player.state.playing) {
@@@ -134,6 -144,48 +162,55 @@@
child: videoWidget,
)
: videoWidget,
+ DoubleTapSeekOverlay(
+ enabled: () => !widget.isFromMemories,
+ position: () => _seekController.position,
+ duration: () => widget.controller.player.state.duration,
+ seekBy: _seekController.seekBy,
+ onSeekInteraction: () {
+ showControlsNotifier.value = true;
+ },
+ onSingleTap: widget.isFromMemories
+ ? null
+ : () {
+ showControlsNotifier.value = !showControlsNotifier.value;
+ if (widget.playbackCallback != null) {
+ widget.playbackCallback!(
+ !showControlsNotifier.value,
+ FullScreenRequestReason.userInteraction,
+ );
+ }
+ },
- onLongPress: widget.isFromMemories
- ? () {
- widget.playbackCallback?.call(
- false,
- FullScreenRequestReason.userInteraction,
- );
- if (widget.controller.player.state.playing) {
- widget.controller.player.pause();
- }
- }
- : null,
- onLongPressUp: widget.isFromMemories
- ? () {
- widget.playbackCallback?.call(
- true,
- FullScreenRequestReason.userInteraction,
- );
- if (!widget.controller.player.state.playing) {
- widget.controller.player.play();
- }
- }
- : null,
++ onLongPress: () {
++ if (widget.isFromMemories) {
++ widget.playbackCallback?.call(
++ false,
++ FullScreenRequestReason.userInteraction,
++ );
++ if (widget.controller.player.state.playing) {
++ widget.controller.player.pause();
++ }
++ } else {
++ _startLongPressSpeed();
++ }
++ },
++ onLongPressUp: () {
++ if (widget.isFromMemories) {
++ widget.playbackCallback?.call(
++ true,
++ FullScreenRequestReason.userInteraction,
++ );
++ if (!widget.controller.player.state.playing) {
++ widget.controller.player.play();
++ }
++ } else {
++ _restorePlaybackSpeed();
++ }
++ },
++ onLongPressCancel: widget.isFromMemories
++ ? null
++ : _restorePlaybackSpeed,
+ ),
ValueListenableBuilder(
valueListenable: showControlsNotifier,
builder: (context, value, _) {
diff --cc mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
index 6474e490a9,ae683b4418..a038d28fc8
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
@@@ -410,34 -424,25 +443,31 @@@ class _VideoWidgetNativeState extends S
);
}
},
- onLongPress: widget.isFromMemories
- ? () {
- widget.playbackCallback?.call(
- false,
- FullScreenRequestReason.userInteraction,
- );
- _controller?.pause();
- }
- : null,
- onLongPressUp: widget.isFromMemories
- ? () {
- if (!widget.isActive) return;
- widget.playbackCallback?.call(
- true,
- FullScreenRequestReason.userInteraction,
- );
- _controller?.play();
- }
- : null,
+ onLongPress: () {
+ if (widget.isFromMemories) {
+ widget.playbackCallback?.call(
+ false,
+ FullScreenRequestReason.userInteraction,
+ );
+ _controller?.pause();
+ } else {
+ _startLongPressSpeed();
+ }
+ },
+ onLongPressUp: () {
+ if (widget.isFromMemories && widget.isActive) {
+ widget.playbackCallback?.call(
+ true,
+ FullScreenRequestReason.userInteraction,
+ );
+ _controller?.play();
+ } else if (!widget.isFromMemories) {
+ _restorePlaybackSpeed();
+ }
+ },
+ onLongPressCancel: widget.isFromMemories
+ ? null
+ : _restorePlaybackSpeed,
- child: Container(
- constraints: const BoxConstraints.expand(),
- ),
),
if (!widget.isFromMemories && isPlaybackReady)
Positioned.fill(