A cross platform Audiobookshelf client for Android and iOS
Dart
Episode finished/progress badges, persist subscription episode IDs
Nathan Poulsond346451de192
diff --git a/lib/providers/library_provider.dart b/lib/providers/library_provider.dartindex d0f8076f..c87086b9 100644--- a/lib/providers/library_provider.dart+++ b/lib/providers/library_provider.dart@@ -144,13 +144,16 @@ class LibraryProvider extends ChangeNotifier {.whereType<String>().toSet();_knownEpisodeIds[podcastId] = ids;+ _saveKnownEpisodeIds(podcastId);}notifyListeners();}Future<void> unsubscribePodcast(String podcastId) async {_subscribedPodcasts.remove(podcastId);+ _knownEpisodeIds.remove(podcastId);await _saveSubscribedPodcasts();+ await ScopedPrefs.remove('known_episodes_$podcastId');notifyListeners();}@@ -604,9 +607,10 @@ class LibraryProvider extends ChangeNotifier {_loadManualAbsorbing();await _loadRollingDownloadSeries();await _loadSubscribedPodcasts();- // Seed episode counts in the background so first socket update- // doesn't treat all existing episodes as new.- Future.microtask(() => seedSubscribedPodcastCounts());+ await _loadKnownEpisodeIds();+ // Check subscribed podcasts for new episodes added while app was closed,+ // and seed counts so socket updates can detect future new episodes.+ Future.microtask(() => checkSubscribedPodcasts());// If server was unreachable on startup, force offline mode and pingif (!auth.serverReachable) {@@ -3193,9 +3197,28 @@ class LibraryProvider extends ChangeNotifier {// ── Podcast subscriptions ──/// Track known episode IDs per podcast so we can detect new ones- /// regardless of position or date.+ /// regardless of position or date. Persisted so episodes added while+ /// the app was closed are detected on next startup.final Map<String, Set<String>> _knownEpisodeIds = {};+ Future<void> _loadKnownEpisodeIds() async {+ for (final podcastId in _subscribedPodcasts) {+ final ids = await ScopedPrefs.getStringList('known_episodes_$podcastId');+ if (ids.isNotEmpty) {+ _knownEpisodeIds[podcastId] = ids.toSet();+ }+ }+ }++ Future<void> _saveKnownEpisodeIds(String podcastId) async {+ final ids = _knownEpisodeIds[podcastId];+ if (ids != null) {+ await ScopedPrefs.setStringList('known_episodes_$podcastId', ids.toList());+ } else {+ await ScopedPrefs.remove('known_episodes_$podcastId');+ }+ }+/// Called when a library item is updated via socket. If it's a subscribed/// podcast with more episodes than we last knew about, auto-download and/// queue the new ones.@@ -3231,6 +3254,8 @@ class LibraryProvider extends ChangeNotifier {.whereType<String>().toSet();_knownEpisodeIds[itemId] = ids;+ _saveKnownEpisodeIds(itemId);+ debugPrint('[Subscription] Seeded $itemId with ${ids.length} episodes');return;}@@ -3269,6 +3294,7 @@ class LibraryProvider extends ChangeNotifier {}if (queued > 0) {+ _saveKnownEpisodeIds(itemId);_saveManualAbsorbing();notifyListeners();_downloadSubscribedEpisodes(itemId);@@ -3276,25 +3302,15 @@ class LibraryProvider extends ChangeNotifier {}}- /// Seed known episode IDs for subscribed podcasts so the first- /// socket update doesn't treat all existing episodes as new.- Future<void> seedSubscribedPodcastCounts() async {+ /// Check subscribed podcasts for new episodes (added while app was closed)+ /// and seed known IDs for future socket-based detection.+ Future<void> checkSubscribedPodcasts() async {if (_subscribedPodcasts.isEmpty || _api == null) return;for (final podcastId in _subscribedPodcasts) {- if (_knownEpisodeIds.containsKey(podcastId)) continue;try {- final item = await _api!.getLibraryItem(podcastId);- if (item == null) continue;- final media = item['media'] as Map<String, dynamic>? ?? {};- final episodes = media['episodes'] as List<dynamic>? ?? [];- final ids = episodes- .map((e) => (e as Map<String, dynamic>)['id'] as String?)- .whereType<String>()- .toSet();- _knownEpisodeIds[podcastId] = ids;- debugPrint('[Subscription] Seeded $podcastId with ${ids.length} episodes');+ await _fetchAndCheckSubscribedPodcast(podcastId);} catch (e) {- debugPrint('[Subscription] Failed to seed $podcastId: $e');+ debugPrint('[Subscription] Failed to check $podcastId: $e');}}}diff --git a/lib/widgets/home_section.dart b/lib/widgets/home_section.dartindex a404c9fd..83974d83 100644--- a/lib/widgets/home_section.dart+++ b/lib/widgets/home_section.dart@@ -2,6 +2,7 @@ import 'dart:io';import 'package:flutter/material.dart';import 'package:provider/provider.dart';import '../providers/library_provider.dart';+import '../services/download_service.dart';import 'book_card.dart';import 'author_card.dart';import 'series_card.dart';@@ -259,6 +260,10 @@ class _EpisodeCard extends StatelessWidget {// Get episode info from recentEpisodefinal episode = item['recentEpisode'] as Map<String, dynamic>?;final episodeTitle = episode?['title'] as String? ?? showTitle;+ final episodeId = episode?['id'] as String?;+ final progress = episodeId != null ? lib.getEpisodeProgress(itemId, episodeId) : 0.0;+ final isFinished = episodeId != null && lib.getEpisodeProgressData(itemId, episodeId)?['isFinished'] == true;+ final isDownloaded = episodeId != null && DownloadService().isDownloaded('$itemId-$episodeId');return GestureDetector(onTap: () {@@ -305,6 +310,67 @@ class _EpisodeCard extends StatelessWidget {child: Icon(Icons.podcasts_rounded, size: 32,color: cs.onSurfaceVariant.withValues(alpha: 0.3)),),+ // Progress bar+ if (progress > 0 && !isFinished)+ Positioned(+ left: 0, right: 0, bottom: 0,+ child: ClipRRect(+ borderRadius: const BorderRadius.vertical(bottom: Radius.circular(12)),+ child: LinearProgressIndicator(+ value: progress.clamp(0, 1),+ minHeight: 3,+ backgroundColor: Colors.transparent,+ valueColor: AlwaysStoppedAnimation(cs.primary),+ ),+ ),+ ),+ // Finished / downloaded badge+ if (isFinished || isDownloaded)+ Positioned(+ left: 0, right: 0, bottom: 0,+ child: Container(+ padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),+ decoration: BoxDecoration(+ borderRadius: const BorderRadius.vertical(bottom: Radius.circular(12)),+ gradient: LinearGradient(+ begin: Alignment.bottomCenter,+ end: Alignment.topCenter,+ colors: [+ Colors.black.withValues(alpha: 0.85),+ Colors.black.withValues(alpha: 0.0),+ ],+ ),+ ),+ child: Row(+ mainAxisAlignment: MainAxisAlignment.center,+ mainAxisSize: MainAxisSize.min,+ children: [+ if (isFinished) ...[+ Icon(Icons.check_circle_rounded,+ size: 10, color: Theme.of(context).brightness == Brightness.dark ? Colors.greenAccent[400] : Colors.green.shade700),+ const SizedBox(width: 3),+ Text('Done',+ style: TextStyle(+ fontSize: 9,+ fontWeight: FontWeight.w600,+ color: Theme.of(context).brightness == Brightness.dark ? Colors.greenAccent[400] : Colors.green.shade700)),+ ],+ if (isFinished && isDownloaded)+ const SizedBox(width: 6),+ if (isDownloaded) ...[+ Icon(Icons.download_done_rounded,+ size: 10, color: cs.primary),+ const SizedBox(width: 3),+ Text('Saved',+ style: TextStyle(+ fontSize: 9,+ fontWeight: FontWeight.w600,+ color: cs.primary)),+ ],+ ],+ ),+ ),+ ),// Subscribed bellif (isSubscribed)Positioned(