A cross platform Audiobookshelf client for Android and iOS
Dart
Download several books at once from multi-select on home and library
Barnabascb6340bd0f49
diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dartindex 3f01f5f5..84aa3488 100644--- a/lib/screens/home_screen.dart+++ b/lib/screens/home_screen.dart@@ -394,8 +394,17 @@ class HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateMicanQuickMatch: auth.isAdmin && !lib.isPodcastLibrary,canMarkProgress: !lib.isPodcastLibrary,canDelete: auth.canDelete,+ canDownload: !lib.isPodcastLibrary,onSelectAll: _toggleSelectAll,onClear: _clearSelection,+ onDownload: () => _runBatchAction(+ () => DesktopBatchActions.download(+ context,+ selectableItems+ .where((i) => _selectedItemIds.contains(i['id']))+ .toList(),+ ),+ ),onQuickMatch: () => _runBatchAction(() => DesktopBatchActions.quickMatch(context,diff --git a/lib/screens/library_screen.dart b/lib/screens/library_screen.dartindex 386599e3..11b6b17c 100644--- a/lib/screens/library_screen.dart+++ b/lib/screens/library_screen.dart@@ -2680,8 +2680,17 @@ class LibraryScreenState extends State<LibraryScreen>canQuickMatch: auth.isAdmin && !libWatch.isPodcastLibrary,canMarkProgress: !libWatch.isPodcastLibrary,canDelete: auth.canDelete,+ canDownload: !libWatch.isPodcastLibrary,onSelectAll: _toggleSelectAll,onClear: _clearSelection,+ onDownload: () => _runBatchAction(+ () => DesktopBatchActions.download(+ context,+ _selectableVisibleItems()+ .where((i) => _selectedItemIds.contains(i['id']))+ .toList(),+ ),+ ),onQuickMatch: () => _runBatchAction(() => DesktopBatchActions.quickMatch(context,diff --git a/lib/widgets/desktop_batch_actions.dart b/lib/widgets/desktop_batch_actions.dartindex 97bcebf0..29b09fb4 100644--- a/lib/widgets/desktop_batch_actions.dart+++ b/lib/widgets/desktop_batch_actions.dart@@ -5,6 +5,7 @@ import '../l10n/app_localizations.dart';import '../providers/auth_provider.dart';import '../providers/library_provider.dart';import '../services/audio_player_service.dart';+import '../services/download_service.dart';import 'delete_confirm_dialog.dart';import 'overlay_toast.dart';@@ -102,6 +103,44 @@ Future<DesktopQuickMatchOptions?> showDesktopQuickMatchDialog(class DesktopBatchActions {const DesktopBatchActions._();+ /// Queue downloads for the picked books without playing any of them.+ /// Books already downloaded or downloading are skipped; the download+ /// service queues past its concurrency limit on its own.+ static Future<bool?> download(+ BuildContext context,+ List<Map<String, dynamic>> items,+ ) async {+ final api = context.read<AuthProvider>().apiService;+ if (api == null || items.isEmpty) return false;+ final l = AppLocalizations.of(context)!;+ final libraryId = context.read<LibraryProvider>().selectedLibraryId;+ final dl = DownloadService();+ var queued = 0;+ for (final item in items) {+ final id = item['id'] as String?;+ if (id == null || dl.isDownloaded(id) || dl.isDownloading(id)) continue;+ final media = item['media'] as Map<String, dynamic>? ?? const {};+ final meta = media['metadata'] as Map<String, dynamic>? ?? const {};+ await dl.downloadItem(+ api: api,+ itemId: id,+ title: meta['title'] as String? ?? l.unknown,+ author: meta['authorName'] as String? ?? '',+ coverUrl: api.getCoverUrl(id),+ libraryId: item['libraryId'] as String? ?? libraryId,+ );+ queued++;+ }+ if (context.mounted) {+ showOverlayToast(+ context,+ queued > 0 ? l.batchDownloadQueued(queued) : l.batchDownloadNothingNew,+ icon: Icons.download_rounded,+ );+ }+ return true;+ }+static Future<bool?> quickMatch(BuildContext context,List<String> itemIds,@@ -238,8 +277,10 @@ class DesktopBatchActionBar extends StatelessWidget {final bool canQuickMatch;final bool canMarkProgress;final bool canDelete;+ final bool canDownload;final VoidCallback onSelectAll;final VoidCallback onClear;+ final VoidCallback? onDownload;final VoidCallback onQuickMatch;final VoidCallback onMarkFinished;final VoidCallback onMarkUnfinished;@@ -254,8 +295,10 @@ class DesktopBatchActionBar extends StatelessWidget {required this.canQuickMatch,this.canMarkProgress = true,required this.canDelete,+ this.canDownload = false,required this.onSelectAll,required this.onClear,+ this.onDownload,required this.onQuickMatch,required this.onMarkFinished,required this.onMarkUnfinished,@@ -318,6 +361,14 @@ class DesktopBatchActionBar extends StatelessWidget {),),),+ if (canDownload && onDownload != null)+ Tooltip(+ message: l.download,+ child: IconButton(+ onPressed: busy || !hasSelection ? null : onDownload,+ icon: const Icon(Icons.download_rounded),+ ),+ ),if (canQuickMatch)Tooltip(message: l.quickMatch,