A cross platform Audiobookshelf client for Android and iOS
Dart
Replace EBook pill with a customizable Read card button
Barnabas3b80c7104b29
diff --git a/lib/services/player_settings.dart b/lib/services/player_settings.dartindex 0c207b77..d77d6bfd 100644--- a/lib/services/player_settings.dart+++ b/lib/services/player_settings.dart@@ -442,7 +442,7 @@ class PlayerSettings {// ── Card button order ──- static const defaultButtonOrder = ['chapters', 'speed', 'sleep', 'bookmarks', 'details', 'equalizer', 'cast', 'history', 'remove', 'car', 'notes', 'download'];+ static const defaultButtonOrder = ['chapters', 'speed', 'sleep', 'bookmarks', 'details', 'ebook', 'equalizer', 'cast', 'history', 'remove', 'car', 'notes', 'download'];static Future<List<String>> getCardButtonOrder() async {final stored = await ScopedPrefs.getStringList('card_button_order');diff --git a/lib/widgets/absorbing_card.dart b/lib/widgets/absorbing_card.dartindex 4acb4032..354025e0 100644--- a/lib/widgets/absorbing_card.dart+++ b/lib/widgets/absorbing_card.dart@@ -97,8 +97,6 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCliif (fn == null || !fn.contains('.')) return null;return fn.substring(fn.lastIndexOf('.') + 1).toLowerCase();}- String get _ebookLabel => _ebookExt == 'pdf' ? 'PDF' : 'EBook';- IconData get _ebookIcon => _ebookExt == 'pdf' ? Icons.picture_as_pdf_rounded : Icons.menu_book_rounded;List<dynamic> get _chapters {// Prefer fetched chapters (from full item or episode), fall back to inline dataif (_fetchedChapters != null && _fetchedChapters!.isNotEmpty) return _fetchedChapters!;@@ -853,31 +851,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli),),),- if (_ebookFile != null) ...[- const Spacer(flex: 1),- GestureDetector(- onTap: _toggleFlip,- behavior: HitTestBehavior.opaque,- child: Container(- padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),- decoration: BoxDecoration(- color: accent.withValues(alpha: 0.15),- borderRadius: BorderRadius.circular(20),- border: Border.all(color: accent.withValues(alpha: 0.3), width: 1),- ),- child: Row(- mainAxisSize: MainAxisSize.min,- children: [- Icon(_ebookIcon, size: 14, color: accent),- const SizedBox(width: 6),- Text(_ebookLabel, style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: accent)),- ],- ),- ),- ),- const Spacer(flex: 1),- ] else- const Spacer(flex: 2),+ const Spacer(flex: 2),]);},),@@ -1220,6 +1194,9 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCliPlayerSettings.setCardButtonOrder(newOrder);PlayerSettings.setCardButtonVisibleCount(newCount);},+ hasEbook: _ebookFile != null,+ isEbookPdf: _ebookExt == 'pdf',+ onEbookTap: _toggleFlip,);int get _visibleButtonCount => _buttonVisibleCount;diff --git a/lib/widgets/card_button_config.dart b/lib/widgets/card_button_config.dartindex 5b7dcaf7..01b2c259 100644--- a/lib/widgets/card_button_config.dart+++ b/lib/widgets/card_button_config.dart@@ -38,6 +38,8 @@ String localizedCardButtonLabel(AppLocalizations l, CardButtonDef def) {return l.notes;case 'download':return l.download;+ case 'ebook':+ return 'Read';}return def.label;}@@ -58,6 +60,7 @@ const _allCardButtons = [CardButtonDef('car', 'Car Mode', Icons.directions_car_rounded),CardButtonDef('notes', 'Notes', Icons.note_rounded),CardButtonDef('download', 'Download', Icons.download_outlined),+ CardButtonDef('ebook', 'Read', Icons.menu_book_rounded),];/// Card buttons filtered for the current platform.diff --git a/lib/widgets/card_buttons.dart b/lib/widgets/card_buttons.dartindex 971e8b25..1e1e75fd 100644--- a/lib/widgets/card_buttons.dart+++ b/lib/widgets/card_buttons.dart@@ -1329,6 +1329,9 @@ class CardActionDelegate {final VoidCallback removeFromAbsorbing;final VoidCallback? onRemoveExtra;final void Function(List<String>, int) onReorder;+ final bool hasEbook;+ final bool isEbookPdf;+ final VoidCallback? onEbookTap;CardActionDelegate({required this.context,@@ -1356,6 +1359,9 @@ class CardActionDelegate {required this.removeFromAbsorbing,this.onRemoveExtra,required this.onReorder,+ this.hasEbook = false,+ this.isEbookPdf = false,+ this.onEbookTap,});Map<String, dynamic> get _media => item['media'] as Map<String, dynamic>? ?? {};@@ -1579,6 +1585,19 @@ class CardActionDelegate {accent: accent, large: large, compact: compact, iconsOnly: iconsOnly,),);+ case 'ebook':+ return CardWideButton(+ icon: isEbookPdf ? Icons.picture_as_pdf_rounded : Icons.menu_book_rounded,+ label: 'Read',+ accent: accent, isActive: true, alwaysEnabled: true, large: large, compact: compact, iconsOnly: iconsOnly,+ onTap: () {+ if (hasEbook) {+ onEbookTap?.call();+ } else {+ showOverlayToast(context, 'No ebook file for this book', icon: Icons.menu_book_outlined);+ }+ },+ );default:return const SizedBox.shrink();}@@ -1735,6 +1754,19 @@ class CardActionDelegate {);},);+ case 'ebook':+ return MoreMenuItem(+ icon: isEbookPdf ? Icons.picture_as_pdf_rounded : Icons.menu_book_rounded,+ label: 'Read', accent: accent,+ onTap: () {+ Navigator.pop(ctx);+ if (hasEbook) {+ onEbookTap?.call();+ } else {+ showOverlayToast(context, 'No ebook file for this book', icon: Icons.menu_book_outlined);+ }+ },+ );default:return const SizedBox.shrink();}diff --git a/lib/widgets/expanded_card.dart b/lib/widgets/expanded_card.dartindex 04b8470f..d3f61359 100644--- a/lib/widgets/expanded_card.dart+++ b/lib/widgets/expanded_card.dart@@ -14,6 +14,7 @@ import 'absorbing_shared.dart';import 'card_progress_bar.dart';import 'card_playback_controls.dart';import 'card_buttons.dart';+import 'ebook_reader_view.dart';// ─── Custom route: slide-up + fade ────────────────────────────@@ -1038,8 +1039,35 @@ class _ExpandedCardState extends State<ExpandedCard> {PlayerSettings.setCardButtonOrder(newOrder);PlayerSettings.setCardButtonVisibleCount(newCount);},+ hasEbook: _ebookFile != null,+ isEbookPdf: _ebookExt == 'pdf',+ onEbookTap: _openReader,);+ Map<String, dynamic>? get _ebookFile => _media['ebookFile'] as Map<String, dynamic>?;+ String? get _ebookExt {+ final ef = _ebookFile;+ if (ef == null) return null;+ final fn = (ef['metadata'] as Map<String, dynamic>?)?['filename'] as String?+ ?? ef['name'] as String?;+ if (fn == null || !fn.contains('.')) return null;+ return fn.substring(fn.lastIndexOf('.') + 1).toLowerCase();+ }++ void _openReader() {+ final ef = _ebookFile;+ if (ef == null) return;+ Navigator.of(context, rootNavigator: true).push(+ MaterialPageRoute(+ builder: (_) => EbookReaderView(+ itemId: _itemId,+ title: _title,+ ebookFile: ef,+ ),+ ),+ );+ }+int get _visibleButtonCount => _buttonVisibleCount;List<Widget> _buildButtonGrid(Color accent, TextTheme tt) => _makeActions().buildButtonGrid(accent, tt);