fix: library continue watching hidden

close #615
This commit is contained in:
edde746
2026-03-03 12:17:37 +01:00
parent ebf2d1e516
commit 013bcfbece
2 changed files with 15 additions and 51 deletions
@@ -53,55 +53,29 @@ class _LibraryRecommendedTabState extends BaseLibraryTabState<PlexHub, LibraryRe
@override
String get errorContext => t.libraries.tabs.recommended;
/// Detects Continue Watching hubs by hubIdentifier.
/// Section-specific CW hubs use identifiers like "movie.inprogress.1".
static bool _isContinueWatchingHub(PlexHub hub) {
final hubId = hub.hubIdentifier?.toLowerCase() ?? '';
return hubId.contains('inprogress');
}
@override
Future<List<PlexHub>> loadData() async {
// Clear hub keys before loading new hubs to prevent stale references
_hubKeys.clear();
// Use server-specific client for this library
final client = getClientForLibrary();
final hubs = await client.getLibraryHubs(widget.library.key, limit: 12);
// Load both continue watching items and regular hubs in parallel
final results = await Future.wait([
client.getOnDeckForLibrary(widget.library.key),
client.getLibraryHubs(widget.library.key, limit: 12),
]);
final continueWatchingItems = results.first as List<PlexMetadata>;
final hubs = results[1] as List<PlexHub>;
// Filter out any existing Continue Watching hubs since we're adding our own
final filteredHubs = hubs.where((hub) {
final title = hub.title.toLowerCase();
final hubId = hub.hubIdentifier?.toLowerCase() ?? '';
return !title.contains('continue watching') &&
!title.contains('on deck') &&
!hubId.contains('ondeck') &&
!hubId.contains('continue');
}).toList();
final finalHubs = <PlexHub>[];
// Add Continue Watching as the first hub if there are items
if (continueWatchingItems.isNotEmpty) {
final continueWatchingHub = PlexHub(
hubKey: 'library_continue_watching_${widget.library.key}',
title: t.discover.continueWatching,
type: 'mixed',
hubIdentifier: '_library_continue_watching_',
size: continueWatchingItems.length,
more: false,
items: continueWatchingItems,
serverId: widget.library.serverId,
serverName: widget.library.serverName,
);
finalHubs.add(continueWatchingHub);
// Move Continue Watching hub to the front if present
final cwIndex = hubs.indexWhere(_isContinueWatchingHub);
if (cwIndex > 0) {
final cwHub = hubs.removeAt(cwIndex);
hubs.insert(0, cwHub);
}
// Add the filtered regular hubs
finalHubs.addAll(filteredHubs);
return finalHubs;
return hubs;
}
/// Ensure we have enough GlobalKeys for all hubs
@@ -163,7 +137,7 @@ class _LibraryRecommendedTabState extends BaseLibraryTabState<PlexHub, LibraryRe
itemCount: items.length,
itemBuilder: (context, index) {
final hub = items[index];
final isContinueWatching = hub.hubIdentifier == '_library_continue_watching_';
final isContinueWatching = _isContinueWatchingHub(hub);
return HubSection(
key: index < _hubKeys.length ? _hubKeys[index] : null,
-10
View File
@@ -851,16 +851,6 @@ class PlexClient {
return Isolate.run(() => _processOnDeckResponse(response.data as Map<String, dynamic>, sid, sname));
}
/// Get on deck items filtered by a specific library section
Future<List<PlexMetadata>> getOnDeckForLibrary(String sectionId) async {
final allOnDeck = await getOnDeck();
// Filter items to only include those from the specified library section
return allOnDeck.where((item) {
return item.librarySectionID == int.tryParse(sectionId);
}).toList();
}
/// Get children of a metadata item (e.g., seasons for a show, episodes for a season)
/// Uses cache when offline or as fallback on network error
Future<List<PlexMetadata>> getChildren(String ratingKey) async {