Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add Up Next and New filters to the podcast episodes tab

Barnabasefc772a887d7
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb
index 8b5a1276..bed93502 100644
--- a/lib/l10n/app_en.arb
+++ b/lib/l10n/app_en.arb
@@ -532,6 +532,8 @@
"filterAllEpisodes": "All",
"filterUnplayed": "Unplayed",
"episodeFeedEmpty": "No episodes match this filter",
+ "podcastFilterUpNext": "Up Next",
+ "podcastFilterNew": "New",
"settingsPodcastTab": "Podcasts tab",
"settingsPodcastTabDesc": "Give one podcast library its own tab in the bottom bar",
"settingsPodcastTabLibrary": "Podcasts tab library",
diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart
index 01565d16..7d34a103 100644
--- a/lib/l10n/app_localizations.dart
+++ b/lib/l10n/app_localizations.dart
@@ -2050,6 +2050,18 @@ abstract class AppLocalizations {
/// **'No episodes match this filter'**
String get episodeFeedEmpty;
+ /// No description provided for @podcastFilterUpNext.
+ ///
+ /// In en, this message translates to:
+ /// **'Up Next'**
+ String get podcastFilterUpNext;
+
+ /// No description provided for @podcastFilterNew.
+ ///
+ /// In en, this message translates to:
+ /// **'New'**
+ String get podcastFilterNew;
+
/// No description provided for @settingsPodcastTab.
///
/// In en, this message translates to:
diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart
index 27356bb8..a1e82e23 100644
--- a/lib/l10n/app_localizations_de.dart
+++ b/lib/l10n/app_localizations_de.dart
@@ -1076,6 +1076,12 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get episodeFeedEmpty => 'Keine Folgen entsprechen diesem Filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcast-Tab';
diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dart
index fd8216c8..c08e7f15 100644
--- a/lib/l10n/app_localizations_el.dart
+++ b/lib/l10n/app_localizations_el.dart
@@ -1068,6 +1068,12 @@ class AppLocalizationsEl extends AppLocalizations {
@override
String get episodeFeedEmpty => 'No episodes match this filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcasts tab';
diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart
index 6ad58038..a3540eb8 100644
--- a/lib/l10n/app_localizations_en.dart
+++ b/lib/l10n/app_localizations_en.dart
@@ -1068,6 +1068,12 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get episodeFeedEmpty => 'No episodes match this filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcasts tab';
diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart
index 10235443..d0cc0112 100644
--- a/lib/l10n/app_localizations_es.dart
+++ b/lib/l10n/app_localizations_es.dart
@@ -1070,6 +1070,12 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get episodeFeedEmpty => 'No episodes match this filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcasts tab';
diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart
index b837390e..52a0fa65 100644
--- a/lib/l10n/app_localizations_fr.dart
+++ b/lib/l10n/app_localizations_fr.dart
@@ -1074,6 +1074,12 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get episodeFeedEmpty => 'Aucun épisode ne correspond à ce filtre';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Onglet Podcasts';
diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart
index ea8e7071..bf4f80e9 100644
--- a/lib/l10n/app_localizations_it.dart
+++ b/lib/l10n/app_localizations_it.dart
@@ -1068,6 +1068,12 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get episodeFeedEmpty => 'No episodes match this filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcasts tab';
diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart
index d530f71e..efe2a2ff 100644
--- a/lib/l10n/app_localizations_ja.dart
+++ b/lib/l10n/app_localizations_ja.dart
@@ -1068,6 +1068,12 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get episodeFeedEmpty => 'No episodes match this filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcasts tab';
diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dart
index 59ddd80e..bc51713e 100644
--- a/lib/l10n/app_localizations_no.dart
+++ b/lib/l10n/app_localizations_no.dart
@@ -1068,6 +1068,12 @@ class AppLocalizationsNo extends AppLocalizations {
@override
String get episodeFeedEmpty => 'No episodes match this filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcasts tab';
diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart
index a6f6885c..9aacd59f 100644
--- a/lib/l10n/app_localizations_pt.dart
+++ b/lib/l10n/app_localizations_pt.dart
@@ -1068,6 +1068,12 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get episodeFeedEmpty => 'No episodes match this filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcasts tab';
diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dart
index 0fea6987..a71c43cb 100644
--- a/lib/l10n/app_localizations_ro.dart
+++ b/lib/l10n/app_localizations_ro.dart
@@ -1068,6 +1068,12 @@ class AppLocalizationsRo extends AppLocalizations {
@override
String get episodeFeedEmpty => 'No episodes match this filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcasts tab';
diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart
index 4146976c..38644db6 100644
--- a/lib/l10n/app_localizations_ru.dart
+++ b/lib/l10n/app_localizations_ru.dart
@@ -1068,6 +1068,12 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get episodeFeedEmpty => 'No episodes match this filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcasts tab';
diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart
index 292d6cc3..08aa4ce7 100644
--- a/lib/l10n/app_localizations_zh.dart
+++ b/lib/l10n/app_localizations_zh.dart
@@ -1057,6 +1057,12 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get episodeFeedEmpty => 'No episodes match this filter';
+ @override
+ String get podcastFilterUpNext => 'Up Next';
+
+ @override
+ String get podcastFilterNew => 'New';
+
@override
String get settingsPodcastTab => 'Podcasts tab';
diff --git a/lib/providers/_lp_core.dart b/lib/providers/_lp_core.dart
index c20b2784..8f3b32c5 100644
--- a/lib/providers/_lp_core.dart
+++ b/lib/providers/_lp_core.dart
@@ -1348,9 +1348,10 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {
_lastPersonalizedFetchLibraryId = _selectedLibraryId;
await _refreshProgress();
_personalizedSections = await _api!.getPersonalizedView(
- _selectedLibraryId!,
- include: const ['numEpisodesIncomplete'],
- );
+ _selectedLibraryId!,
+ include: const ['numEpisodesIncomplete'],
+ ) ??
+ [];
for (final section in _personalizedSections) {
for (final e in (section['entities'] as List<dynamic>? ?? [])) {
if (e is Map<String, dynamic>) {
@@ -1432,11 +1433,12 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {
try {
final sections = await api.getPersonalizedView(
- libraryId,
- include: const ['numEpisodesIncomplete'],
- shelves: _StateMixin._progressDrivenShelfIds,
- limit: 10,
- );
+ libraryId,
+ include: const ['numEpisodesIncomplete'],
+ shelves: _StateMixin._progressDrivenShelfIds,
+ limit: 10,
+ ) ??
+ [];
_lastProgressShelvesFetchAt = DateTime.now();
_lastProgressShelvesLibraryId = libraryId;
if (_selectedLibraryId != libraryId || isOffline) return;
@@ -1512,9 +1514,10 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {
unawaited(() async {
try {
final sections = await api.getPersonalizedView(
- libraryId,
- include: const ['numEpisodesIncomplete', 'rssfeed'],
- );
+ libraryId,
+ include: const ['numEpisodesIncomplete', 'rssfeed'],
+ ) ??
+ [];
_lastRssHydrationAt = DateTime.now();
_lastRssHydrationLibraryId = libraryId;
diff --git a/lib/services/android_auto_service.dart b/lib/services/android_auto_service.dart
index edc2e35d..ace802ee 100644
--- a/lib/services/android_auto_service.dart
+++ b/lib/services/android_auto_service.dart
@@ -599,14 +599,16 @@ class AndroidAutoService {
// episodes come from a separate /recent-episodes call below since the
// personalized endpoint's `episodes-recently-added` shelf gets stripped
// when a `shelves` filter is passed.
- final clFutures = _libraries.map((lib) => api.getPersonalizedView(
+ final clFutures = _libraries.map((lib) => api
+ .getPersonalizedView(
lib.id,
include: const ['numEpisodesIncomplete'],
shelves: lib.isPodcast
? const ['continue-listening']
: const ['continue-listening', 'continue-series', 'recently-added'],
limit: 10,
- ));
+ )
+ .then((sections) => sections ?? const <dynamic>[]));
// Newly added podcast episodes per podcast library (empty for book libs).
final episodeFutures = _libraries
diff --git a/lib/services/api_service.dart b/lib/services/api_service.dart
index 0e5d209b..d12a93e8 100644
--- a/lib/services/api_service.dart
+++ b/lib/services/api_service.dart
@@ -468,7 +468,9 @@ class ApiService {
/// Get the personalized home view for a library.
/// Returns sections like "continue-listening", "recently-added", "discover", etc.
- Future<List<dynamic>> getPersonalizedView(
+ /// Null means the request failed (network / non-200), as opposed to an
+ /// empty list of shelves.
+ Future<List<dynamic>?> getPersonalizedView(
String libraryId, {
bool minified = true,
List<String> include = const ['numEpisodesIncomplete'],
@@ -502,7 +504,7 @@ class ApiService {
} catch (e) {
// ignore
}
- return [];
+ return null;
}
/// Get library items (paginated).
diff --git a/lib/widgets/podcast_episode_feed.dart b/lib/widgets/podcast_episode_feed.dart
index 85814931..87242497 100644
--- a/lib/widgets/podcast_episode_feed.dart
+++ b/lib/widgets/podcast_episode_feed.dart
@@ -1,3 +1,4 @@
+import 'dart:async';
import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
@@ -62,13 +63,27 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {
String _filter = 'all';
final _scroll = ScrollController();
+ // Server-category filters ("Up Next" / "New") show a personalized shelf
+ // instead of the client-filtered recent-episodes pages.
+ final _shelfEpisodes = <Map<String, dynamic>>[];
+ bool _shelfLoading = false;
+ String? _loadedShelfFilter;
+ String? _shelfError;
+ int _shelfReq = 0;
+
+ bool get _isShelfFilter => _filter == 'upnext' || _filter == 'new';
+
@override
void initState() {
super.initState();
ScopedPrefs.getString('episode_feed_filter_${widget.libraryId}').then((v) {
if (mounted && v != null && v.isNotEmpty) {
setState(() => _filter = v);
- _fillFilteredResults();
+ if (_isShelfFilter) {
+ _loadShelf();
+ } else {
+ _fillFilteredResults();
+ }
}
});
_scroll.addListener(_onScroll);
@@ -82,7 +97,7 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {
}
void _onScroll() {
- if (!_hasMore || _loadingMore || _loading) return;
+ if (_isShelfFilter || !_hasMore || _loadingMore || _loading) return;
if (_scroll.position.pixels > _scroll.position.maxScrollExtent - 600) {
_loadPage();
}
@@ -115,6 +130,10 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {
}
Future<void> _refresh() async {
+ if (_isShelfFilter) {
+ await _loadShelf();
+ return;
+ }
_episodes.clear();
_page = 0;
_hasMore = true;
@@ -125,13 +144,85 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {
if (f == _filter) return;
setState(() => _filter = f);
ScopedPrefs.setString('episode_feed_filter_${widget.libraryId}', f);
- _fillFilteredResults();
+ if (_isShelfFilter) {
+ _loadShelf();
+ } else {
+ _fillFilteredResults();
+ }
+ }
+
+ /// "Up Next" maps to the personalized view's continue-listening shelf,
+ /// "New" to newest-episodes - the shelves the old podcast home page
+ /// showed before the Podcasts tab replaced it. Always refetches on entry
+ /// (progress changes reshape Up Next server-side); previous rows for the
+ /// same shelf stay visible while the refresh runs.
+ Future<void> _loadShelf() async {
+ final wanted = _filter;
+ final req = ++_shelfReq;
+ final api = context.read<AuthProvider>().apiService;
+ if (api == null) return;
+ setState(() {
+ _shelfLoading = true;
+ _shelfError = null;
+ if (_loadedShelfFilter != wanted) _shelfEpisodes.clear();
+ });
+ final shelves = await api.getPersonalizedView(widget.libraryId, limit: 50);
+ // The token guards A -> B -> A chip flips, where the filter check alone
+ // would let the first A response overwrite the second's.
+ if (!mounted || _filter != wanted || req != _shelfReq) return;
+ if (shelves == null) {
+ // Failed fetch: keep whatever is showing; only surface an error when
+ // the list is empty. Pull-to-refresh retries.
+ setState(() {
+ _shelfLoading = false;
+ if (_shelfEpisodes.isEmpty) {
+ _shelfError = AppLocalizations.of(context)!.failedToLoad;
+ }
+ });
+ return;
+ }
+ final shelfId =
+ wanted == 'upnext' ? 'continue-listening' : 'newest-episodes';
+ final shelf = shelves.whereType<Map<String, dynamic>>().firstWhere(
+ (s) => s['id'] == shelfId && s['type'] == 'episode',
+ orElse: () => const <String, dynamic>{},
+ );
+ final entities = shelf['entities'] as List<dynamic>? ?? const [];
+ debugPrint('[EpisodeFeed] shelf $shelfId -> ${entities.length} entities');
+ setState(() {
+ _shelfEpisodes
+ ..clear()
+ ..addAll(_mapShelfEntities(entities));
+ _loadedShelfFilter = wanted;
+ _shelfLoading = false;
+ });
+ }
+
+ /// Personalized shelf entities are minified library items with the episode
+ /// attached as `recentEpisode`. Flatten to the feed's episode shape.
+ List<Map<String, dynamic>> _mapShelfEntities(List<dynamic> entities) {
+ final out = <Map<String, dynamic>>[];
+ for (final item in entities.whereType<Map<String, dynamic>>()) {
+ final ep = item['recentEpisode'];
+ if (ep is! Map<String, dynamic>) continue;
+ out.add(<String, dynamic>{
+ ...ep,
+ // Non-expanded episode JSON keeps duration inside audioFile.
+ 'duration': ep['duration'] ??
+ (ep['audioFile'] as Map<String, dynamic>?)?['duration'],
+ 'libraryItemId': ep['libraryItemId'] ?? item['id'],
+ 'libraryId': item['libraryId'] ?? widget.libraryId,
+ 'podcast': item,
+ });
+ }
+ return out;
}
void _fillFilteredResults() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted ||
_filter == 'all' ||
+ _isShelfFilter ||
!_hasMore ||
_loading ||
_loadingMore) {
@@ -336,6 +427,8 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {
lib.markFinishedLocally('$showId-$epId', skipAutoAdvance: true);
}
if (mounted) setState(() {});
+ // Up Next is server-shaped by progress, so re-pull it after a toggle.
+ if (mounted && _isShelfFilter) unawaited(_loadShelf());
}
@override
@@ -344,10 +437,12 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {
final l = AppLocalizations.of(context)!;
final lib = context.watch<LibraryProvider>();
- if (_loading) {
+ // Shelf mode renders from its own state - don't let the recent-feed's
+ // initial load or error blank an already-loaded shelf.
+ if (_loading && !_isShelfFilter) {
return const Center(child: CircularProgressIndicator());
}
- if (_error != null && _episodes.isEmpty) {
+ if (_error != null && _episodes.isEmpty && !_isShelfFilter) {
return Center(
child: Padding(
padding: const EdgeInsets.all(24),
@@ -360,7 +455,9 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {
);
}
- final filtered = _episodes.where((ep) => _matchesFilter(lib, ep)).toList();
+ final filtered = _isShelfFilter
+ ? _shelfEpisodes
+ : _episodes.where((ep) => _matchesFilter(lib, ep)).toList();
return RefreshIndicator(
onRefresh: _refresh,
@@ -380,6 +477,8 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {
children: [
for (final (key, label) in [
('all', l.filterAllEpisodes),
+ ('upnext', l.podcastFilterUpNext),
+ ('new', l.podcastFilterNew),
('subscribed', l.episodeListSubscribedChip),
('notfinished', l.notFinished),
('unplayed', l.filterUnplayed),
@@ -401,19 +500,27 @@ class _PodcastEpisodeFeedState extends State<PodcastEpisodeFeed> {
),
),
),
- if (filtered.isEmpty)
+ if (_isShelfFilter && _shelfLoading && _shelfEpisodes.isEmpty)
+ const SliverFillRemaining(
+ hasScrollBody: false,
+ child: Center(child: CircularProgressIndicator()),
+ )
+ else if (filtered.isEmpty)
SliverFillRemaining(
hasScrollBody: false,
child: Center(
child: Text(
- l.episodeFeedEmpty,
+ _isShelfFilter && _shelfError != null
+ ? _shelfError!
+ : l.episodeFeedEmpty,
style: TextStyle(color: cs.onSurfaceVariant),
),
),
)
else
SliverList.builder(
- itemCount: filtered.length + (_loadingMore ? 1 : 0),
+ itemCount: filtered.length +
+ (_loadingMore && !_isShelfFilter ? 1 : 0),
itemBuilder: (context, i) {
if (i >= filtered.length) {
return const Padding(