Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix offline downloaded-podcast access

Nathan Poulson9f7574b95157
diff --git a/lib/providers/_lp_core.dart b/lib/providers/_lp_core.dart
index b43bc6bd..84bbf8ed 100644
--- a/lib/providers/_lp_core.dart
+++ b/lib/providers/_lp_core.dart
@@ -262,6 +262,8 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {
'recentEpisode': {
'id': episodeId,
'title': episodeTitle ?? dl.title ?? 'Episode',
+ 'duration': duration,
+ 'chapters': chapters,
},
'media': {
'metadata': {
@@ -363,6 +365,8 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {
'recentEpisode': {
'id': episodeId,
'title': episodeTitle ?? dl.title ?? 'Episode',
+ 'duration': duration,
+ 'chapters': chapters,
},
'media': {
'metadata': {
diff --git a/lib/screens/absorbing_screen.dart b/lib/screens/absorbing_screen.dart
index 15aed5de..35c438ad 100644
--- a/lib/screens/absorbing_screen.dart
+++ b/lib/screens/absorbing_screen.dart
@@ -368,6 +368,29 @@ class _AbsorbingScreenState extends State<AbsorbingScreen> {
skippedKeys[key] = 'not in section or cache';
}
}
+ // Offline-only fallback: surface all downloads that aren't already in the
+ // absorbing list. Online we keep Absorbing focused on started/queued items;
+ // offline the user has no other way to reach unstarted downloads, so we
+ // merge them in. Started ones already appear via the absorbingBookIds path.
+ if (lib.isOffline) {
+ final seenKeys = items.map(_absorbingKey).toSet();
+ for (final section in lib.personalizedSections) {
+ if ((section['id'] as String?) != 'downloaded-books') continue;
+ for (final e in (section['entities'] as List<dynamic>? ?? [])) {
+ if (e is! Map<String, dynamic>) continue;
+ final itemId = e['id'] as String?;
+ if (itemId == null) continue;
+ final re = e['recentEpisode'] as Map<String, dynamic>?;
+ final epId = re?['id'] as String?;
+ final key = epId != null ? '$itemId-$epId' : itemId;
+ if (seenKeys.contains(key)) continue;
+ if (removes.contains(key)) continue;
+ items.add(e);
+ seenKeys.add(key);
+ }
+ }
+ }
+
// If the currently playing/casting item isn't in the list, add it at the front.
// For podcast episodes, match by compound key.
// Skip if the playing item belongs to a different library type.
diff --git a/lib/widgets/section_detail_sheet.dart b/lib/widgets/section_detail_sheet.dart
index f44dac49..9183ced7 100644
--- a/lib/widgets/section_detail_sheet.dart
+++ b/lib/widgets/section_detail_sheet.dart
@@ -8,9 +8,24 @@ import '../providers/library_provider.dart';
import '../services/audio_player_service.dart';
import '../services/download_service.dart';
import 'book_detail_sheet.dart';
+import 'episode_detail_sheet.dart';
import 'overlay_toast.dart';
import 'stackable_sheet.dart';
+/// Open the right detail sheet for a section entity: episode detail for
+/// podcast entries (which carry a `recentEpisode`), book detail otherwise.
+/// Falls back to book detail if a podcast entry is missing its episode payload.
+void _openEntityDetail(BuildContext context, Map<String, dynamic> item) {
+ final recentEpisode = item['recentEpisode'] as Map<String, dynamic>?;
+ if (recentEpisode != null) {
+ EpisodeDetailSheet.show(context, item, recentEpisode);
+ return;
+ }
+ final itemId = item['id'] as String? ?? '';
+ if (itemId.isEmpty) return;
+ showBookDetailSheet(context, itemId);
+}
+
/// Generic detail sheet for any home screen section (Continue Listening,
/// Recently Added, Downloads, etc.). Shows items in a list or 3-column grid
/// with progress bars, saved/done badges, and explicit badges.
@@ -145,7 +160,7 @@ class _SectionDetailSheetState extends State<SectionDetailSheet> {
borderRadius: BorderRadius.circular(14)),
clipBehavior: Clip.antiAlias,
child: InkWell(
- onTap: () => showBookDetailSheet(context, itemId),
+ onTap: () => _openEntityDetail(context, item),
borderRadius: BorderRadius.circular(14),
child: SizedBox(
height: 112,
@@ -254,7 +269,7 @@ class _SectionDetailSheetState extends State<SectionDetailSheet> {
final isDownloaded = DownloadService().isDownloaded(itemId);
return GestureDetector(
- onTap: () => showBookDetailSheet(context, itemId),
+ onTap: () => _openEntityDetail(context, item),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [