Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix absorbing card order not persisting across plays

Nathan Poulsoneb935d6c3d01
diff --git a/lib/providers/library_provider.dart b/lib/providers/library_provider.dart
index d7d71d8b..7d10790b 100644
--- a/lib/providers/library_provider.dart
+++ b/lib/providers/library_provider.dart
@@ -844,6 +844,16 @@ class LibraryProvider extends ChangeNotifier {
Set<String> get manualAbsorbRemoves => _manualAbsorbRemoves;
List<String> get absorbingBookIds => _absorbingBookIds;
+ /// Move an existing absorbing key to the front and persist.
+ /// No-op if the key isn't in the list or is already first.
+ void moveAbsorbingToFront(String key) {
+ if (!_absorbingBookIds.contains(key)) return;
+ if (_absorbingBookIds.first == key) return;
+ _absorbingBookIds.remove(key);
+ _absorbingBookIds.insert(0, key);
+ _saveManualAbsorbing();
+ }
+
/// Add a key to _absorbingBookIds if not already present.
/// If [afterKey] is provided and exists, insert right after it —
/// and reposition the key if it's already in the list elsewhere.
diff --git a/lib/screens/absorbing_screen.dart b/lib/screens/absorbing_screen.dart
index c6b0661e..49628284 100644
--- a/lib/screens/absorbing_screen.dart
+++ b/lib/screens/absorbing_screen.dart
@@ -105,6 +105,10 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
? (_pageController.page ?? 0).round()
: 0;
_suppressReorder = currentPage > 0;
+ if (!_suppressReorder) {
+ // No animation needed — persist the move-to-front immediately.
+ lib.moveAbsorbingToFront(playingKey);
+ }
WidgetsBinding.instance.addPostFrameCallback((_) => _scrollToActiveCard());
} else if (wasPlayingId != null && !_isSyncing) {
// Playback stopped — keep this item at the front of the list.
@@ -175,6 +179,11 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
.then((_) {
if (!mounted) return;
_suppressReorder = false;
+ // Persist the played item at front so subsequent plays
+ // maintain the correct order instead of reverting.
+ if (playingKey != null) {
+ context.read<LibraryProvider>().moveAbsorbingToFront(playingKey);
+ }
setState(() {});
});
} else {