A cross platform Audiobookshelf client for Android and iOS
Dart
Simplify absorbing header: Stop + Refresh, protect continue-series
Nathan Poulsonac86453b0f8c
diff --git a/lib/providers/library_provider.dart b/lib/providers/library_provider.dartindex 653ffde5..69d93ad0 100644--- a/lib/providers/library_provider.dart+++ b/lib/providers/library_provider.dart@@ -742,11 +742,21 @@ class LibraryProvider extends ChangeNotifier {// playing item. The player is the source of truth while active.// This prevents rollbacks when the network drops and reconnects with// stale server progress.+ // Exception: if the server marked the item finished (e.g. user paused+ // near the end and the server's "mark finished with N seconds remaining"+ // threshold fired) AND the player is paused, update the finished state+ // so the absorbing card reflects it. Don't interrupt active playback -+ // let _onPlaybackComplete handle that naturally.final player = AudioPlayerService();final playingKey = player.currentEpisodeId != null? '${player.currentItemId}-${player.currentEpisodeId}': player.currentItemId;- if (key == playingKey && player.hasBook) return;+ if (key == playingKey && player.hasBook) {+ if (mp['isFinished'] == true && !player.isPlaying) {+ markFinishedLocally(key, skipAutoAdvance: true);+ }+ return;+ }_progressMap[key] = mp;_localProgressOverrides.remove(key);_resetItems.remove(key);@@ -1787,6 +1797,10 @@ class LibraryProvider extends ChangeNotifier {for (final key in continueSeriesKeys) {if (!existingIds.contains(key)) {_absorbingIdsAdd(key, afterKey: _lastFinishedItemId);+ // Protect from pruning on future refreshes (the server may not+ // include it in continue-series again until the user starts it).+ _manualAbsorbAdds.add(key);+ _manualAbsorbRemoves.remove(key);newContinueSeriesKey ??= key; // first new item is the next in series}}diff --git a/lib/screens/absorbing_screen.dart b/lib/screens/absorbing_screen.dartindex 4c8f2c6d..4ae7046f 100644--- a/lib/screens/absorbing_screen.dart+++ b/lib/screens/absorbing_screen.dart@@ -240,28 +240,6 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {await lib.refresh();}- /// Confirm before syncing when idle — server positions will overwrite local.- Future<void> _confirmAndSync(LibraryProvider lib) async {- final confirmed = await showDialog<bool>(- context: context,- builder: (ctx) => AlertDialog(- title: const Text('Sync with server?'),- content: const Text(- 'This will pull fresh positions from the server. '- 'Any local progress will be replaced with whatever '- 'the server has.',- ),- actions: [- TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('Cancel')),- FilledButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('Sync')),- ],- ),- );- if (confirmed != true || !mounted) return;- setState(() => _isSyncing = true);- await _pullRefresh();- if (mounted) setState(() => _isSyncing = false);- }/// Derive the absorbing key for an item map: compound "itemId-episodeId" for/// podcast episodes, plain "itemId" for books.@@ -522,18 +500,11 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {),),const SizedBox(width: 8),- // Unified button: "Sync" when idle, "Stop & Sync" when playing- if (!effectiveOffline)+ // Stop button (visible when playing)+ if (_player.hasBook)GestureDetector(- onTap: _isSyncing ? null : () {- if (_player.hasBook) {- _stopAndRefresh(lib);- } else {- _confirmAndSync(lib);- }- },- child: AnimatedContainer(- duration: const Duration(milliseconds: 200),+ onTap: _isSyncing ? null : () => _stopAndRefresh(lib),+ child: Container(padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),decoration: BoxDecoration(color: subtleBg,@@ -542,52 +513,32 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {),child: Row(mainAxisSize: MainAxisSize.min,- mainAxisAlignment: MainAxisAlignment.center,children: [- if (_isSyncing) ...[- SizedBox(width: 12, height: 12, child: CircularProgressIndicator(strokeWidth: 1.5, color: muted)),- const SizedBox(width: 6),- Text('Syncing…', style: TextStyle(color: muted, fontSize: 11, fontWeight: FontWeight.w500)),- ] else if (_player.hasBook) ...[- Icon(Icons.stop_rounded, size: 14, color: muted),- const SizedBox(width: 4),- Text('Stop & Sync', style: TextStyle(color: muted, fontSize: 11, fontWeight: FontWeight.w500)),- ] else ...[- Icon(Icons.sync_rounded, size: 14, color: muted),- const SizedBox(width: 4),- Text('Sync', style: TextStyle(color: muted, fontSize: 11, fontWeight: FontWeight.w500)),- ],+ Icon(Icons.stop_rounded, size: 14, color: muted),+ const SizedBox(width: 4),+ Text('Stop', style: TextStyle(color: muted, fontSize: 11, fontWeight: FontWeight.w500)),],),),)- else- // Offline: just stop button (no sync)- AnimatedOpacity(- opacity: _player.hasBook ? 1.0 : 0.0,- duration: const Duration(milliseconds: 300),- child: IgnorePointer(- ignoring: !_player.hasBook,- child: GestureDetector(- onTap: () => _stopAndRefresh(lib),- child: Container(- padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),- decoration: BoxDecoration(- color: subtleBg,- borderRadius: BorderRadius.circular(20),- border: Border.all(color: subtleBorder),- ),- child: Row(- mainAxisAlignment: MainAxisAlignment.center,- mainAxisSize: MainAxisSize.min,- children: [- Icon(Icons.stop_rounded, size: 14, color: muted),- const SizedBox(width: 4),- Text('Stop', style: TextStyle(color: muted, fontSize: 11, fontWeight: FontWeight.w500)),- ],- ),- ),+ // Refresh button (visible when idle + online)+ else if (!effectiveOffline)+ GestureDetector(+ onTap: _isSyncing ? null : () async {+ setState(() => _isSyncing = true);+ await _pullRefresh();+ if (mounted) setState(() => _isSyncing = false);+ },+ child: Container(+ padding: const EdgeInsets.all(6),+ decoration: BoxDecoration(+ color: subtleBg,+ shape: BoxShape.circle,+ border: Border.all(color: subtleBorder),),+ child: _isSyncing+ ? SizedBox(width: 14, height: 14, child: CircularProgressIndicator(strokeWidth: 1.5, color: muted))+ : Icon(Icons.refresh_rounded, size: 14, color: muted),),),if (books.length > 1) ...[diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dartindex 9d3ee5f2..c3bab9fd 100644--- a/lib/screens/settings_screen.dart+++ b/lib/screens/settings_screen.dart@@ -306,7 +306,7 @@ class _SettingsScreenState extends State<SettingsScreen> {_tipCard(cs, tt,icon: Icons.fullscreen_rounded,title: 'Full Screen Player',- desc: 'Tap the cover art on the active card to open a full screen player view. Swipe down to dismiss it. You can also enable "Full screen player" in Settings to auto-open it whenever playback starts.',+ desc: 'Tap the cover art on the active card to open a full screen player view. Tap the cover again to dismiss it. You can also enable "Full screen player" in Settings to auto-open it whenever playback starts.',),_tipCard(cs, tt,icon: Icons.edit_note_rounded,@@ -362,8 +362,8 @@ class _SettingsScreenState extends State<SettingsScreen> {),_tipCard(cs, tt,icon: Icons.stop_rounded,- title: 'Stop & Sync',- desc: 'The "Stop & Sync" button in the Absorbing header fully stops playback and syncs your progress to the server. Use it when you\'re done listening for the day.',+ title: 'Stop Playback',+ desc: 'The Stop button in the Absorbing header ends your listening session and saves your progress. Your progress syncs automatically in the background.',),_tipCard(cs, tt,icon: Icons.download_rounded,diff --git a/lib/widgets/expanded_card.dart b/lib/widgets/expanded_card.dartindex 486b089b..f7b156a6 100644--- a/lib/widgets/expanded_card.dart+++ b/lib/widgets/expanded_card.dart@@ -95,9 +95,6 @@ class _ExpandedCardState extends State<ExpandedCard> {// Our own route, captured for popUntil when modals are stacked above usRoute<dynamic>? _ownRoute;- // Swipe-down-to-dismiss- double _dragOffset = 0;-// Current item data (may change if a new book starts)late Map<String, dynamic> _item;@@ -245,17 +242,16 @@ class _ExpandedCardState extends State<ExpandedCard> {widget.player.removeListener(_onPlayerChanged);ChromecastService().removeListener(_onCastChanged);_chapterTrackSub?.cancel();- WidgetsBinding.instance.addPostFrameCallback((_) {- if (!mounted) return;- final nav = Navigator.of(context, rootNavigator: true);- // Pop all routes above us (e.g. open modals/sheets) plus our own route- if (_ownRoute != null) {- nav.popUntil((route) => route == _ownRoute);- nav.pop();- } else {- nav.pop();- }- });+ if (!mounted) return;+ final nav = Navigator.of(context, rootNavigator: true);+ if (!nav.canPop()) return;+ // Pop all routes above us (e.g. open modals/sheets) plus our own route+ if (_ownRoute != null) {+ nav.popUntil((route) => route == _ownRoute);+ if (nav.canPop()) nav.pop();+ } else {+ nav.pop();+ }}void _handleItemChange(String newItemId, String? newEpisodeId) {@@ -505,25 +501,7 @@ class _ExpandedCardState extends State<ExpandedCard> {return Scaffold(backgroundColor: cs.surface,- body: GestureDetector(- behavior: HitTestBehavior.translucent,- onVerticalDragUpdate: (details) {- final newOffset = _dragOffset + details.delta.dy;- if (newOffset < 0) return; // only allow downward- setState(() => _dragOffset = newOffset);- },- onVerticalDragEnd: (details) {- if (_dragOffset > 100 || details.velocity.pixelsPerSecond.dy > 500) {- _dismissExpanded();- } else {- setState(() => _dragOffset = 0);- }- },- child: Transform.translate(- offset: Offset(0, _dragOffset),- child: Opacity(- opacity: (1.0 - (_dragOffset / 400)).clamp(0.5, 1.0),- child: Stack(+ body: Stack(fit: StackFit.expand,children: [// Layer 1: Blurred cover background@@ -587,7 +565,10 @@ class _ExpandedCardState extends State<ExpandedCard> {const SizedBox(height: 16),// ── Cover art (larger — 90% width) ──Flexible(- child: Padding(+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: _dismissExpanded,+ child: Padding(padding: const EdgeInsets.symmetric(horizontal: 4),child: ListenableBuilder(listenable: ChromecastService(),@@ -745,6 +726,7 @@ class _ExpandedCardState extends State<ExpandedCard> {),),),+ ),const SizedBox(height: 24),// ── Chapter scrubber ──Padding(@@ -832,9 +814,6 @@ class _ExpandedCardState extends State<ExpandedCard> {),],),- ),- ),- ),);}