A cross platform Audiobookshelf client for Android and iOS
Dart
Let you subscribe to a podcast without new episodes filling up Absorbing
Barnabasbaf449d901f7
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arbindex a1f3cfc6..56aabc80 100644--- a/lib/l10n/app_en.arb+++ b/lib/l10n/app_en.arb@@ -3686,10 +3686,20 @@}}},+ "lpSubscribedEpisodeDownloaded": "New {showTitle} episode downloaded",+ "@lpSubscribedEpisodeDownloaded": {+ "placeholders": {+ "showTitle": {+ "type": "String"+ }+ }+ },"episodeListNewEpisodePosition": "New episode position","episodeListPositionTop": "Top of queue","episodeListPositionSecond": "Second in queue","episodeListPositionEnd": "End of queue",+ "episodeListPositionNone": "Don't add to queue",+ "episodeListPositionNoneDesc": "Still notified and downloaded","lpQueueDownloadingItems": "{count, plural, =1{Queue: downloading 1 item} other{Queue: downloading {count} items}}","@lpQueueDownloadingItems": {"placeholders": {diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dartindex ef8b2fb2..721e74aa 100644--- a/lib/l10n/app_localizations.dart+++ b/lib/l10n/app_localizations.dart@@ -10773,6 +10773,12 @@ abstract class AppLocalizations {/// **'{showTitle} added to the end of your queue'**String lpSubscribedEpisodeAddedEnd(String showTitle);+ /// No description provided for @lpSubscribedEpisodeDownloaded.+ ///+ /// In en, this message translates to:+ /// **'New {showTitle} episode downloaded'**+ String lpSubscribedEpisodeDownloaded(String showTitle);+/// No description provided for @episodeListNewEpisodePosition.////// In en, this message translates to:@@ -10797,6 +10803,18 @@ abstract class AppLocalizations {/// **'End of queue'**String get episodeListPositionEnd;+ /// No description provided for @episodeListPositionNone.+ ///+ /// In en, this message translates to:+ /// **'Don\'t add to queue'**+ String get episodeListPositionNone;++ /// No description provided for @episodeListPositionNoneDesc.+ ///+ /// In en, this message translates to:+ /// **'Still notified and downloaded'**+ String get episodeListPositionNoneDesc;+/// No description provided for @lpQueueDownloadingItems.////// In en, this message translates to:diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dartindex 0389b141..88023591 100644--- a/lib/l10n/app_localizations_de.dart+++ b/lib/l10n/app_localizations_de.dart@@ -6260,6 +6260,11 @@ class AppLocalizationsDe extends AppLocalizations {return '$showTitle an das Ende deiner Warteschlange hinzugefügt';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'Position neuer Folgen';@@ -6272,6 +6277,12 @@ class AppLocalizationsDe extends AppLocalizations {@overrideString get episodeListPositionEnd => 'Ende der Warteschlange';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dartindex fe6cea0c..4528a1d9 100644--- a/lib/l10n/app_localizations_el.dart+++ b/lib/l10n/app_localizations_el.dart@@ -6178,6 +6178,11 @@ class AppLocalizationsEl extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6190,6 +6195,12 @@ class AppLocalizationsEl extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dartindex b57f1a3c..7221c237 100644--- a/lib/l10n/app_localizations_en.dart+++ b/lib/l10n/app_localizations_en.dart@@ -6178,6 +6178,11 @@ class AppLocalizationsEn extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6190,6 +6195,12 @@ class AppLocalizationsEn extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dartindex 81ae0340..60cc12d1 100644--- a/lib/l10n/app_localizations_es.dart+++ b/lib/l10n/app_localizations_es.dart@@ -6180,6 +6180,11 @@ class AppLocalizationsEs extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6192,6 +6197,12 @@ class AppLocalizationsEs extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dartindex 577c77cd..55d0d365 100644--- a/lib/l10n/app_localizations_fr.dart+++ b/lib/l10n/app_localizations_fr.dart@@ -6198,6 +6198,11 @@ class AppLocalizationsFr extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6210,6 +6215,12 @@ class AppLocalizationsFr extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dartindex 1151a969..7c6f2f5a 100644--- a/lib/l10n/app_localizations_it.dart+++ b/lib/l10n/app_localizations_it.dart@@ -6178,6 +6178,11 @@ class AppLocalizationsIt extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6190,6 +6195,12 @@ class AppLocalizationsIt extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dartindex 11726227..e6aa8e7b 100644--- a/lib/l10n/app_localizations_ja.dart+++ b/lib/l10n/app_localizations_ja.dart@@ -6178,6 +6178,11 @@ class AppLocalizationsJa extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6190,6 +6195,12 @@ class AppLocalizationsJa extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dartindex c56b7067..5f20ad66 100644--- a/lib/l10n/app_localizations_no.dart+++ b/lib/l10n/app_localizations_no.dart@@ -6178,6 +6178,11 @@ class AppLocalizationsNo extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6190,6 +6195,12 @@ class AppLocalizationsNo extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dartindex 055b280f..5efa3f1d 100644--- a/lib/l10n/app_localizations_pt.dart+++ b/lib/l10n/app_localizations_pt.dart@@ -6178,6 +6178,11 @@ class AppLocalizationsPt extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6190,6 +6195,12 @@ class AppLocalizationsPt extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dartindex 8d364560..6f95be89 100644--- a/lib/l10n/app_localizations_ro.dart+++ b/lib/l10n/app_localizations_ro.dart@@ -6178,6 +6178,11 @@ class AppLocalizationsRo extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6190,6 +6195,12 @@ class AppLocalizationsRo extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dartindex 2cbd4eda..c02b9059 100644--- a/lib/l10n/app_localizations_ru.dart+++ b/lib/l10n/app_localizations_ru.dart@@ -6182,6 +6182,11 @@ class AppLocalizationsRu extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6194,6 +6199,12 @@ class AppLocalizationsRu extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dartindex dc1cf19c..8f70288f 100644--- a/lib/l10n/app_localizations_zh.dart+++ b/lib/l10n/app_localizations_zh.dart@@ -6089,6 +6089,11 @@ class AppLocalizationsZh extends AppLocalizations {return '$showTitle added to the end of your queue';}+ @override+ String lpSubscribedEpisodeDownloaded(String showTitle) {+ return 'New $showTitle episode downloaded';+ }+@overrideString get episodeListNewEpisodePosition => 'New episode position';@@ -6101,6 +6106,12 @@ class AppLocalizationsZh extends AppLocalizations {@overrideString get episodeListPositionEnd => 'End of queue';+ @override+ String get episodeListPositionNone => 'Don\'t add to queue';++ @override+ String get episodeListPositionNoneDesc => 'Still notified and downloaded';+@overrideString lpQueueDownloadingItems(int count) {String _temp0 = intl.Intl.pluralLogic(diff --git a/lib/providers/_lp_core.dart b/lib/providers/_lp_core.dartindex 5799f116..0b15696d 100644--- a/lib/providers/_lp_core.dart+++ b/lib/providers/_lp_core.dart@@ -2232,8 +2232,17 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {// the same library instead (otherwise an item from another library at// index 0 would push this to visible-first). 'start'/'end' are the list// extremes and read correctly in both modes, so they need no adjustment.+ // 'none' subscribes without queueing: the episode is still detected,+ // notified and downloaded, it just never lands on the absorbing list.+ final queueless = position == 'none';final merged = await PlayerSettings.getMergeAbsorbingLibraries();final libId = item['libraryId'] as String?;+ // The download step normally rediscovers episodes by scanning the+ // absorbing queue, which finds nothing for a queue-less show, so the+ // keys and their metadata have to be carried over explicitly.+ final freshKeys = <String>[];+ final freshMeta = <String, Map<String, dynamic>>{};+ final freshEpIds = <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).@@ -2243,24 +2252,7 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {final epId = epMap['id'] as String;final key = '$itemId-$epId';- switch (position) {- case 'end':- _absorbingIdsAdd(key, atFront: false);- break;- case 'second':- if (merged) {- _absorbingIdsAdd(key, atIndex: 1);- } else {- final firstSameLib = _absorbingBookIds.indexWhere(- (k) => _absorbingItemCache[k]?['libraryId'] == libId);- _absorbingIdsAdd(key, atIndex: firstSameLib >= 0 ? firstSameLib + 1 : 0);- }- break;- default:- _absorbingIdsAdd(key, atFront: true);- startFrontKey = key;- }- _absorbingItemCache[key] = {+ final entry = {'id': itemId,'libraryId': item['libraryId'] as String?,'mediaType': 'podcast',@@ -2268,9 +2260,34 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {'recentEpisode': epMap,'media': media,};- _manualAbsorbAdds.add(key);- _manualAbsorbRemoves.remove(key);- knownIds.add(epId);+ freshKeys.add(key);+ freshMeta[key] = entry;++ if (!queueless) {+ switch (position) {+ case 'end':+ _absorbingIdsAdd(key, atFront: false);+ break;+ case 'second':+ if (merged) {+ _absorbingIdsAdd(key, atIndex: 1);+ } else {+ final firstSameLib = _absorbingBookIds.indexWhere(+ (k) => _absorbingItemCache[k]?['libraryId'] == libId);+ _absorbingIdsAdd(key, atIndex: firstSameLib >= 0 ? firstSameLib + 1 : 0);+ }+ break;+ default:+ _absorbingIdsAdd(key, atFront: true);+ startFrontKey = key;+ }+ // Only cache what the queue will render. A queue-less show would+ // otherwise grow this cache with entries nothing ever reads.+ _absorbingItemCache[key] = entry;+ _manualAbsorbAdds.add(key);+ _manualAbsorbRemoves.remove(key);+ }+ freshEpIds.add(epId);queued++;}@@ -2278,10 +2295,28 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {if (startFrontKey != null) {(this as _AbsorbingMixin).setFreshQueuedFront(startFrontKey);}- _saveKnownEpisodeIds(itemId);- (this as _AbsorbingMixin)._saveManualAbsorbing();- notifyListeners();- _downloadSubscribedEpisodes(itemId);+ if (!queueless) {+ knownIds.addAll(freshEpIds);+ _saveKnownEpisodeIds(itemId);+ (this as _AbsorbingMixin)._saveManualAbsorbing();+ notifyListeners();+ _downloadSubscribedEpisodes(itemId, keys: freshKeys, meta: freshMeta);+ } else {+ // Nothing queue-less lands on the absorbing list, so the catch-up+ // pass has no way to rediscover these. Only mark them seen once the+ // download is actually enqueued - if it was deferred for WiFi,+ // leaving them unseen makes the next check retry instead of losing+ // the episode entirely.+ final started = await _downloadSubscribedEpisodes(itemId,+ keys: freshKeys, meta: freshMeta);+ if (started) {+ knownIds.addAll(freshEpIds);+ _saveKnownEpisodeIds(itemId);+ } else {+ debugPrint('[Subscription] $itemId download deferred - leaving '+ '${freshEpIds.length} episode(s) unseen so the next check retries');+ }+ }}}}@@ -2297,26 +2332,43 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {}}- Future<void> _downloadSubscribedEpisodes(String podcastId) async {- if (_api == null || isOffline) return;+ /// Downloads a subscribed show's episodes. [keys] names the exact episodes+ /// (with [meta] carrying their details); without it the absorbing queue is+ /// scanned instead, which is what the catch-up pass does. A queue-less show+ /// must pass [keys] - its episodes never enter the queue, so a scan would+ /// come back empty and silently download nothing.+ ///+ /// Returns false when it bailed before enqueueing anything (offline, or+ /// holding out for WiFi), so a caller that can't rely on the catch-up pass+ /// knows the episodes still need retrying.+ Future<bool> _downloadSubscribedEpisodes(+ String podcastId, {+ List<String>? keys,+ Map<String, Map<String, dynamic>>? meta,+ }) async {+ if (_api == null || isOffline) return false;final wifiOnly = await PlayerSettings.getWifiOnlyDownloads();if (wifiOnly) {final connectivity = await Connectivity().checkConnectivity();if (!connectivity.contains(ConnectivityResult.wifi)) {debugPrint('[Subscription] Skipping download (not on WiFi) - will retry on WiFi');- return;+ return false;}}final dl = DownloadService();int downloaded = 0;- for (final key in _absorbingBookIds) {- if (!key.startsWith(podcastId)) continue;+ final targets = keys ??+ [for (final k in _absorbingBookIds) if (k.startsWith(podcastId)) k];++ for (final key in targets) {if (dl.isDownloaded(key) || dl.isDownloading(key)) continue;- final cached = _absorbingItemCache[key];- final epId = key.substring(37);+ final cached = meta?[key] ?? _absorbingItemCache[key];+ // key is '<podcastId>-<episodeId>', so the offset follows the show id+ // rather than assuming every id is a 36-char UUID.+ final epId = key.substring(podcastId.length + 1);final ep = cached?['recentEpisode'] as Map<String, dynamic>?;final media = cached?['media'] as Map<String, dynamic>? ?? {};final metadata = media['metadata'] as Map<String, dynamic>? ?? {};@@ -2334,10 +2386,13 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {}if (downloaded > 0) {- final cached = _absorbingItemCache.values.firstWhere(- (c) => (c['id'] as String?) == podcastId,- orElse: () => {},- );+ // A queue-less show has nothing in the absorbing cache, so fall back to+ // the metadata that came in with this batch.+ final cached = meta?.values.firstOrNull ??+ _absorbingItemCache.values.firstWhere(+ (c) => (c['id'] as String?) == podcastId,+ orElse: () => {},+ );final media = cached['media'] as Map<String, dynamic>? ?? {};final metadata = media['metadata'] as Map<String, dynamic>? ?? {};final showTitle = metadata['title'] as String? ?? 'Podcast';@@ -2345,6 +2400,10 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {final l = _l();final String message;switch (position) {+ case 'none':+ message = l?.lpSubscribedEpisodeDownloaded(showTitle)+ ?? 'New $showTitle episode downloaded';+ break;case 'end':message = l?.lpSubscribedEpisodeAddedEnd(showTitle)?? '$showTitle added to the end of your queue';@@ -2359,9 +2418,14 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {}final ctx = rootNavigatorKey.currentContext;if (ctx != null) {- showOverlayToast(ctx, message, icon: Icons.playlist_add_rounded);+ showOverlayToast(ctx,+ message,+ icon: position == 'none'+ ? Icons.download_done_rounded+ : Icons.playlist_add_rounded);}}+ return true;}Future<void> catchUpSubscribedPodcasts() async {diff --git a/lib/widgets/episode_list_sheet.dart b/lib/widgets/episode_list_sheet.dartindex bbd5a886..d3108054 100644--- a/lib/widgets/episode_list_sheet.dart+++ b/lib/widgets/episode_list_sheet.dart@@ -601,10 +601,17 @@ class _EpisodeListSheetState extends State<EpisodeListSheet> {void _showNewEpisodePositionPicker() {final l = AppLocalizations.of(context)!;final cs = Theme.of(context).colorScheme;- final options = <String, String>{- 'start': l.episodeListPositionTop,- 'second': l.episodeListPositionSecond,- 'end': l.episodeListPositionEnd,+ // 'none' keeps everything else about the subscription - new-episode+ // detection, the notification, the download - and only skips the queue,+ // for people subscribed to enough shows that it buries the rest.+ final options = <String, ({String title, String? subtitle})>{+ 'start': (title: l.episodeListPositionTop, subtitle: null),+ 'second': (title: l.episodeListPositionSecond, subtitle: null),+ 'end': (title: l.episodeListPositionEnd, subtitle: null),+ 'none': (+ title: l.episodeListPositionNone,+ subtitle: l.episodeListPositionNoneDesc+ ),};showModalBottomSheet(context: context,@@ -634,7 +641,14 @@ class _EpisodeListSheetState extends State<EpisodeListSheet> {: Icons.radio_button_unchecked_rounded,color: _newEpisodePosition == entry.key ? cs.primary : cs.onSurfaceVariant,),- title: Text(entry.value),+ title: Text(entry.value.title),+ subtitle: entry.value.subtitle == null+ ? null+ : Text(entry.value.subtitle!,+ style: Theme.of(context)+ .textTheme+ .bodySmall+ ?.copyWith(color: cs.onSurfaceVariant)),onTap: () async {Navigator.pop(ctx);await PlayerSettings.setPodcastNewEpisodePosition(_itemId, entry.key);