A cross platform Audiobookshelf client for Android and iOS
Dart
Keep new podcast episodes at the top of the queue when set to the beginning
Barnabas054237b21f91
diff --git a/lib/providers/_lp_absorbing.dart b/lib/providers/_lp_absorbing.dartindex 0734a291..15ee0bf5 100644--- a/lib/providers/_lp_absorbing.dart+++ b/lib/providers/_lp_absorbing.dart@@ -14,12 +14,27 @@ mixin _AbsorbingMixin on ChangeNotifier, _StateMixin, _CoreMixin {void moveAbsorbingToFront(String key) {if (!_absorbingBookIds.contains(key)) return;+ // The user engaged with the queue, so the "keep a fresh episode on top"+ // protection has done its job - drop it.+ setFreshQueuedFront(null);if (_absorbingBookIds.first == key) return;_absorbingBookIds.remove(key);_absorbingBookIds.insert(0, key);_saveManualAbsorbing();}+ /// Mark (or clear) the just-arrived subscribed episode that should stay at the+ /// top of the queue. Persisted so it survives an app kill.+ void setFreshQueuedFront(String? key) {+ if (_freshQueuedFrontKey == key) return;+ _freshQueuedFrontKey = key;+ if (key == null) {+ ScopedPrefs.remove('absorbing_fresh_front');+ } else {+ ScopedPrefs.setString('absorbing_fresh_front', key);+ }+ }+Future<void> _loadManualAbsorbing() async {_manualAbsorbAdds =(await ScopedPrefs.getStringList('absorbing_manual_adds')).toSet();@@ -27,6 +42,8 @@ mixin _AbsorbingMixin on ChangeNotifier, _StateMixin, _CoreMixin {(await ScopedPrefs.getStringList('absorbing_manual_removes')).toSet();_absorbingBookIds =(await ScopedPrefs.getStringList('absorbing_seen_ids')).toList();+ final fresh = await ScopedPrefs.getString('absorbing_fresh_front');+ _freshQueuedFrontKey = (fresh != null && fresh.isNotEmpty) ? fresh : null;final cacheList =await ScopedPrefs.getStringList('absorbing_item_cache_v2');_absorbingItemCache = {};@@ -321,6 +338,7 @@ mixin _AbsorbingMixin on ChangeNotifier, _StateMixin, _CoreMixin {Future<void> reorderAbsorbing(List<String> newOrder) async {_absorbingBookIds = newOrder;+ setFreshQueuedFront(null);await _saveManualAbsorbing();notifyListeners();_catchUpQueueAutoDownloads();diff --git a/lib/providers/_lp_core.dart b/lib/providers/_lp_core.dartindex d79d3a05..01d5dd8d 100644--- a/lib/providers/_lp_core.dart+++ b/lib/providers/_lp_core.dart@@ -1901,6 +1901,10 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {// extremes and read correctly in both modes, so they need no adjustment.final merged = await PlayerSettings.getMergeAbsorbingLibraries();final libId = item['libraryId'] as String?;+ // For 'start', remember the front-most new episode so the absorbing+ // screen's keep-on-top pins yield to it (otherwise a paused/last-finished+ // item gets pulled above it and it shows 2nd).+ String? startFrontKey;for (final epMap in newEpisodes) {final epId = epMap['id'] as String;@@ -1921,6 +1925,7 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {break;default:_absorbingIdsAdd(key, atFront: true);+ startFrontKey = key;}_absorbingItemCache[key] = {'id': itemId,@@ -1937,6 +1942,9 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {}if (queued > 0) {+ if (startFrontKey != null) {+ (this as _AbsorbingMixin).setFreshQueuedFront(startFrontKey);+ }_saveKnownEpisodeIds(itemId);(this as _AbsorbingMixin)._saveManualAbsorbing();notifyListeners();diff --git a/lib/providers/_lp_state.dart b/lib/providers/_lp_state.dartindex 0405cf4a..08b6f0a0 100644--- a/lib/providers/_lp_state.dart+++ b/lib/providers/_lp_state.dart@@ -94,6 +94,11 @@ mixin _StateMixin on ChangeNotifier {List<String> _absorbingBookIds = [];Map<String, Map<String, dynamic>> _absorbingItemCache = {};String? _lastFinishedItemId;+ // A just-arrived subscribed-podcast episode the user asked to land at the top+ // of the queue. The absorbing screen's "keep last-finished/playing on top"+ // pins yield to this so a "beginning" episode actually stays first. Persisted+ // so it survives an app kill; cleared once the user plays or reorders.+ String? _freshQueuedFrontKey;final Set<String> _locallyFinishedItems = {};StreamSubscription? _connectivitySub;@@ -125,6 +130,7 @@ mixin _StateMixin on ChangeNotifier {List<String> get absorbingBookIds => _absorbingBookIds;Map<String, Map<String, dynamic>> get absorbingItemCache =>_absorbingItemCache;+ String? get freshQueuedFrontKey => _freshQueuedFrontKey;Map<String, dynamic>? get selectedLibrary {if (_selectedLibraryId == null) return null;diff --git a/lib/screens/absorbing_screen.dart b/lib/screens/absorbing_screen.dartindex 265cbf03..014bbefa 100644--- a/lib/screens/absorbing_screen.dart+++ b/lib/screens/absorbing_screen.dart@@ -506,7 +506,11 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {final activeKey = activeEpId != null ? '$activeId-$activeEpId' : activeId;final existingIdx = items.indexWhere((b) => _absorbingKey(b) == activeKey);- if (!_suppressReorder && existingIdx > 0) {+ // Only pull the active item to the top while it's actually playing.+ // When paused, leave the queue order alone so a freshly-queued+ // "beginning" episode stays first instead of being bumped to 2nd.+ final activePlaying = _player.hasBook ? _player.isPlaying : _cast.isCasting;+ if (!_suppressReorder && existingIdx > 0 && activePlaying) {final item = items.removeAt(existingIdx);items.insert(0, item);} else if (existingIdx < 0) {@@ -542,7 +546,11 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {final finishedIsPodcast = _lastFinishedId!.length > 36;if (_mergeLibraries || finishedIsPodcast == isPod) {final finishedIdx = items.indexWhere((b) => _absorbingKey(b) == _lastFinishedId);- if (finishedIdx > 0) {+ // Don't pull the last-finished item over a brand-new "beginning"+ // episode that's deliberately sitting at the top.+ final freshOnTop = items.isNotEmpty &&+ _absorbingKey(items[0]) == lib.freshQueuedFrontKey;+ if (finishedIdx > 0 && !freshOnTop) {final item = items.removeAt(finishedIdx);items.insert(0, item);}