A cross platform Audiobookshelf client for Android and iOS
Dart
Give the series sheet a cover strip, series stats, an up next button that plays the book, and the actions as pills instead of a menu
Barnabas1947016795dc
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arbindex 9b216708..c24b61f1 100644--- a/lib/l10n/app_en.arb+++ b/lib/l10n/app_en.arb@@ -4713,6 +4713,14 @@"@detailOtherListeners": {"placeholders": { "count": { "type": "int" } }},+ "seriesUpNext": "Up next",+ "seriesStatsFinished": "Finished",+ "seriesStatsListened": "Listened",+ "seriesStatsLeft": "Left",+ "seriesFinishedOf": "{done} of {total}",+ "@seriesFinishedOf": {+ "placeholders": { "done": { "type": "int" }, "total": { "type": "int" } }+ },"detailSessionsNone": "No listening sessions yet","detailSessionsAll": "All {count} sessions","@detailSessionsAll": {diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dartindex 8080b88c..c23ae2d8 100644--- a/lib/l10n/app_localizations.dart+++ b/lib/l10n/app_localizations.dart@@ -14169,6 +14169,36 @@ abstract class AppLocalizations {/// **'{count, plural, =0{No other listeners} =1{1 other listener} other{{count} other listeners}}'**String detailOtherListeners(int count);+ /// No description provided for @seriesUpNext.+ ///+ /// In en, this message translates to:+ /// **'Up next'**+ String get seriesUpNext;++ /// No description provided for @seriesStatsFinished.+ ///+ /// In en, this message translates to:+ /// **'Finished'**+ String get seriesStatsFinished;++ /// No description provided for @seriesStatsListened.+ ///+ /// In en, this message translates to:+ /// **'Listened'**+ String get seriesStatsListened;++ /// No description provided for @seriesStatsLeft.+ ///+ /// In en, this message translates to:+ /// **'Left'**+ String get seriesStatsLeft;++ /// No description provided for @seriesFinishedOf.+ ///+ /// In en, this message translates to:+ /// **'{done} of {total}'**+ String seriesFinishedOf(int done, int total);+/// No description provided for @detailSessionsNone.////// In en, this message translates to:diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dartindex 45a0e72c..82ff54da 100644--- a/lib/l10n/app_localizations_de.dart+++ b/lib/l10n/app_localizations_de.dart@@ -8340,6 +8340,23 @@ class AppLocalizationsDe extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dartindex 947ec185..886b87d0 100644--- a/lib/l10n/app_localizations_el.dart+++ b/lib/l10n/app_localizations_el.dart@@ -8223,6 +8223,23 @@ class AppLocalizationsEl extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dartindex 48de91bd..c12c12f1 100644--- a/lib/l10n/app_localizations_en.dart+++ b/lib/l10n/app_localizations_en.dart@@ -8223,6 +8223,23 @@ class AppLocalizationsEn extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dartindex 8cec3bdb..e5ac513b 100644--- a/lib/l10n/app_localizations_es.dart+++ b/lib/l10n/app_localizations_es.dart@@ -8225,6 +8225,23 @@ class AppLocalizationsEs extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dartindex 5b60dc75..b4ec222f 100644--- a/lib/l10n/app_localizations_fr.dart+++ b/lib/l10n/app_localizations_fr.dart@@ -8274,6 +8274,23 @@ class AppLocalizationsFr extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dartindex e82a7826..c7213ce8 100644--- a/lib/l10n/app_localizations_it.dart+++ b/lib/l10n/app_localizations_it.dart@@ -8223,6 +8223,23 @@ class AppLocalizationsIt extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dartindex ee1a549e..efe083b9 100644--- a/lib/l10n/app_localizations_ja.dart+++ b/lib/l10n/app_localizations_ja.dart@@ -8223,6 +8223,23 @@ class AppLocalizationsJa extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dartindex a6d148f4..b991bd77 100644--- a/lib/l10n/app_localizations_no.dart+++ b/lib/l10n/app_localizations_no.dart@@ -8223,6 +8223,23 @@ class AppLocalizationsNo extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dartindex ce8a1a87..fad2ae56 100644--- a/lib/l10n/app_localizations_pt.dart+++ b/lib/l10n/app_localizations_pt.dart@@ -8223,6 +8223,23 @@ class AppLocalizationsPt extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dartindex 38d3e705..4fe29127 100644--- a/lib/l10n/app_localizations_ro.dart+++ b/lib/l10n/app_localizations_ro.dart@@ -8223,6 +8223,23 @@ class AppLocalizationsRo extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dartindex 987b31af..874fc1ef 100644--- a/lib/l10n/app_localizations_ru.dart+++ b/lib/l10n/app_localizations_ru.dart@@ -8228,6 +8228,23 @@ class AppLocalizationsRu extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dartindex b6bb99aa..70e628fe 100644--- a/lib/l10n/app_localizations_zh.dart+++ b/lib/l10n/app_localizations_zh.dart@@ -8131,6 +8131,23 @@ class AppLocalizationsZh extends AppLocalizations {return '$_temp0';}+ @override+ String get seriesUpNext => 'Up next';++ @override+ String get seriesStatsFinished => 'Finished';++ @override+ String get seriesStatsListened => 'Listened';++ @override+ String get seriesStatsLeft => 'Left';++ @override+ String seriesFinishedOf(int done, int total) {+ return '$done of $total';+ }+@overrideString get detailSessionsNone => 'No listening sessions yet';diff --git a/lib/widgets/series_books_sheet.dart b/lib/widgets/series_books_sheet.dartindex a92dcd42..81e30935 100644--- a/lib/widgets/series_books_sheet.dart+++ b/lib/widgets/series_books_sheet.dart@@ -2,8 +2,13 @@ import 'dart:io';import 'package:flutter/material.dart';import 'package:flutter/services.dart';import 'package:cached_network_image/cached_network_image.dart';+import 'package:palette_generator/palette_generator.dart';+import '../utils/cover_accent.dart';import 'overlay_toast.dart';import 'swipe_action.dart';+import 'card_buttons.dart' show showErrorToast;+import '../main.dart' show rootNavigatorKey;+import '../screens/app_shell.dart';import 'package:provider/provider.dart';import '../l10n/app_localizations.dart';import 'cover_badges.dart';@@ -37,7 +42,8 @@ void showSeriesBooksSheet(BuildContext context, {}) {showStackableSheet(context: context,- showHandle: true,+ // The sheet draws its own handle inside the cover-tinted header.+ showHandle: false,builder: (ctx, scrollController) => SeriesBooksSheet(seriesName: seriesName,seriesId: seriesId,@@ -93,6 +99,33 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {bool _isDownloadingAll = false;bool _isMarkingAll = false;bool _autoDownloadEnabled = false;++ // The sheet takes its accent from a cover, like the book sheet does, so+ // it isn't a grey page with a name on it.+ ColorScheme? _coverScheme;+ String? _coverSchemeUrl;+ // The library's cover shape setting: portrait tiles in the strip when on.+ bool _rectCovers = false;+ // The header and the view-mode bar scroll with the list, so the jump to+ // the next book measures them instead of guessing.+ final _headerKey = GlobalKey();+ final _barKey = GlobalKey();++ void _maybeDeriveScheme(String url) {+ if (url.isEmpty || _coverSchemeUrl == url || PlayerSettings.einkMode) return;+ _coverSchemeUrl = url;+ final brightness = Theme.of(context).brightness;+ final ImageProvider provider = url.startsWith('/')+ ? FileImage(File(url))+ : CachedNetworkImageProvider(url, headers: context.read<LibraryProvider>().mediaHeaders);+ PaletteGenerator.fromImageProvider(provider, maximumColorCount: 16).then((palette) {+ final seed = accentFromCoverPalette(palette);+ if (seed == null || !mounted) return;+ setState(() => _coverScheme = ColorScheme.fromSeed(seedColor: seed, brightness: brightness));+ }).catchError((e) {+ debugPrint('[SeriesSheet] palette failed: $e');+ });+ }bool _scanExcluded = false;bool _collapseSeries = false;final Set<String> _expandedSubSeries = {};@@ -132,6 +165,9 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {// Don't load sub-series yet - _books may be empty. It triggers after books load.}});+ PlayerSettings.getRectangleCoversFor(widget.libraryId).then((v) {+ if (mounted && v != _rectCovers) setState(() => _rectCovers = v);+ });_lib = context.read<LibraryProvider>();_lib!.addListener(_onLibraryChanged);}@@ -166,8 +202,14 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {if (targetIndex <= 0) return;WidgetsBinding.instance.addPostFrameCallback((_) {if (!mounted || !widget.scrollController.hasClients) return;- // Each book card is ~120px (112 height + 8 bottom padding)- final offset = (targetIndex * 120.0).clamp(+ // Each book card is ~120px (112 height + 8 bottom padding), after the+ // header that scrolls with the list.+ double above = 0;+ for (final key in [_headerKey, _barKey]) {+ final box = key.currentContext?.findRenderObject();+ if (box is RenderBox && box.hasSize) above += box.size.height;+ }+ final offset = (above + targetIndex * 120.0).clamp(0.0,widget.scrollController.position.maxScrollExtent,);@@ -464,18 +506,19 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {Widget _buildGroupedGrid(ColorScheme cs, TextTheme tt, LibraryProvider lib) {final parsed = _buildSubSeriesGroups();- return GridView.builder(- controller: widget.scrollController,+ return SliverPadding(padding: EdgeInsets.fromLTRB(16, 0, 16, 24 + MediaQuery.of(context).viewPadding.bottom),- gridDelegate: sheetBookGridDelegate(context, childAspectRatio: 0.65),- itemCount: parsed.subSeries.length + parsed.standalone.length,- itemBuilder: (context, index) {- if (index < parsed.subSeries.length) {- return GridSeriesTileDirect(series: parsed.subSeries[index], parentSeriesId: widget.seriesId);- }- final book = parsed.standalone[index - parsed.subSeries.length];- return GridBookTile(item: book, sequenceBadge: _getSequenceString(book));- },+ sliver: SliverGrid.builder(+ gridDelegate: sheetBookGridDelegate(context, childAspectRatio: 0.65),+ itemCount: parsed.subSeries.length + parsed.standalone.length,+ itemBuilder: (context, index) {+ if (index < parsed.subSeries.length) {+ return GridSeriesTileDirect(series: parsed.subSeries[index], parentSeriesId: widget.seriesId);+ }+ final book = parsed.standalone[index - parsed.subSeries.length];+ return GridBookTile(item: book, sequenceBadge: _getSequenceString(book));+ },+ ),);}@@ -483,10 +526,9 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {final parsed = _buildSubSeriesGroups();final l = AppLocalizations.of(context)!;- return ListView(- controller: widget.scrollController,+ return SliverPadding(padding: EdgeInsets.fromLTRB(16, 0, 16, 24 + MediaQuery.of(context).viewPadding.bottom),- children: [+ sliver: SliverList(delegate: SliverChildListDelegate([// Sub-series headersfor (final series in parsed.subSeries) ...[() {@@ -543,7 +585,7 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {],// Standalone books...parsed.standalone.map((book) => _buildBookCard(cs, tt, lib, book)),- ],+ ])),);}@@ -795,59 +837,262 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {);}- Widget _buildOverflowMenu(ColorScheme cs) {- final allDone = _allFinished;- final dl = DownloadService();- int downloaded = 0;- for (final book in _books) {- final bookId = book['id'] as String? ?? '';- if (dl.isDownloaded(bookId)) downloaded++;+ /// The first few covers, overlapped, with the book to carry on with in+ /// front.+ Widget _coverStrip(LibraryProvider lib, Color accent, Map<String, dynamic>? nextUp) {+ // Five covers around the book to carry on with, so book 7 of 12 shows+ // its neighbours rather than the first five every time.+ final n = _books.length;+ final count = n < 5 ? n : 5;+ final nextAt = nextUp == null ? 0 : _books.indexOf(nextUp);+ final start = (nextAt - 2).clamp(0, n - count);+ final covers = _books.sublist(start, start + count);+ // Portrait tiles when the library shows rectangle covers.+ final w = _rectCovers ? 58.0 : 76.0;+ final h = _rectCovers ? 86.0 : 76.0;+ final step = w * 0.68;+ final width = w + step * (covers.length - 1);+ final nextId = nextUp?['id'] as String?;+ // Paint order is list order. The covers fan out from the next book:+ // the ones to its left stack towards it, the ones to its right stack+ // back towards it, and it goes last so it sits on top of both sides.+ final nextIdx = covers.indexWhere((b) => b['id'] == nextId);+ final order = <Map<String, dynamic>>[];+ if (nextIdx < 0) {+ order.addAll(covers);+ } else {+ order.addAll(covers.sublist(0, nextIdx));+ order.addAll(covers.sublist(nextIdx + 1).reversed);+ order.add(covers[nextIdx]);}- final allDownloaded = downloaded == _books.length;- final hasSeriesId = widget.seriesId != null && widget.seriesId!.isNotEmpty;-- if (_isMarkingAll || _isDownloadingAll) {- return Padding(- padding: const EdgeInsets.all(12),+ return SizedBox(+ height: h + 8,+ child: Center(child: SizedBox(- width: 18, height: 18,- child: CircularProgressIndicator(strokeWidth: 2, color: cs.primary),+ width: width,+ child: Stack(children: [+ for (final book in order)+ Positioned(+ left: covers.indexOf(book) * step,+ top: book['id'] == nextId ? 0 : 6,+ // The ring is the tile's own background showing around the+ // clipped cover, so it stays clean at the corners.+ child: Container(+ width: w,+ height: h,+ padding: EdgeInsets.all(book['id'] == nextId ? 2 : 1),+ decoration: BoxDecoration(+ color: book['id'] == nextId ? accent : Colors.black.withValues(alpha: 0.25),+ borderRadius: BorderRadius.circular(10),+ boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.35), blurRadius: 8, offset: const Offset(0, 3))],+ ),+ child: ClipRRect(+ borderRadius: BorderRadius.circular(book['id'] == nextId ? 8 : 9),+ child: _coverImage(lib, book['id'] as String? ?? ''),+ ),+ ),+ ),+ ]),),+ ),+ );+ }++ Widget _coverImage(LibraryProvider lib, String bookId) {+ final url = lib.getCoverUrl(bookId);+ if (url == null || url.isEmpty) return const ColoredBox(color: Colors.black26);+ if (url.startsWith('/')) return Image.file(File(url), fit: BoxFit.cover);+ return CachedNetworkImage(+ imageUrl: url,+ httpHeaders: lib.mediaHeaders,+ fit: BoxFit.cover,+ errorWidget: (_, __, ___) => const ColoredBox(color: Colors.black26),+ );+ }++ Widget _stat(String value, String label, ColorScheme cs, TextTheme tt) => Expanded(+ child: Column(children: [+ Text(value, maxLines: 1, overflow: TextOverflow.ellipsis,+ style: tt.titleSmall?.copyWith(fontWeight: FontWeight.w700, color: cs.onSurface)),+ const SizedBox(height: 2),+ Text(label, maxLines: 1, overflow: TextOverflow.ellipsis,+ style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant)),+ ]),);++ /// The next unfinished book as a button filled with the series' progress,+ /// the way the book sheet's Absorb button carries the book's.+ Widget _upNextButton(Map<String, dynamic> book, double progress, int percent,+ Color accent, Color onAccent, TextTheme tt) {+ final l = AppLocalizations.of(context)!;+ final media = book['media'] as Map<String, dynamic>? ?? {};+ final meta = media['metadata'] as Map<String, dynamic>? ?? {};+ final title = meta['title'] as String? ?? '';+ final seq = _getSequenceString(book) ?? '';+ return SizedBox(+ height: 44,+ width: double.infinity,+ child: Material(+ color: accent,+ borderRadius: BorderRadius.circular(14),+ clipBehavior: Clip.antiAlias,+ child: InkWell(+ onTap: () => _playBook(book),+ child: Stack(children: [+ if (progress > 0)+ Positioned.fill(+ child: FractionallySizedBox(+ alignment: Alignment.centerLeft,+ widthFactor: progress.clamp(0.0, 1.0),+ child: Container(color: onAccent.withValues(alpha: 0.22)),+ ),+ ),+ Positioned.fill(+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 14),+ child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [+ Icon(Icons.play_arrow_rounded, size: 22, color: onAccent),+ const SizedBox(width: 8),+ Expanded(+ child: Text(+ '${l.seriesUpNext}${seq.isNotEmpty ? ' #$seq' : ''} · $title',+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: tt.labelLarge?.copyWith(fontWeight: FontWeight.w600, color: onAccent),+ ),+ ),+ if (progress > 0) ...[+ const SizedBox(width: 8),+ Text('$percent%',+ style: tt.labelMedium?.copyWith(fontWeight: FontWeight.w700, color: onAccent.withValues(alpha: 0.85))),+ ],+ ]),+ ),+ ),+ ]),+ ),+ ),+ );+ }++ /// Starts [book] straight from the sheet, the way the book sheet's Absorb+ /// button does: the sheet closes, the Absorbing tab comes up, and the+ /// full item is fetched for its chapters before playback starts.+ Future<void> _playBook(Map<String, dynamic> book) async {+ final id = book['id'] as String? ?? '';+ if (id.isEmpty) return;+ HapticFeedback.selectionClick();+ final api = context.read<AuthProvider>().apiService;+ if (api == null) return;+ final lib = context.read<LibraryProvider>();+ final player = AudioPlayerService();+ final rootNav = Navigator.of(context, rootNavigator: true);+ rootNav.popUntil((route) => route.isFirst);+ if (player.currentItemId == id) {+ if (!player.isPlaying) await player.play(fromUi: true);+ Future.delayed(const Duration(milliseconds: 100), AppShell.goToAbsorbingGlobal);+ return;+ }+ AppShell.goToAbsorbingGlobal();+ // The series listing is a lean item; the full one carries the chapters.+ // Offline or on a failed fetch the lean one still starts the book.+ final full = await api.getLibraryItem(id) ?? book;+ final media = full['media'] as Map<String, dynamic>? ?? {};+ final meta = media['metadata'] as Map<String, dynamic>? ?? {};+ final error = await player.playItem(+ api: api,+ itemId: id,+ title: meta['title'] as String? ?? '',+ author: meta['authorName'] as String? ?? '',+ coverUrl: lib.getCoverUrl(id),+ totalDuration: (media['duration'] as num?)?.toDouble() ?? 0,+ chapters: (media['chapters'] as List<dynamic>?) ?? const [],+ libraryId: full['libraryId'] as String? ?? widget.libraryId,+ fromUi: true,+ );+ if (error != null) {+ final ctx = rootNavigatorKey.currentContext;+ if (ctx != null) showErrorToast(ctx, error);}+ lib.refreshLocalProgress();+ }- return IconButton(- icon: Icon(Icons.more_vert_rounded, color: cs.onSurfaceVariant),- onPressed: () => _showSeriesMoreSheet(cs, allDownloaded, downloaded, allDone, hasSeriesId),+ /// The series actions as a row of pills under the header, in place of+ /// the old three-dot menu. Rolling download shows its state.+ Widget _pillRow(ColorScheme cs, Color accent) {+ if (_isMarkingAll || _isDownloadingAll) {+ return SizedBox(+ height: 34,+ child: Center(child: SizedBox(width: 18, height: 18,+ child: CircularProgressIndicator(strokeWidth: 2, color: accent))),+ );+ }+ final items = _actionPills(context);+ // Wrapped, not scrolled: every action stays in reach with nothing cut+ // off at the edge.+ return Wrap(+ alignment: WrapAlignment.center,+ spacing: 8,+ runSpacing: 8,+ children: [+ for (final p in items)+ () {+ final active = p.tint != null;+ final color = active ? accent : cs.onSurfaceVariant;+ return Material(+ color: active ? accent.withValues(alpha: 0.14) : cs.onSurface.withValues(alpha: 0.06),+ borderRadius: BorderRadius.circular(12),+ clipBehavior: Clip.antiAlias,+ child: InkWell(+ onTap: p.enabled ? p.onTap : null,+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 9),+ child: Row(mainAxisSize: MainAxisSize.min, children: [+ Icon(p.icon, size: 16, color: color),+ const SizedBox(width: 6),+ Text(p.label, style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500, color: color)),+ ]),+ ),+ ),+ );+ }(),+ ],);}- void _showSeriesMoreSheet(ColorScheme cs, bool allDownloaded, int downloaded, bool allDone, bool hasSeriesId) {+ /// The series actions. [tint] set on a pill means it is switched on.+ List<ActionPillData> _actionPills(BuildContext ctx) {final l = AppLocalizations.of(context)!;- showModalBottomSheet(- context: context,- backgroundColor: Theme.of(context).bottomSheetTheme.backgroundColor,- shape: const RoundedRectangleBorder(- borderRadius: BorderRadius.vertical(top: Radius.circular(24)),- ),- builder: (ctx) {- return SafeArea(- child: Padding(- padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),- child: Column(mainAxisSize: MainAxisSize.min, children: [- Center(child: Container(width: 40, height: 4, margin: const EdgeInsets.only(bottom: 16),- decoration: BoxDecoration(color: cs.onSurface.withValues(alpha: 0.24), borderRadius: BorderRadius.circular(2)))),- ActionPillGrid(items: [+ final cs = Theme.of(context).colorScheme;+ final allDone = _allFinished;+ final dl = DownloadService();+ var downloaded = 0;+ for (final book in _books) {+ if (dl.isDownloaded(book['id'] as String? ?? '')) downloaded++;+ }+ final allDownloaded = downloaded == _books.length;+ final hasSeriesId = widget.seriesId != null && widget.seriesId!.isNotEmpty;+ return [+ if (hasSeriesId)+ ActionPillData(+ icon: _autoDownloadEnabled ? Icons.downloading_rounded : Icons.download_outlined,+ label: _autoDownloadEnabled ? l.turnAutoDownloadOff : l.turnAutoDownloadOn,+ tint: _autoDownloadEnabled ? cs.primary : null,+ onTap: () async {+ final lib = context.read<LibraryProvider>();+ await lib.toggleRollingDownload(widget.seriesId!,+ name: widget.seriesName, kind: 'series');+ if (mounted) setState(() => _autoDownloadEnabled = lib.isRollingDownloadEnabled(widget.seriesId!));+ }),if (!allDownloaded)ActionPillData(icon: Icons.download_rounded,label: downloaded > 0 ? l.downloadRemainingCount((_totalBooks > 0 ? _totalBooks : _books.length) - downloaded) : l.downloadAll,- onTap: () { Navigator.pop(ctx); _downloadAll(); }),+ onTap: _downloadAll),ActionPillData(icon: allDone ? Icons.remove_done_rounded : Icons.done_all_rounded,label: allDone ? l.markAllNotFinished : l.markAllFinished,onTap: () async {- Navigator.pop(ctx);if (allDone) {final confirmed = await showDialog<bool>(context: context,@@ -876,35 +1121,18 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {if (confirmed == true) _markAllFinished();}}),- if (hasSeriesId)- ActionPillData(- icon: _autoDownloadEnabled ? Icons.downloading_rounded : Icons.download_outlined,- label: _autoDownloadEnabled ? l.turnAutoDownloadOff : l.turnAutoDownloadOn,- onTap: () async {- Navigator.pop(ctx);- final lib = context.read<LibraryProvider>();- await lib.toggleRollingDownload(widget.seriesId!,- name: widget.seriesName, kind: 'series');- setState(() => _autoDownloadEnabled = lib.isRollingDownloadEnabled(widget.seriesId!));- }),if (hasSeriesId)ActionPillData(icon: _scanExcluded ? Icons.visibility_rounded : Icons.visibility_off_rounded,label: _scanExcluded ? l.seriesIncludeInScan : l.seriesExcludeFromScan,onTap: () async {- Navigator.pop(ctx);final next = !_scanExcluded;await UpcomingReleasesService.setNeverScan(widget.seriesId!, next);if (mounted) setState(() => _scanExcluded = next);}),ActionPillData(icon: Icons.search_rounded, label: l.seriesBooksFindMissingTitle,- onTap: () { Navigator.pop(ctx); _findOnAudible(); }),- ]),- ]),- ),- );- },- );+ onTap: _findOnAudible),+ ];}Future<void> _downloadAll() async {@@ -983,119 +1211,136 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {final seriesProgress = totalDuration > 0 ? (listenedDuration / totalDuration).clamp(0.0, 1.0) : 0.0;final seriesPercent = (seriesProgress * 100).round();- return ClipRect(child: Column(- children: [- // Header row: 3-dot menu pinned top-right- Row(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- const SizedBox(width: 48),- Expanded(- child: Column(- children: [- Icon(Icons.auto_stories_rounded, size: 20, color: cs.primary),- const SizedBox(height: 4),- Text(widget.seriesName,- maxLines: 2,- overflow: TextOverflow.ellipsis,- textAlign: TextAlign.center,- style: tt.titleLarge- ?.copyWith(fontWeight: FontWeight.w600)),- ],- ),- ),- SizedBox(- width: 48,- child: _books.isNotEmpty ? _buildOverflowMenu(cs) : null,- ),- ],+ // What to carry on with, and how far through the series that leaves you.+ Map<String, dynamic>? nextUp;+ var finishedCount = 0;+ for (final book in _books) {+ final bookId = book['id'] as String? ?? '';+ final done = lib.getProgressData(bookId)?['isFinished'] == true || lib.getProgress(bookId) >= 1.0;+ if (done) {+ finishedCount++;+ } else {+ nextUp ??= book;+ }+ }+ final schemeBook = nextUp ?? (_books.isNotEmpty ? _books.first : null);+ if (schemeBook != null) _maybeDeriveScheme(lib.getCoverUrl(schemeBook['id'] as String? ?? '') ?? '');+ final accent = PlayerSettings.einkMode ? cs.primary : (_coverScheme?.primary ?? cs.primary);+ final onAccent = PlayerSettings.einkMode ? cs.onPrimary : (_coverScheme?.onPrimary ?? cs.onPrimary);+ final tint = PlayerSettings.einkMode+ ? Colors.transparent+ : (_coverScheme?.primaryContainer ?? cs.primaryContainer).withValues(alpha: 0.35);++ final bg = Theme.of(context).bottomSheetTheme.backgroundColor ?? cs.surface;+ final listPad = EdgeInsets.fromLTRB(16, 0, 16, 24 + MediaQuery.of(context).viewPadding.bottom);+ Widget fill(Widget child) =>+ SliverFillRemaining(hasScrollBody: false, child: Center(child: child));++ // The sheet paints its own handle so the tint reaches the very top;+ // the whole header scrolls away with the list.+ final header = Container(+ key: _headerKey,+ decoration: BoxDecoration(+ gradient: LinearGradient(+ begin: Alignment.topCenter,+ end: Alignment.bottomCenter,+ colors: [tint, Colors.transparent],),- const SizedBox(height: 4),- Text.rich(- TextSpan(- children: [- TextSpan(- text: () {- final displayDuration = _seriesDuration > totalDuration ? _seriesDuration : totalDuration;- final bookCount = _totalBooks > 0 ? _totalBooks : _books.length;- final base = l.booksInSeriesCount(bookCount);- return displayDuration > 0- ? '$base · ${formatHm(displayDuration)}'- : base;- }(),- ),- if (_autoDownloadEnabled) ...[- const TextSpan(text: ' · '),- WidgetSpan(- alignment: PlaceholderAlignment.middle,- child: Icon(Icons.downloading_rounded, size: 14, color: cs.primary),- ),- ],- ],+ ),+ padding: const EdgeInsets.fromLTRB(16, 0, 16, 6),+ child: Column(children: [+ const SizedBox(height: 12),+ Center(+ child: Container(+ width: 32,+ height: 4,+ decoration: BoxDecoration(+ color: cs.onSurfaceVariant.withValues(alpha: 0.4),+ borderRadius: BorderRadius.circular(2),+ ),),+ ),+ const SizedBox(height: 12),+ if (_books.isNotEmpty) _coverStrip(lib, accent, nextUp),+ const SizedBox(height: 10),+ Text(widget.seriesName,+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ textAlign: TextAlign.center,+ style: tt.titleLarge?.copyWith(fontWeight: FontWeight.w600)),+ const SizedBox(height: 2),+ Text(+ () {+ final displayDuration = _seriesDuration > totalDuration ? _seriesDuration : totalDuration;+ final bookCount = _totalBooks > 0 ? _totalBooks : _books.length;+ final base = l.booksInSeriesCount(bookCount);+ return displayDuration > 0 ? '$base · ${formatHm(displayDuration)}' : base;+ }(),style: tt.bodyMedium?.copyWith(color: cs.onSurfaceVariant),),- SizedBox(height: seriesProgress > 0 ? 4 : 12),- if (seriesProgress > 0)- Padding(- padding: const EdgeInsets.fromLTRB(24, 0, 24, 12),- child: Row(- children: [- Expanded(- child: ClipRRect(- borderRadius: BorderRadius.circular(2),- child: LinearProgressIndicator(- value: seriesProgress,- minHeight: 4,- backgroundColor: cs.surfaceContainerHighest,- valueColor: AlwaysStoppedAnimation(cs.primary),- ),+ if (_books.isNotEmpty) ...[+ const SizedBox(height: 12),+ Row(children: [+ _stat(l.seriesFinishedOf(finishedCount, _totalBooks > 0 ? _totalBooks : _books.length), l.seriesStatsFinished, cs, tt),+ _stat(formatHm(listenedDuration), l.seriesStatsListened, cs, tt),+ _stat(formatHm((totalDuration - listenedDuration).clamp(0.0, double.infinity)), l.seriesStatsLeft, cs, tt),+ ]),+ if (nextUp != null) ...[+ const SizedBox(height: 10),+ _upNextButton(nextUp, seriesProgress, seriesPercent, accent, onAccent, tt),+ ],+ const SizedBox(height: 10),+ _pillRow(cs, accent),+ ],+ ]),+ );++ return Container(+ clipBehavior: Clip.antiAlias,+ decoration: BoxDecoration(+ color: bg,+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),+ ),+ child: ListenableBuilder(+ listenable: DownloadService(),+ builder: (context, _) => CustomScrollView(+ controller: widget.scrollController,+ slivers: [+ SliverToBoxAdapter(child: header),+ if (_books.isNotEmpty)+ SliverToBoxAdapter(+ child: KeyedSubtree(+ key: _barKey,+ child: sheetViewModeBar(+ context,+ gridView: _gridView,+ onChanged: (grid) => setState(() => _gridView = grid),+ padding: const EdgeInsets.symmetric(horizontal: 16),+ leading: IconButton(+ icon: Icon(Icons.collections_bookmark_rounded, size: 20,+ color: _collapseSeries ? cs.primary : cs.onSurfaceVariant),+ visualDensity: VisualDensity.compact,+ tooltip: _collapseSeries ? l.seriesBooksShowAllBooks : l.seriesBooksGroupBySubSeries,+ onPressed: () {+ setState(() {+ _collapseSeries = !_collapseSeries;+ if (_collapseSeries) {+ _expandedSubSeries.clear();+ if (!_subSeriesLoaded) _loadSubSeriesData();+ }+ });+ PlayerSettings.setCollapseBookSeries(_collapseSeries);+ },),),- const SizedBox(width: 10),- Text(- l.percentComplete(seriesPercent.toString()),- style: tt.labelSmall?.copyWith(- color: cs.primary,- fontWeight: FontWeight.w600,- ),),- ],- ),- ),- if (_books.isNotEmpty)- sheetViewModeBar(- context,- gridView: _gridView,- onChanged: (grid) => setState(() => _gridView = grid),- padding: const EdgeInsets.symmetric(horizontal: 16),- leading: IconButton(- icon: Icon(Icons.collections_bookmark_rounded, size: 20,- color: _collapseSeries ? cs.primary : cs.onSurfaceVariant),- visualDensity: VisualDensity.compact,- tooltip: _collapseSeries ? l.seriesBooksShowAllBooks : l.seriesBooksGroupBySubSeries,- onPressed: () {- setState(() {- _collapseSeries = !_collapseSeries;- if (_collapseSeries) {- _expandedSubSeries.clear();- if (!_subSeriesLoaded) _loadSubSeriesData();- }- });- PlayerSettings.setCollapseBookSeries(_collapseSeries);- },- ),- ),- if (_isLoading && _books.isEmpty)- const Expanded(- child: Center(child: CircularProgressIndicator()))- else if (_books.isEmpty && _loadFailed)- Expanded(- child: Center(- child: Column(mainAxisSize: MainAxisSize.min, children: [+ ),+ if (_isLoading && _books.isEmpty)+ fill(const CircularProgressIndicator())+ else if (_books.isEmpty && _loadFailed)+ fill(Column(mainAxisSize: MainAxisSize.min, children: [Text(l.failedToLoad,- style: tt.bodyLarge- ?.copyWith(color: cs.onSurfaceVariant)),+ style: tt.bodyLarge?.copyWith(color: cs.onSurfaceVariant)),TextButton(onPressed: () {setState(() {@@ -1106,65 +1351,42 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {},child: Text(l.retry),),- ]),- ),- )- else if (_books.isEmpty)- Expanded(- child: Center(- child: Text(l.noBooksFound,- style: tt.bodyLarge- ?.copyWith(color: cs.onSurfaceVariant)),- ),- )- else if (_collapseSeries && !_subSeriesLoaded)- Expanded(- child: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [- const CircularProgressIndicator(strokeWidth: 2),- const SizedBox(height: 12),- Text(l.seriesBooksLoadingSubSeries, style: tt.bodySmall?.copyWith(color: cs.onSurface.withValues(alpha: 0.4))),- ])),- )- else if (_collapseSeries && _gridView)- Expanded(- child: ListenableBuilder(- listenable: DownloadService(),- builder: (context, _) => _buildGroupedGrid(cs, tt, lib),- ),- )- else if (_collapseSeries)- Expanded(- child: ListenableBuilder(- listenable: DownloadService(),- builder: (context, _) => _buildGroupedList(cs, tt, lib),- ),- )- else if (_gridView)- Expanded(- child: ListenableBuilder(- listenable: DownloadService(),- builder: (context, _) => GridView.builder(- controller: widget.scrollController,- padding: EdgeInsets.fromLTRB(16, 0, 16, 24 + MediaQuery.of(context).viewPadding.bottom),- gridDelegate: sheetBookGridDelegate(context, childAspectRatio: 0.65),- itemCount: _books.length,- itemBuilder: (context, index) => GridBookTile(item: _books[index], sequenceBadge: _getSequenceString(_books[index])),- ),- ))- else- Expanded(- child: ListenableBuilder(- listenable: DownloadService(),- builder: (context, _) => ListView.builder(- controller: widget.scrollController,- padding: EdgeInsets.fromLTRB(16, 0, 16, 24 + MediaQuery.of(context).viewPadding.bottom),- itemCount: _books.length,- itemBuilder: (context, index) => _buildBookCard(cs, tt, lib, _books[index]),- ),- ),- ),- ],- ));+ ]))+ else if (_books.isEmpty)+ fill(Text(l.noBooksFound,+ style: tt.bodyLarge?.copyWith(color: cs.onSurfaceVariant)))+ else if (_collapseSeries && !_subSeriesLoaded)+ fill(Column(mainAxisSize: MainAxisSize.min, children: [+ const CircularProgressIndicator(strokeWidth: 2),+ const SizedBox(height: 12),+ Text(l.seriesBooksLoadingSubSeries, style: tt.bodySmall?.copyWith(color: cs.onSurface.withValues(alpha: 0.4))),+ ]))+ else if (_collapseSeries && _gridView)+ _buildGroupedGrid(cs, tt, lib)+ else if (_collapseSeries)+ _buildGroupedList(cs, tt, lib)+ else if (_gridView)+ SliverPadding(+ padding: listPad,+ sliver: SliverGrid.builder(+ gridDelegate: sheetBookGridDelegate(context, childAspectRatio: 0.65),+ itemCount: _books.length,+ itemBuilder: (context, index) =>+ GridBookTile(item: _books[index], sequenceBadge: _getSequenceString(_books[index])),+ ),+ )+ else+ SliverPadding(+ padding: listPad,+ sliver: SliverList.builder(+ itemCount: _books.length,+ itemBuilder: (context, index) => _buildBookCard(cs, tt, lib, _books[index]),+ ),+ ),+ ],+ ),+ ),+ );}Widget _buildBookCard(ColorScheme cs, TextTheme tt, LibraryProvider lib, Map<String, dynamic> book) {