A cross platform Audiobookshelf client for Android and iOS
Dart
Track libraryId on downloads, filter downloads screen by active library
Nathan Poulsonc611f7e1a4e1
diff --git a/lib/providers/_lp_core.dart b/lib/providers/_lp_core.dartindex 87ad46ca..23f9f866 100644--- a/lib/providers/_lp_core.dart+++ b/lib/providers/_lp_core.dart@@ -1546,6 +1546,7 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {author: metadata['title'] as String? ?? '',coverUrl: getCoverUrl(podcastId),episodeId: epId,+ libraryId: _selectedLibraryId,);downloaded++;}@@ -1712,6 +1713,7 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {author: title,coverUrl: getCoverUrl(showId),episodeId: epId,+ libraryId: _selectedLibraryId,);} else {dl.downloadItem(@@ -1720,6 +1722,7 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {title: title,author: author,coverUrl: getCoverUrl(key),+ libraryId: _selectedLibraryId,);}queued++;@@ -1766,6 +1769,7 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {author: player.currentAuthor ?? '',coverUrl: player.currentCoverUrl,episodeId: player.currentEpisodeId,+ libraryId: _selectedLibraryId,);}@@ -1804,6 +1808,7 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {title: md['title'] as String? ?? '',author: md['authorName'] as String? ?? '',coverUrl: getCoverUrl(bookId),+ libraryId: _selectedLibraryId,);newDownloads++;}@@ -1843,6 +1848,7 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {title: metadata['title'] as String? ?? '',author: metadata['authorName'] as String? ?? '',coverUrl: getCoverUrl(id),+ libraryId: _selectedLibraryId,);queued++;newDownloads++;@@ -1893,6 +1899,7 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {author: metadata['title'] as String? ?? '',coverUrl: getCoverUrl(showId),episodeId: episodeId,+ libraryId: _selectedLibraryId,);newDownloads++;}@@ -1917,6 +1924,7 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {author: metadata['title'] as String? ?? '',coverUrl: getCoverUrl(showId),episodeId: epId,+ libraryId: _selectedLibraryId,);queued++;newDownloads++;diff --git a/lib/screens/downloads_screen.dart b/lib/screens/downloads_screen.dartindex 7d9e476a..9289e5ad 100644--- a/lib/screens/downloads_screen.dart+++ b/lib/screens/downloads_screen.dart@@ -3,6 +3,7 @@ import 'package:cached_network_image/cached_network_image.dart';import 'package:flutter/material.dart';import 'package:provider/provider.dart';import '../providers/library_provider.dart';+import '../services/audio_player_service.dart';import '../services/download_service.dart';import '../widgets/absorb_page_header.dart';@@ -18,6 +19,7 @@ class _DownloadsScreenState extends State<DownloadsScreen> {Map<String, int> _fileSizes = {};bool _selecting = false;final Set<String> _selected = {};+ bool _mergeLibraries = false;@overridevoid initState() {@@ -31,10 +33,12 @@ class _DownloadsScreenState extends State<DownloadsScreen> {for (final item in items) {sizes[item.itemId] = DownloadService().getItemFileSize(item.itemId);}+ final merge = await PlayerSettings.getMergeAbsorbingLibraries();if (mounted) {setState(() {_items = items;_fileSizes = sizes;+ _mergeLibraries = merge;_loading = false;});}@@ -200,9 +204,18 @@ class _DownloadsScreenState extends State<DownloadsScreen> {listenable: DownloadService(),builder: (ctx, _) {final ds = DownloadService();- final active = ds.activeDownloads;- final queued = ds.queuedDownloads;- final completed = ds.downloadedItems;+ final lib = context.watch<LibraryProvider>();+ final activeLibId = lib.selectedLibraryId;+ final shouldFilter = !lib.isOffline && !_mergeLibraries && activeLibId != null;++ List<DownloadInfo> filterByLibrary(List<DownloadInfo> items) {+ if (!shouldFilter) return items;+ return items.where((d) => d.libraryId == null || d.libraryId == activeLibId).toList();+ }++ final active = filterByLibrary(ds.activeDownloads);+ final queued = filterByLibrary(ds.queuedDownloads);+ final completed = filterByLibrary(ds.downloadedItems);final hasAny = active.isNotEmpty || queued.isNotEmpty || completed.isNotEmpty;if (!hasAny) {diff --git a/lib/services/download_service.dart b/lib/services/download_service.dartindex b1b61493..6b9e7f4b 100644--- a/lib/services/download_service.dart+++ b/lib/services/download_service.dart@@ -25,6 +25,7 @@ class DownloadInfo {final String? coverUrl;final String? localCoverPath;final String? localDirPath;+ final String? libraryId;DownloadInfo({required this.itemId,@@ -37,6 +38,7 @@ class DownloadInfo {this.coverUrl,this.localCoverPath,this.localDirPath,+ this.libraryId,});Map<String, dynamic> toJson() => {@@ -49,6 +51,7 @@ class DownloadInfo {'coverUrl': coverUrl,'localCoverPath': localCoverPath,if (localDirPath != null) 'localDirPath': localDirPath,+ if (libraryId != null) 'libraryId': libraryId,};factory DownloadInfo.fromJson(Map<String, dynamic> json) {@@ -93,6 +96,7 @@ class DownloadInfo {coverUrl: coverUrl,localCoverPath: json['localCoverPath'] as String?,localDirPath: json['localDirPath'] as String?,+ libraryId: json['libraryId'] as String?,);}}@@ -104,6 +108,7 @@ class _QueuedDownload {final String? author;final String? coverUrl;final String? episodeId;+ final String? libraryId;_QueuedDownload({required this.api,@@ -112,6 +117,7 @@ class _QueuedDownload {this.author,this.coverUrl,this.episodeId,+ this.libraryId,});}@@ -371,6 +377,7 @@ class DownloadService extends ChangeNotifier {coverUrl: info.coverUrl,localCoverPath: newCoverPath,localDirPath: newDirPath,+ libraryId: info.libraryId,);changed = true;}@@ -530,6 +537,7 @@ class DownloadService extends ChangeNotifier {author: author ?? info.author,coverUrl: coverUrl ?? info.coverUrl,localCoverPath: localCoverPath,+ libraryId: info.libraryId,);changed = true;}@@ -596,6 +604,7 @@ class DownloadService extends ChangeNotifier {String? author,String? coverUrl,String? episodeId,+ String? libraryId,}) async {if (_activeDownloadIds.contains(itemId)) return null;if (isDownloaded(itemId)) return null;@@ -622,6 +631,7 @@ class DownloadService extends ChangeNotifier {author: author,coverUrl: coverUrl,episodeId: episodeId,+ libraryId: libraryId,));_downloads[itemId] = DownloadInfo(itemId: itemId,@@ -630,6 +640,7 @@ class DownloadService extends ChangeNotifier {title: title,author: author,coverUrl: coverUrl,+ libraryId: libraryId,);notifyListeners();return null;@@ -643,6 +654,7 @@ class DownloadService extends ChangeNotifier {author: author,coverUrl: coverUrl,episodeId: episodeId,+ libraryId: libraryId,));return null;}@@ -658,6 +670,7 @@ class DownloadService extends ChangeNotifier {unawaited(_executeDownload(api: next.api, itemId: next.itemId, title: next.title,author: next.author, coverUrl: next.coverUrl, episodeId: next.episodeId,+ libraryId: next.libraryId,));}}@@ -682,6 +695,7 @@ class DownloadService extends ChangeNotifier {String? author,String? coverUrl,String? episodeId,+ String? libraryId,}) async {_activeDownloadIds.add(itemId);_cancelledIds.remove(itemId);@@ -696,6 +710,7 @@ class DownloadService extends ChangeNotifier {title: title,author: author,coverUrl: coverUrl,+ libraryId: libraryId,);notifyListeners();@@ -787,6 +802,7 @@ class DownloadService extends ChangeNotifier {title: title,author: author,coverUrl: coverUrl,+ libraryId: libraryId,);notifyListeners();}@@ -877,6 +893,7 @@ class DownloadService extends ChangeNotifier {title: title,author: author,coverUrl: coverUrl,+ libraryId: libraryId,);notifyListeners();@@ -907,6 +924,7 @@ class DownloadService extends ChangeNotifier {coverUrl: coverUrl,localCoverPath: localCoverPath,localDirPath: bookDir.path,+ libraryId: libraryId,);await _save();notifyListeners();diff --git a/lib/widgets/absorbing_shared.dart b/lib/widgets/absorbing_shared.dartindex c479924b..f2e5aea1 100644--- a/lib/widgets/absorbing_shared.dart+++ b/lib/widgets/absorbing_shared.dart@@ -3,6 +3,7 @@ import 'dart:ui';import 'package:flutter/material.dart';import 'package:provider/provider.dart';import '../providers/auth_provider.dart';+import '../providers/library_provider.dart';import '../services/download_service.dart';import '../services/playback_history_service.dart';@@ -201,7 +202,7 @@ class _DownloadWideButtonState extends State<DownloadWideButton> {} else if (_dl.isDownloading(widget.itemId)) {_dl.cancelDownload(widget.itemId);} else {- _dl.downloadItem(api: api, itemId: widget.itemId, title: widget.title, author: widget.author, coverUrl: widget.coverUrl);+ _dl.downloadItem(api: api, itemId: widget.itemId, title: widget.title, author: widget.author, coverUrl: widget.coverUrl, libraryId: context.read<LibraryProvider>().selectedLibraryId);}}}diff --git a/lib/widgets/episode_detail_sheet.dart b/lib/widgets/episode_detail_sheet.dartindex 193095f7..29ecd034 100644--- a/lib/widgets/episode_detail_sheet.dart+++ b/lib/widgets/episode_detail_sheet.dart@@ -113,6 +113,7 @@ class _EpisodeDetailSheetState extends State<EpisodeDetailSheet> {author: _showTitle,coverUrl: api.getCoverUrl(_itemId),episodeId: _episodeId,+ libraryId: context.read<LibraryProvider>().selectedLibraryId,);if (error != null && mounted) {ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(error)));diff --git a/lib/widgets/episode_list_sheet.dart b/lib/widgets/episode_list_sheet.dartindex 82df7287..93f01a39 100644--- a/lib/widgets/episode_list_sheet.dart+++ b/lib/widgets/episode_list_sheet.dart@@ -308,6 +308,7 @@ class _EpisodeListSheetState extends State<EpisodeListSheet> {author: _title,coverUrl: coverUrl,episodeId: episodeId,+ libraryId: context.read<LibraryProvider>().selectedLibraryId,);if (error != null && mounted) {@@ -355,6 +356,7 @@ class _EpisodeListSheetState extends State<EpisodeListSheet> {author: _title,coverUrl: api.getCoverUrl(_itemId),episodeId: episodeId,+ libraryId: context.read<LibraryProvider>().selectedLibraryId,);}diff --git a/lib/widgets/series_books_sheet.dart b/lib/widgets/series_books_sheet.dartindex ea605e3a..3af1751b 100644--- a/lib/widgets/series_books_sheet.dart+++ b/lib/widgets/series_books_sheet.dart@@ -836,6 +836,7 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {title: title,author: author,coverUrl: api.getCoverUrl(bookId),+ libraryId: context.read<LibraryProvider>().selectedLibraryId,);}