A cross platform Audiobookshelf client for Android and iOS
Dart
Fine-grained distance-based scrubbing for all progress bars
Nathan Poulsonfafe3ded7a88
diff --git a/lib/widgets/card_edge_progress_bar.dart b/lib/widgets/card_edge_progress_bar.dartindex cb0db5b6..073fc99b 100644--- a/lib/widgets/card_edge_progress_bar.dart+++ b/lib/widgets/card_edge_progress_bar.dart@@ -51,6 +51,9 @@ class _CardEdgeProgressBarState extends State<CardEdgeProgressBar>// ── Expand/collapse animation ──late AnimationController _expandController;double? _dragValue;+ double _dragStartDy = 0;+ double _lastLongPressDx = 0;+ double _edgeScrubSpeed = 1.0;bool _showBookSlider = false;static const _thinHeight = 3.5;@@ -190,6 +193,19 @@ class _CardEdgeProgressBarState extends State<CardEdgeProgressBar>}}+ static double _scrubScale(double vertDist) {+ if (vertDist < 50) return 1.0;+ if (vertDist < 100) return 0.5;+ if (vertDist < 175) return 0.25;+ return 0.1;+ }++ static String _scrubSpeedLabel(double scale) {+ if (scale <= 0.1) return 'Fine Scrubbing';+ if (scale <= 0.25) return 'Quarter Speed';+ return 'Half Speed';+ }+@overridevoid dispose() {WidgetsBinding.instance.removeObserver(this);@@ -249,12 +265,15 @@ class _CardEdgeProgressBarState extends State<CardEdgeProgressBar>if (!_expandController.isAnimating && _expandController.value < 1.0) {_expandController.forward();}+ _dragStartDy = d.localPosition.dy;+ _edgeScrubSpeed = 1.0;final box = context.findRenderObject() as RenderBox;setState(() => _dragValue = (d.localPosition.dx / box.size.width).clamp(0.0, 1.0));} : null,onHorizontalDragUpdate: interactive ? (d) {final box = context.findRenderObject() as RenderBox;- setState(() => _dragValue = (d.localPosition.dx / box.size.width).clamp(0.0, 1.0));+ _edgeScrubSpeed = _scrubScale((d.localPosition.dy - _dragStartDy).abs());+ setState(() => _dragValue = ((_dragValue ?? bookProgress) + d.delta.dx / box.size.width * _edgeScrubSpeed).clamp(0.0, 1.0));} : null,onHorizontalDragEnd: interactive ? (_) {if (_dragValue != null) {@@ -266,12 +285,18 @@ class _CardEdgeProgressBarState extends State<CardEdgeProgressBar>} : null,onLongPressStart: interactive ? (d) {_expandController.forward();+ _dragStartDy = d.localPosition.dy;+ _lastLongPressDx = d.localPosition.dx;+ _edgeScrubSpeed = 1.0;final box = context.findRenderObject() as RenderBox;setState(() => _dragValue = (d.localPosition.dx / box.size.width).clamp(0.0, 1.0));} : null,onLongPressMoveUpdate: interactive ? (d) {final box = context.findRenderObject() as RenderBox;- setState(() => _dragValue = (d.localPosition.dx / box.size.width).clamp(0.0, 1.0));+ _edgeScrubSpeed = _scrubScale((d.localPosition.dy - _dragStartDy).abs());+ final delta = d.localPosition.dx - _lastLongPressDx;+ _lastLongPressDx = d.localPosition.dx;+ setState(() => _dragValue = ((_dragValue ?? bookProgress) + delta / box.size.width * _edgeScrubSpeed).clamp(0.0, 1.0));} : null,onLongPressEnd: interactive ? (_) {if (_dragValue != null) {@@ -329,6 +354,7 @@ class _CardEdgeProgressBarState extends State<CardEdgeProgressBar>)],),),+ if (_dragValue != null && _edgeScrubSpeed < 1.0) Text(_scrubSpeedLabel(_edgeScrubSpeed), style: tt.labelSmall?.copyWith(color: widget.accent, fontSize: 11, fontWeight: FontWeight.w500)),Text('-${_fmt(_dragValue != null ? (1.0 - _dragValue!) * totalDur / speedDiv : bookRemaining)}',style: tt.labelSmall?.copyWith(diff --git a/lib/widgets/card_progress_bar.dart b/lib/widgets/card_progress_bar.dartindex 30bcd9b6..b8b5eea9 100644--- a/lib/widgets/card_progress_bar.dart+++ b/lib/widgets/card_progress_bar.dart@@ -28,6 +28,10 @@ class CardDualProgressBar extends StatefulWidget {class _CardDualProgressBarState extends State<CardDualProgressBar> with TickerProviderStateMixin, WidgetsBindingObserver {double? _chapterDragValue;double? _bookDragValue;+ double _bookDragStartDy = 0;+ double _chapterDragStartDy = 0;+ double _bookScrubSpeed = 1.0;+ double _chapterScrubSpeed = 1.0;bool _showBookSlider = false;bool _speedAdjustedTime = true;late AnimationController _smoothTicker;@@ -184,6 +188,19 @@ class _CardDualProgressBarState extends State<CardDualProgressBar> with TickerPr}}+ static double _scrubScale(double vertDist) {+ if (vertDist < 50) return 1.0;+ if (vertDist < 100) return 0.5;+ if (vertDist < 175) return 0.25;+ return 0.1;+ }++ static String _scrubSpeedLabel(double scale) {+ if (scale <= 0.1) return 'Fine Scrubbing';+ if (scale <= 0.25) return 'Quarter Speed';+ return 'Half Speed';+ }+@overrideWidget build(BuildContext context) {final tt = Theme.of(context).textTheme;@@ -270,8 +287,8 @@ class _CardDualProgressBarState extends State<CardDualProgressBar> with TickerPrfinal p = _bookDragValue ?? bookProgress;return GestureDetector(behavior: HitTestBehavior.opaque,- onHorizontalDragStart: active ? (d) { setState(() => _bookDragValue = (d.localPosition.dx / w).clamp(0.0, 1.0)); } : null,- onHorizontalDragUpdate: active ? (d) { setState(() => _bookDragValue = (d.localPosition.dx / w).clamp(0.0, 1.0)); } : null,+ onHorizontalDragStart: active ? (d) { _bookDragStartDy = d.localPosition.dy; _bookScrubSpeed = 1.0; setState(() => _bookDragValue = (d.localPosition.dx / w).clamp(0.0, 1.0)); } : null,+ onHorizontalDragUpdate: active ? (d) { _bookScrubSpeed = _scrubScale((d.localPosition.dy - _bookDragStartDy).abs()); setState(() => _bookDragValue = ((_bookDragValue ?? bookProgress) + d.delta.dx / w * _bookScrubSpeed).clamp(0.0, 1.0)); } : null,onHorizontalDragEnd: active ? (_) { if (_bookDragValue != null) { final seekMs = (_bookDragValue! * totalDur * 1000).round(); _doSeek(seekMs); } setState(() => _bookDragValue = null); } : null,onTapUp: active ? (d) { final v = (d.localPosition.dx / w).clamp(0.0, 1.0); final seekMs = (v * totalDur * 1000).round(); _doSeek(seekMs); } : null,child: CustomPaint(size: Size(w, 32), painter: AbsorbProgressPainter(progress: p, accent: widget.accent.withValues(alpha: 0.5), isDragging: _bookDragValue != null)),@@ -281,6 +298,7 @@ class _CardDualProgressBarState extends State<CardDualProgressBar> with TickerPrmainAxisAlignment: MainAxisAlignment.spaceBetween,children: [Text(_fmt(_bookDragValue != null ? _bookDragValue! * totalDur : bookElapsed), style: tt.labelSmall?.copyWith(color: _bookDragValue != null ? cs.onSurface.withValues(alpha: 0.7) : cs.onSurfaceVariant, fontSize: 12, fontWeight: FontWeight.w600, shadows: [Shadow(color: Theme.of(context).brightness == Brightness.dark ? Colors.black.withValues(alpha: 0.5) : Colors.white.withValues(alpha: 0.5), blurRadius: 3)])),+ if (_bookDragValue != null && _bookScrubSpeed < 1.0) Text(_scrubSpeedLabel(_bookScrubSpeed), style: tt.labelSmall?.copyWith(color: widget.accent, fontSize: 11, fontWeight: FontWeight.w500)),Text('-${_fmt(_bookDragValue != null ? (1.0 - _bookDragValue!) * totalDur : bookRemaining)}', style: tt.labelSmall?.copyWith(color: _bookDragValue != null ? cs.onSurface.withValues(alpha: 0.7) : cs.onSurfaceVariant, fontSize: 12, fontWeight: FontWeight.w600, shadows: [Shadow(color: Theme.of(context).brightness == Brightness.dark ? Colors.black.withValues(alpha: 0.5) : Colors.white.withValues(alpha: 0.5), blurRadius: 3)])),],)),@@ -309,8 +327,8 @@ class _CardDualProgressBarState extends State<CardDualProgressBar> with TickerPrreturn GestureDetector(behavior: HitTestBehavior.opaque,- onHorizontalDragStart: active ? (d) { setState(() => _chapterDragValue = (d.localPosition.dx / w).clamp(0.0, 1.0)); } : null,- onHorizontalDragUpdate: active ? (d) { setState(() => _chapterDragValue = (d.localPosition.dx / w).clamp(0.0, 1.0)); } : null,+ onHorizontalDragStart: active ? (d) { _chapterDragStartDy = d.localPosition.dy; _chapterScrubSpeed = 1.0; setState(() => _chapterDragValue = (d.localPosition.dx / w).clamp(0.0, 1.0)); } : null,+ onHorizontalDragUpdate: active ? (d) { _chapterScrubSpeed = _scrubScale((d.localPosition.dy - _chapterDragStartDy).abs()); setState(() => _chapterDragValue = ((_chapterDragValue ?? chapterProgress) + d.delta.dx / w * _chapterScrubSpeed).clamp(0.0, 1.0)); } : null,onHorizontalDragEnd: active ? (_) { if (_chapterDragValue != null) { final seekMs = ((chapterStart + _chapterDragValue! * chapterDur) * 1000).round(); _doSeek(seekMs); } setState(() => _chapterDragValue = null); } : null,onTapUp: active ? (d) { final v = (d.localPosition.dx / w).clamp(0.0, 1.0); final seekMs = ((chapterStart + v * chapterDur) * 1000).round(); _doSeek(seekMs); } : null,child: CustomPaint(@@ -352,6 +370,7 @@ class _CardDualProgressBarState extends State<CardDualProgressBar> with TickerPrfontSize: 11, fontWeight: FontWeight.w600,fontFeatures: const [FontFeature.tabularFigures()],shadows: [Shadow(color: Theme.of(context).brightness == Brightness.dark ? Colors.black.withValues(alpha: 0.5) : Colors.white.withValues(alpha: 0.5), blurRadius: 3)])),+ if (_chapterDragValue != null && _chapterScrubSpeed < 1.0) Text(_scrubSpeedLabel(_chapterScrubSpeed), style: tt.labelSmall?.copyWith(color: widget.accent, fontSize: 11, fontWeight: FontWeight.w500)),Text('-${_fmt(_chapterDragValue != null ? ((1.0 - _chapterDragValue!) * chapterDur) / speedDiv : chapterRemaining)}',style: tt.labelSmall?.copyWith(color: _chapterDragValue != null ? widget.accent : cs.onSurface.withValues(alpha: 0.5),