Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Play a collection as a queue, like playlists

Barnabas99a87b3d2276
diff --git a/lib/providers/_lp_absorbing.dart b/lib/providers/_lp_absorbing.dart
index d54f96f1..0734a291 100644
--- a/lib/providers/_lp_absorbing.dart
+++ b/lib/providers/_lp_absorbing.dart
@@ -438,6 +438,8 @@ mixin _AbsorbingMixin on ChangeNotifier, _StateMixin, _CoreMixin {
_autoAdvanceOffline(itemId);
} else if (mode == 'playlist') {
_advanceInPlaylist(itemId);
+ } else if (mode == 'collection') {
+ _advanceInCollection(itemId);
}
});
}
@@ -1114,6 +1116,84 @@ mixin _AbsorbingMixin on ChangeNotifier, _StateMixin, _CoreMixin {
debugPrint('[AutoAdvance] Playlist $playlistId exhausted after $finishedKey');
}
+ // ── Collection queue mode (books only) ───────────────────────────────
+ // Collections aren't a native queue in ABS, so we drive them through the
+ // same machinery as playlists: a collection's books are normalized into the
+ // playlist-item shape and run through _playPlaylistItem / the finished-item
+ // advance, keyed on `queueCollectionId` instead of `queuePlaylistId`.
+
+ Future<Map<String, dynamic>?> _getCollectionById(String collectionId) async {
+ // Prefer the cached collection (works offline) before hitting the API,
+ // mirroring _getPlaylistById.
+ final cached = _collections.cast<Map<String, dynamic>>().where(
+ (c) => c['id'] == collectionId,
+ ).firstOrNull;
+ if (cached != null) return cached;
+ if (_api == null) return null;
+ try {
+ return await _api!.getCollection(collectionId);
+ } catch (e) {
+ debugPrint('[Collection] getCollection($collectionId) failed: $e');
+ return null;
+ }
+ }
+
+ List<Map<String, dynamic>> _collectionItems(Map<String, dynamic> collection) {
+ final books = (collection['books'] as List<dynamic>?) ?? const [];
+ return books
+ .whereType<Map<String, dynamic>>()
+ .map((b) => {'libraryItemId': b['id'] as String? ?? '', 'libraryItem': b})
+ .where((m) => (m['libraryItemId'] as String).isNotEmpty)
+ .toList();
+ }
+
+ /// Start playing the first unfinished book in [collectionId].
+ Future<bool> playCollectionFromStart(String collectionId) async {
+ final c = await _getCollectionById(collectionId);
+ if (c == null) return false;
+ final items = _collectionItems(c);
+ final idx = firstUnfinishedPlaylistIndex(items);
+ if (idx < 0) return false;
+ return _playPlaylistItem(items[idx]);
+ }
+
+ Future<bool> isInActiveQueueCollection(String libraryItemId,
+ {String? episodeId}) async {
+ final collectionId = await PlayerSettings.getQueueCollectionId();
+ if (collectionId == null) return false;
+ final c = await _getCollectionById(collectionId);
+ if (c == null) return false;
+ final items = _collectionItems(c);
+ final target = episodeId != null ? '$libraryItemId-$episodeId' : libraryItemId;
+ for (final m in items) {
+ if (_playlistItemKey(m) == target) return true;
+ }
+ return false;
+ }
+
+ Future<void> _advanceInCollection(String finishedKey) async {
+ final collectionId = await PlayerSettings.getQueueCollectionId();
+ if (collectionId == null) return;
+ final c = await _getCollectionById(collectionId);
+ if (c == null) {
+ await PlayerSettings.clearQueueModeCollection();
+ return;
+ }
+ final items = _collectionItems(c);
+ int idx = -1;
+ for (var i = 0; i < items.length; i++) {
+ if (_playlistItemKey(items[i]) == finishedKey) { idx = i; break; }
+ }
+ if (idx < 0) return;
+ final self = this as LibraryProvider;
+ for (var i = idx + 1; i < items.length; i++) {
+ final key = _playlistItemKey(items[i]);
+ if (key.isEmpty) continue;
+ if (self.isItemFinishedByKey(key)) continue;
+ if (await _playPlaylistItem(items[i])) return;
+ }
+ }
+
/// Returns the (seriesId, sequence) for [item]. Public wrapper around the
/// private `_StateMixin._extractSeries` so sheets in other files can use
/// it without reaching into private mixins.
@@ -1138,6 +1218,9 @@ mixin _AbsorbingMixin on ChangeNotifier, _StateMixin, _CoreMixin {
Future<Map<String, dynamic>?> fetchPlaylistById(String playlistId) =>
_getPlaylistById(playlistId);
+ Future<Map<String, dynamic>?> fetchCollectionById(String collectionId) =>
+ _getCollectionById(collectionId);
+
// ── Up-next preview ─────────────────────────────────────────────────
String? _playlistItemTitle(Map<String, dynamic> item) {
@@ -1313,6 +1396,28 @@ mixin _AbsorbingMixin on ChangeNotifier, _StateMixin, _CoreMixin {
return null;
}
+ if (mode == 'collection') {
+ final cid = await PlayerSettings.getQueueCollectionId();
+ if (cid == null) return null;
+ final c = await _getCollectionById(cid);
+ if (c == null) return null;
+ final items = _collectionItems(c);
+ final name = c['name'] as String? ?? '';
+ int currentIdx = -1;
+ for (var i = 0; i < items.length; i++) {
+ if (_playlistItemKey(items[i]) == currentItemId) { currentIdx = i; break; }
+ }
+ if (currentIdx < 0) return null;
+ for (var i = currentIdx + 1; i < items.length; i++) {
+ final key = _playlistItemKey(items[i]);
+ if (key.isEmpty) continue;
+ if (self.isItemFinishedByKey(key)) continue;
+ final title = _playlistItemTitle(items[i]);
+ return name.isNotEmpty ? '$name - $title' : title;
+ }
+ return null;
+ }
+
if (mode == 'manual') {
final bookMode = await PlayerSettings.getBookQueueMode();
final podMode = await PlayerSettings.getPodcastQueueMode();
diff --git a/lib/screens/absorbing_screen.dart b/lib/screens/absorbing_screen.dart
index a88fd746..33255946 100644
--- a/lib/screens/absorbing_screen.dart
+++ b/lib/screens/absorbing_screen.dart
@@ -15,6 +15,7 @@ import '../widgets/offline_status_icon.dart';
import '../widgets/overlay_toast.dart';
import '../widgets/series_books_sheet.dart';
import '../widgets/playlist_detail_sheet.dart';
+import '../widgets/collection_detail_sheet.dart';
import '../widgets/episode_list_sheet.dart';
import '../l10n/app_localizations.dart';
import '../services/wording.dart';
@@ -66,6 +67,7 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
String _bookQueueMode = 'off';
String _podcastQueueMode = 'off';
String? _queuePlaylistId;
+ String? _queueCollectionName;
@override
void initState() {
@@ -103,6 +105,12 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
return n.length > 24 ? '${n.substring(0, 23)}…' : n;
}
+ String _activeCollectionChipLabel() {
+ final n = _queueCollectionName;
+ if (n == null || n.isEmpty) return 'Collection';
+ return n.length > 24 ? '${n.substring(0, 23)}…' : n;
+ }
+
Future<void> _loadQueueMode() async {
final lib = context.read<LibraryProvider>();
String mode;
@@ -110,6 +118,8 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
final pm = await PlayerSettings.getPodcastQueueMode();
if (bm == 'playlist' || pm == 'playlist') {
mode = 'playlist';
+ } else if (bm == 'collection') {
+ mode = 'collection';
} else if (_mergeLibraries) {
// When merged, use the more restrictive of the two modes
// (matches Settings screen's _mergedQueueMode logic)
@@ -121,6 +131,7 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
mode = lib.isPodcastLibrary ? pm : bm;
}
final qpId = await PlayerSettings.getQueuePlaylistId();
+ final qcName = await PlayerSettings.getQueueCollectionName();
final showUpNext = await PlayerSettings.getShowUpNextLabel();
if (mounted) {
setState(() {
@@ -128,6 +139,7 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
_bookQueueMode = bm;
_podcastQueueMode = pm;
_queuePlaylistId = qpId;
+ _queueCollectionName = qcName;
_showUpNextLabel = showUpNext;
});
_refreshUpNext();
@@ -147,7 +159,7 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
// the front changes what's up next without changing the first key.
final queueOrder = lib.absorbingBookIds.join(',');
final stamp = '$_queueMode|$_bookQueueMode|$_podcastQueueMode|$_mergeLibraries'
- '|$_queuePlaylistId|$currentId|$queueOrder';
+ '|$_queuePlaylistId|$_queueCollectionName|$currentId|$queueOrder';
if (stamp == _upNextComputedFor) return;
_upNextComputedFor = stamp;
final label = await lib.peekUpNext(currentItemId: currentId);
@@ -710,9 +722,11 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
Text(
_queueMode == 'playlist'
? _activePlaylistChipLabel(lib, l)
- : _queueMode == 'auto_next'
- ? (_mergeLibraries ? l.queueModeAuto : lib.isPodcastLibrary ? l.queueModeShowLabel : l.queueModeSeriesLabel)
- : l.queueModeManual,
+ : _queueMode == 'collection'
+ ? _activeCollectionChipLabel()
+ : _queueMode == 'auto_next'
+ ? (_mergeLibraries ? l.queueModeAuto : lib.isPodcastLibrary ? l.queueModeShowLabel : l.queueModeSeriesLabel)
+ : l.queueModeManual,
style: TextStyle(fontSize: 10, fontWeight: FontWeight.w600, color: cs.primary),
),
],
@@ -1096,6 +1110,9 @@ class _ReorderAbsorbingSheetState extends State<_ReorderAbsorbingSheet> {
List<Map<String, dynamic>>? _playlistItems;
String? _playlistId;
String? _playlistName;
+ List<Map<String, dynamic>>? _collectionBooks;
+ String? _collectionId;
+ String? _collectionName;
// Podcast auto_next: the current show's episodes (unsorted - the list sorts
// by _podcastAdvanceDir at build so flipping the toggle reorders live).
List<Map<String, dynamic>>? _showEpisodes;
@@ -1114,6 +1131,8 @@ class _ReorderAbsorbingSheetState extends State<_ReorderAbsorbingSheet> {
}
} else if (_queueMode == 'playlist') {
await _loadPlaylistContent();
+ } else if (_queueMode == 'collection') {
+ await _loadCollectionContent();
}
}
@@ -1192,6 +1211,21 @@ class _ReorderAbsorbingSheetState extends State<_ReorderAbsorbingSheet> {
});
}
+ Future<void> _loadCollectionContent() async {
+ final cid = await PlayerSettings.getQueueCollectionId();
+ if (cid == null) return;
+ final c = await widget.lib.fetchCollectionById(cid);
+ if (!mounted || c == null) return;
+ final books = ((c['books'] as List<dynamic>?) ?? const [])
+ .whereType<Map<String, dynamic>>()
+ .toList();
+ setState(() {
+ _collectionBooks = books;
+ _collectionId = cid;
+ _collectionName = c['name'] as String?;
+ });
+ }
+
@override
void dispose() {
PlayerSettings.settingsChanged.removeListener(_refreshMode);
@@ -1204,6 +1238,8 @@ class _ReorderAbsorbingSheetState extends State<_ReorderAbsorbingSheet> {
String mode;
if (bm == 'playlist' || pm == 'playlist') {
mode = 'playlist';
+ } else if (bm == 'collection') {
+ mode = 'collection';
} else if (widget.isMerged) {
const order = ['off', 'manual', 'auto_next'];
final bi = order.indexOf(bm);
@@ -1265,6 +1301,10 @@ class _ReorderAbsorbingSheetState extends State<_ReorderAbsorbingSheet> {
ButtonSegment(value: 'auto_next', icon: const Icon(Icons.skip_next_rounded, size: 16),
label: FittedBox(fit: BoxFit.scaleDown, child: Text(widget.isMerged ? l.queueModeAuto : widget.isPodcast ? l.queueModeShowLabel : l.queueModeSeriesLabel, maxLines: 1))),
ButtonSegment(value: 'playlist', icon: const Icon(Icons.playlist_play_rounded, size: 16), label: FittedBox(fit: BoxFit.scaleDown, child: Text(l.queueModePlaylist, maxLines: 1))),
+ // Collection mode is entered via a collection's Play button, not
+ // picked here - shown only while active so the selection is valid.
+ if (_queueMode == 'collection')
+ ButtonSegment(value: 'collection', icon: const Icon(Icons.collections_bookmark_rounded, size: 16), label: FittedBox(fit: BoxFit.scaleDown, child: const Text('Collection', maxLines: 1))),
],
selected: {_queueMode},
onSelectionChanged: (v) {
@@ -1364,6 +1404,18 @@ class _ReorderAbsorbingSheetState extends State<_ReorderAbsorbingSheet> {
PlaylistDetailSheet.show(outer, _playlistId!);
},
),
+ if (_queueMode == 'collection' && _collectionId != null)
+ _modeHeaderButton(
+ cs, tt,
+ label: 'Open collection',
+ subtitle: _collectionName,
+ icon: Icons.collections_bookmark_rounded,
+ onTap: () {
+ final outer = rootNavigatorKey.currentContext ?? context;
+ Navigator.pop(context);
+ CollectionDetailSheet.show(outer, _collectionId!);
+ },
+ ),
Expanded(
child: _buildQueueList(cs, tt, l, bottomInset),
),
@@ -1430,9 +1482,37 @@ class _ReorderAbsorbingSheetState extends State<_ReorderAbsorbingSheet> {
if (_queueMode == 'playlist') {
return _buildPlaylistList(cs, tt, l, bottomInset);
}
+ if (_queueMode == 'collection') {
+ return _buildCollectionList(cs, tt, l, bottomInset);
+ }
return _buildManualList(cs, tt, l, bottomInset);
}
+ Widget _buildCollectionList(ColorScheme cs, TextTheme tt, AppLocalizations l, double bottomInset) {
+ final books = _collectionBooks;
+ if (books == null) {
+ return const Center(child: CircularProgressIndicator(strokeWidth: 2));
+ }
+ if (books.isEmpty) {
+ return Center(
+ child: Padding(
+ padding: const EdgeInsets.all(24),
+ child: Text(l.absorbingNothingAbsorbingYet,
+ style: tt.bodyMedium?.copyWith(color: cs.onSurfaceVariant)),
+ ),
+ );
+ }
+ return ListView.builder(
+ padding: EdgeInsets.only(bottom: bottomInset + 16),
+ itemCount: books.length,
+ itemBuilder: (context, i) {
+ final book = books[i];
+ final id = book['id'] as String? ?? '';
+ return _readOnlyQueueItem(cs, tt, l, key: id, book: book, index: i);
+ },
+ );
+ }
+
Widget _buildShowEpisodesList(ColorScheme cs, TextTheme tt, AppLocalizations l, double bottomInset) {
final eps = _showEpisodes;
if (eps == null) {
diff --git a/lib/screens/library_screen.dart b/lib/screens/library_screen.dart
index aadb5562..86e39590 100644
--- a/lib/screens/library_screen.dart
+++ b/lib/screens/library_screen.dart
@@ -149,6 +149,8 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
// switch - playlists are per-user, so switching accounts must drop the old
// user's lists.
String? _listsLoadedKey;
+ Future<void>? _listsLoadFuture;
+ String? _listsLoadingKey;
// When a collection/playlist is open the Library grid shows its items in
// place, like a filter. null = normal library.
String? _scopeId;
@@ -1204,15 +1206,26 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
// ── Collections / Playlists ──
- Future<void> _loadLists() async {
+ /// Loads the current library+account's collections/playlists. Returns the
+ /// in-flight load so callers (the sort sheet) can await it - that's what
+ /// makes the Lists tab show on first open instead of after a reopen.
+ Future<void> _loadLists() {
final lib = context.read<LibraryProvider>();
final api = context.read<AuthProvider>().apiService;
final libId = lib.selectedLibraryId;
- if (api == null || libId == null) return;
+ if (api == null || libId == null) return Future.value();
final key = '${UserAccountService().activeScopeKey}|$libId';
- if (_listsLoadedKey == key) return;
- // Library or account changed: drop the previous lists + any open scope
- // before loading the new ones. Mark the key now so concurrent calls dedupe.
+ if (_listsLoadingKey == key && _listsLoadFuture != null) return _listsLoadFuture!;
+ if (_listsLoadedKey == key) return Future.value();
+ _listsLoadingKey = key;
+ final f = _fetchLists(key, api, libId);
+ _listsLoadFuture = f;
+ return f;
+ }
+
+ Future<void> _fetchLists(String key, ApiService api, String libId) async {
+ // New key (library/account changed) or first load: drop the previous
+ // lists + any open scope before fetching the new ones.
setState(() {
_collections = [];
_playlists = [];
@@ -1221,17 +1234,21 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
_scopeName = null;
_scopeItems = [];
}
- _listsLoadedKey = key;
- });
- final results = await Future.wait([
- api.getLibraryCollections(libId),
- api.getLibraryPlaylists(libId),
- ]);
- if (!mounted || _listsLoadedKey != key) return;
- setState(() {
- _collections = results[0].whereType<Map<String, dynamic>>().toList();
- _playlists = results[1].whereType<Map<String, dynamic>>().toList();
});
+ try {
+ final results = await Future.wait([
+ api.getLibraryCollections(libId),
+ api.getLibraryPlaylists(libId),
+ ]);
+ if (!mounted || _listsLoadingKey != key) return;
+ setState(() {
+ _collections = results[0].whereType<Map<String, dynamic>>().toList();
+ _playlists = results[1].whereType<Map<String, dynamic>>().toList();
+ _listsLoadedKey = key;
+ });
+ } finally {
+ if (_listsLoadingKey == key) _listsLoadFuture = null;
+ }
}
void _openCollection(Map<String, dynamic> c) {
@@ -1276,11 +1293,20 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
Future<void> _playScope() async {
final id = _scopeId;
- if (!_scopeIsPlaylist || id == null) return;
+ if (id == null) return;
final lib = context.read<LibraryProvider>();
- await PlayerSettings.setQueueModePlaylist(id);
- await lib.playPlaylistFromStart(id);
+ final isPlaylist = _scopeIsPlaylist;
+ final name = _scopeName ?? '';
+ // Jump to the player first - it shows its own loading state - so the tap
+ // gives instant feedback instead of a dead pause while the list loads.
AppShell.goToAbsorbingGlobal();
+ if (isPlaylist) {
+ await PlayerSettings.setQueueModePlaylist(id);
+ await lib.playPlaylistFromStart(id);
+ } else {
+ await PlayerSettings.setQueueModeCollection(id, name);
+ await lib.playCollectionFromStart(id);
+ }
}
// ── Search ──
@@ -1503,8 +1529,10 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
LibraryFilter.none => '',
};
- void _showSortFilterSheet(BuildContext context, ColorScheme cs, TextTheme tt, {int initialTab = 0}) {
- _loadLists();
+ Future<void> _showSortFilterSheet(BuildContext context, ColorScheme cs, TextTheme tt, {int initialTab = 0}) async {
+ // Await the load so the Lists tab appears on the first open, not after a reopen.
+ await _loadLists();
+ if (!mounted) return;
final LibraryTab tab;
final LibrarySort currentSort;
final bool currentSortAsc;
@@ -2113,24 +2141,22 @@ class LibraryScreenState extends State<LibraryScreen> with TickerProviderStateMi
),
),
),
- if (_scopeIsPlaylist) ...[
- const SizedBox(width: 8),
- GestureDetector(
- onTap: _playScope,
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
- decoration: BoxDecoration(
- color: cs.primary.withValues(alpha: 0.12),
- borderRadius: BorderRadius.circular(20),
- ),
- child: Row(mainAxisSize: MainAxisSize.min, children: [
- Icon(Icons.play_arrow_rounded, size: 14, color: cs.primary),
- const SizedBox(width: 4),
- Text(l.playlistPlayAction, style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: cs.primary)),
- ]),
+ const SizedBox(width: 8),
+ GestureDetector(
+ onTap: _playScope,
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
+ decoration: BoxDecoration(
+ color: cs.primary.withValues(alpha: 0.12),
+ borderRadius: BorderRadius.circular(20),
),
+ child: Row(mainAxisSize: MainAxisSize.min, children: [
+ Icon(Icons.play_arrow_rounded, size: 14, color: cs.primary),
+ const SizedBox(width: 4),
+ Text(l.playlistPlayAction, style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: cs.primary)),
+ ]),
),
- ],
+ ),
],
if (_currentTab == 0 && _filter != LibraryFilter.none && !_isScoped) ...[
GestureDetector(
diff --git a/lib/services/backup_service.dart b/lib/services/backup_service.dart
index 5336ba57..629bf77f 100644
--- a/lib/services/backup_service.dart
+++ b/lib/services/backup_service.dart
@@ -99,6 +99,8 @@ class BackupService {
'language': await PlayerSettings.getLanguage(),
'showUpNextLabel': await PlayerSettings.getShowUpNextLabel(),
'queuePlaylistId': await PlayerSettings.getQueuePlaylistId(),
+ 'queueCollectionId': await PlayerSettings.getQueueCollectionId(),
+ 'queueCollectionName': await PlayerSettings.getQueueCollectionName(),
'coverSeedColor': await PlayerSettings.getCoverSeedColor(),
'speedPresets': await PlayerSettings.getSpeedPresets(),
'cardBackground': await PlayerSettings.getCardBackground(),
@@ -452,6 +454,8 @@ class BackupService {
if (s['language'] != null) await PlayerSettings.setLanguage(s['language'] as String);
if (s['showUpNextLabel'] != null) await PlayerSettings.setShowUpNextLabel(s['showUpNextLabel'] as bool);
if (s['queuePlaylistId'] != null) await PlayerSettings.setQueuePlaylistId(s['queuePlaylistId'] as String?);
+ if (s['queueCollectionId'] != null) await ScopedPrefs.setString('queueCollectionId', s['queueCollectionId'] as String);
+ if (s['queueCollectionName'] != null) await ScopedPrefs.setString('queueCollectionName', s['queueCollectionName'] as String);
if (s['coverSeedColor'] != null) await PlayerSettings.setCoverSeedColor(s['coverSeedColor'] as int);
if (s['speedPresets'] is List) {
await PlayerSettings.setSpeedPresets((s['speedPresets'] as List).map((e) => (e as num).toDouble()).toList());
diff --git a/lib/services/player_settings.dart b/lib/services/player_settings.dart
index c9a6028d..c62e5cf7 100644
--- a/lib/services/player_settings.dart
+++ b/lib/services/player_settings.dart
@@ -268,6 +268,38 @@ class PlayerSettings {
_notify();
}
+ // ── Collection queue mode (books only) ──
+ // Mirrors playlist queue mode but plays through a collection's books. Drives
+ // bookQueueMode = 'collection' + queueCollectionId; the name is stored too so
+ // the now-playing chip needn't fetch the collection.
+
+ static Future<String?> getQueueCollectionId() async {
+ final s = await ScopedPrefs.getString('queueCollectionId');
+ return (s == null || s.isEmpty) ? null : s;
+ }
+
+ static Future<String?> getQueueCollectionName() =>
+ ScopedPrefs.getString('queueCollectionName');
+
+ static Future<void> setQueueModeCollection(String collectionId, String name) async {
+ await ScopedPrefs.setString('bookQueueMode', 'collection');
+ await ScopedPrefs.setString('queueCollectionId', collectionId);
+ await ScopedPrefs.setString('queueCollectionName', name);
+ // Collection mode replaces any active playlist queue.
+ await ScopedPrefs.remove('queuePlaylistId');
+ if ((await ScopedPrefs.getString('podcastQueueMode')) == 'playlist') {
+ await ScopedPrefs.setString('podcastQueueMode', 'off');
+ }
+ _notify();
+ }
+
+ static Future<void> clearQueueModeCollection() async {
+ await ScopedPrefs.setString('bookQueueMode', 'off');
+ await ScopedPrefs.remove('queueCollectionId');
+ await ScopedPrefs.remove('queueCollectionName');
+ _notify();
+ }
+
/// One-time migration from the old boolean auto-play settings to queueMode.
static Future<void> migrateQueueMode() async {
if (await ScopedPrefs.containsKey('queueMode')) return;
diff --git a/lib/widgets/collection_detail_sheet.dart b/lib/widgets/collection_detail_sheet.dart
index 493ea5eb..fec2dd3d 100644
--- a/lib/widgets/collection_detail_sheet.dart
+++ b/lib/widgets/collection_detail_sheet.dart
@@ -12,6 +12,7 @@ import '../services/audio_player_service.dart';
import '../services/download_service.dart';
import 'book_detail_sheet.dart';
import 'stackable_sheet.dart';
+import '../screens/app_shell.dart';
class CollectionDetailSheet extends StatefulWidget {
final String collectionId;
@@ -207,6 +208,8 @@ class _CollectionDetailSheetState extends State<CollectionDetailSheet> {
const SizedBox(height: 12),
Divider(height: 1, color: cs.outlineVariant.withValues(alpha: 0.3),
indent: 20, endIndent: 20),
+ if (!_reordering)
+ _buildPlayButton(cs, lib, books, name, l),
// Content
Expanded(
child: _reordering
@@ -218,6 +221,41 @@ class _CollectionDetailSheetState extends State<CollectionDetailSheet> {
]);
}
+ Widget _buildPlayButton(ColorScheme cs, LibraryProvider lib, List<dynamic> books, String name, AppLocalizations l) {
+ int firstIdx = -1;
+ for (var i = 0; i < books.length; i++) {
+ final b = books[i];
+ if (b is! Map<String, dynamic>) continue;
+ final id = b['id'] as String? ?? '';
+ if (id.isEmpty) continue;
+ if (!lib.isItemFinishedByKey(id)) { firstIdx = i; break; }
+ }
+ final allFinished = books.isNotEmpty && firstIdx < 0;
+ final enabled = books.isNotEmpty && firstIdx >= 0;
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(20, 12, 20, 4),
+ child: SizedBox(
+ width: double.infinity,
+ child: FilledButton.icon(
+ onPressed: enabled
+ ? () async {
+ HapticFeedback.selectionClick();
+ final id = widget.collectionId;
+ Navigator.pop(context);
+ AppShell.goToAbsorbingGlobal();
+ await PlayerSettings.setQueueModeCollection(id, name);
+ await lib.playCollectionFromStart(id);
+ }
+ : null,
+ icon: Icon(allFinished
+ ? Icons.check_circle_outline_rounded
+ : Icons.play_arrow_rounded),
+ label: Text(allFinished ? l.playlistAllFinished : l.playlistPlayAction),
+ ),
+ ),
+ );
+ }
+
Widget _buildReorderList(ColorScheme cs, TextTheme tt, LibraryProvider lib, AppLocalizations l) {
final items = _reorderItems!;
return ReorderableListView.builder(