A cross platform Audiobookshelf client for Android and iOS
Dart
Merge branch 'main' into card-flip-animation
Barnabasd094e7fad48f
diff --cc lib/widgets/absorbing_card.dartindex 354025e0,67a83220..004138c0--- a/lib/widgets/absorbing_card.dart+++ b/lib/widgets/absorbing_card.dart@@@ -482,59 -463,10 +505,61 @@@ class AbsorbingCardState extends State<_blurredCover?.dispose();_blurredCover = null;}+ // In gradient/off mode the cover image isn't painted, so derive its scheme separately.+ if (_cardBackground != 'blurred') _ensureCoverScheme();final showBookBar = (!_isPodcastEpisode || _chapters.isNotEmpty) && (!lib.isPodcastLibrary || _chapters.isNotEmpty);++ // Build both faces ONCE per parent rebuild (not per animation frame).+ // The AnimatedBuilder below only updates the rotation matrix; the heavy+ // child trees (front content + embedded reader) are stable references.+ final frontFace = _buildFront(context, cs, accent, isDark, l, lib, progress, chapterIdx, totalChapters, bookProgress, showBookBar);+ final backFace = _backInitialized+ ? Transform(+ alignment: Alignment.center,+ // Counter-rotate so back content reads correctly when card is fully flipped.+ transform: Matrix4.identity()..rotateY(3.1415926535),+ child: _buildBack(context, cs, accent, isDark),+ )+ : const SizedBox.shrink();++ return AnimatedBuilder(+ animation: _flipController,+ builder: (context, child) {+ final t = _flipController.value;+ final angle = t * 3.1415926535;+ return Transform(+ alignment: Alignment.center,+ transform: Matrix4.identity()+ ..setEntry(3, 2, 0.0015) // perspective+ ..rotateY(angle),+ child: IndexedStack(+ alignment: Alignment.center,+ sizing: StackFit.passthrough,+ index: t > 0.5 ? 1 : 0,+ children: [frontFace, backFace],+ ),+ );+ },+ );+ }++ Widget _buildFront(+ BuildContext context,+ ColorScheme cs,+ Color accent,+ bool isDark,+ AppLocalizations l,+ LibraryProvider lib,+ double progress,+ int chapterIdx,+ int totalChapters,+ double bookProgress,+ bool showBookBar,+ ) {+ final tt = Theme.of(context).textTheme;+ final mediaHeaders = lib.mediaHeaders;+ final cast = ChromecastService();return GestureDetector(onVerticalDragEnd: (details) {final vy = details.primaryVelocity ?? 0;diff --cc lib/widgets/book_detail_sheet.dartindex 0e84ccd9,7e6eeb15..b17cb37a--- a/lib/widgets/book_detail_sheet.dart+++ b/lib/widgets/book_detail_sheet.dart@@@ -38,9 -40,8 +40,9 @@@ import 'metadata_lookup_sheet.dart'import 'playlist_picker_sheet.dart';import 'collection_picker_sheet.dart';import 'absorb_wave_icon.dart';- import 'edit_metadata_sheet.dart';import 'stackable_sheet.dart';+import 'ebook_reader_view.dart';+ import '../utils/duration_format.dart';// ─── BOOK DETAIL BOTTOM SHEET ───────────────────────────────@@@ -672,6 -699,308 +708,311 @@@ class _BookDetailSheetContentState exte]);}+ // ─── QUICK ACTIONS (long-press) ─────────────────────────────+ // Compact long-press layout: cover + title, an Absorb/Download grid, then+ // the same actions as the detail sheet's "more" menu rendered as pills.+ // Actions run on this (live) sheet context just like the detail sheet, so we+ // never pop-then-touch a defunct context; navigation actions dismiss us.+ Widget _buildQuickContent(BuildContext context, ColorScheme cs, TextTheme tt, AppLocalizations l) {+ final accent = _coverScheme?.primary ?? cs.primary;+ final onAccent = _coverScheme?.onPrimary ?? cs.onPrimary;+ final media = _item!['media'] as Map<String, dynamic>? ?? {};+ final metadata = media['metadata'] as Map<String, dynamic>? ?? {};+ final chapters = media['chapters'] as List<dynamic>? ?? [];+ final title = metadata['title'] as String? ?? l.unknown;+ final authorName = metadata['authorName'] as String? ?? '';+ final duration = (media['duration'] as num?)?.toDouble() ?? 0;+ final serverPath = _item!['path'] as String? ?? _item!['relPath'] as String? ?? '';+ final ebookFile = media['ebookFile'] as Map<String, dynamic>?;+ final isEbookOnly = PlayerSettings.isEbookOnly(_item!);++ final lib = context.watch<LibraryProvider>();+ final auth = context.read<AuthProvider>();+ final progress = lib.getProgress(widget.itemId);+ final progressData = lib.getProgressData(widget.itemId);+ final isFinished = progressData?['isFinished'] == true;+ final currentTime = (progressData?['currentTime'] as num?)?.toDouble() ?? 0;++ // Continue-shelf actions (mirror the detail sheet's more menu).+ final inContinueListening = lib.isInContinueListeningShelf(widget.itemId);+ final rawSeries = ((_item?['media'] as Map<String, dynamic>?)?['metadata']+ as Map<String, dynamic>?)?['series'];+ final bookSeriesIds = <String>[];+ if (rawSeries is List) {+ for (final s in rawSeries.whereType<Map<String, dynamic>>()) {+ final id = (s['id'] as String? ?? '').trim();+ if (id.isNotEmpty) bookSeriesIds.add(id);+ }+ } else if (rawSeries is Map<String, dynamic>) {+ final id = (rawSeries['id'] as String? ?? '').trim();+ if (id.isNotEmpty) bookSeriesIds.add(id);+ }+ final continueSeriesId = lib.continueSeriesShelfMatch(bookSeriesIds);++ return ListView(+ controller: widget.scrollController,+ padding: EdgeInsets.fromLTRB(20, 8, 20, 24 + MediaQuery.of(context).viewPadding.bottom),+ 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)))),+ // Header: cover thumb + title/author+ Row(crossAxisAlignment: CrossAxisAlignment.center, children: [+ _quickThumb(56, lib.mediaHeaders, cs),+ const SizedBox(width: 12),+ Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [+ Text(title, maxLines: 2, overflow: TextOverflow.ellipsis,+ style: tt.titleMedium?.copyWith(fontWeight: FontWeight.w700, color: cs.onSurface)),+ if (authorName.isNotEmpty) ...[+ const SizedBox(height: 2),+ Text(authorName, maxLines: 1, overflow: TextOverflow.ellipsis,+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),+ ],+ ])),+ ]),+ const SizedBox(height: 18),+ // Primary actions: Absorb | Download side by side+ if (!isEbookOnly)+ Row(children: [+ Expanded(child: _quickAbsorbButton(context, cs, tt, auth, accent, onAccent, title, authorName, duration, chapters, isFinished)),+ const SizedBox(width: 10),+ Expanded(child: DownloadWideButton(itemId: widget.itemId, coverUrl: _coverUrl, title: title, author: authorName, accent: accent)),+ ])+ else+ SizedBox(height: 44, child: Center(child: Text(l.ebookOnlyNoAudio,+ style: tt.bodyMedium?.copyWith(color: cs.onSurfaceVariant, fontWeight: FontWeight.w600)))),+ const SizedBox(height: 10),+ // Mark finished toggle+ _quickFinishedPill(context, cs, auth, isFinished, currentTime, duration),+ const SizedBox(height: 18),+ // Secondary actions as the shared responsive pill grid. The quick sheet+ // stays open behind navigation actions, so dismiss is a no-op here.+ _actionPillGrid(context, cs, tt, l, auth, lib, title, authorName, progress,+ isFinished, duration, ebookFile, isEbookOnly, serverPath, inContinueListening,+ continueSeriesId, dismiss: () {}, includeOpenDetails: true),+ ],+ );+ }++ /// The book's secondary actions as a responsive pill grid (admin-Users-page+ /// style). Shared by the long-press quick sheet and the detail sheet's+ /// overflow menu. [dismiss] closes the surrounding sheet before an action+ /// runs (the overflow menu pops itself; the quick sheet passes a no-op and+ /// stays open). [includeOpenDetails] adds a "Book Details" pill (quick sheet+ /// only — pointless when you're already in the detail sheet).+ Widget _actionPillGrid(BuildContext context, ColorScheme cs, TextTheme tt, AppLocalizations l,+ AuthProvider auth, LibraryProvider lib, String title, String authorName, double progress,+ bool isFinished, double duration, Map<String, dynamic>? ebookFile, bool isEbookOnly,+ String serverPath, bool inContinueListening, String? continueSeriesId,+ {required VoidCallback dismiss, bool includeOpenDetails = false}) {+ final onAbsorbing = lib.isOnAbsorbingList(widget.itemId);+ return Column(mainAxisSize: MainAxisSize.min, children: [+ LayoutBuilder(builder: (ctx, constraints) {+ const gap = 10.0;+ // Responsive grid: 3 pills across normally, but drop to 2 on a narrow+ // screen or when the system font is scaled up, so labels keep room to+ // show in full. Cell height tracks the text scale so 2-line labels at a+ // large zoom don't get clipped.+ final textScale = MediaQuery.textScalerOf(context).scale(1.0);+ final cols = (constraints.maxWidth < 340 || textScale >= 1.3) ? 2 : 3;+ final cellW = (constraints.maxWidth - gap * (cols - 1)) / cols;+ final cellH = (cols == 2 ? 72.0 : 80.0) * textScale.clamp(1.0, 1.7) + 8;+ final pills = <Widget>[];+ void add(IconData icon, String label, VoidCallback onTap, {Color? tint}) {+ pills.add(SizedBox(width: cellW, height: cellH,+ child: _quickPill(cs, tt, icon, label, () { dismiss(); onTap(); }, tint: tint)));+ }+ add(onAbsorbing ? Icons.remove_circle_outline_rounded : Icons.add_circle_outline_rounded,+ onAbsorbing ? Wording.of(context).removeFromAbsorbing : Wording.of(context).addToAbsorbing, () async {+ if (onAbsorbing) {+ await lib.removeFromAbsorbing(widget.itemId);+ HapticFeedback.mediumImpact();+ if (context.mounted) showOverlayToast(context, Wording.of(context).removedFromAbsorbing, icon: Icons.remove_circle_outline_rounded);+ } else {+ await lib.addToAbsorbingQueue(widget.itemId);+ if (_item != null) {+ final cached = Map<String, dynamic>.from(_item!);+ cached['_absorbingKey'] = widget.itemId;+ lib.absorbingItemCache[widget.itemId] = cached;+ }+ HapticFeedback.mediumImpact();+ if (context.mounted) showOverlayToast(context, Wording.of(context).addedToAbsorbing, icon: Icons.add_circle_outline_rounded);+ }+ });+ if (!lib.isOffline) {+ add(Icons.playlist_add_rounded, l.addToPlaylist, () => PlaylistPickerSheet.show(context, widget.itemId));+ }+ if (!lib.isOffline && !lib.isPodcastLibrary && auth.isAdmin) {+ add(Icons.collections_bookmark_rounded, l.addToCollection, () => CollectionPickerSheet.show(context, widget.itemId));+ }++ if (ebookFile != null) {++ add(Icons.menu_book_rounded, 'Read eBook', () => _openEbookReader(context, auth, ebookFile, title));++ }+ if (ebookFile != null) {+ add(_ebookSaved ? Icons.download_done_rounded : Icons.save_alt_rounded,+ _ebookSaved ? l.downloadEbookAgain : l.downloadEbook, () => _saveEbook(context, auth, ebookFile, title));+ }+ if (ebookFile != null && auth.ereaderDevices.isNotEmpty) {+ add(Icons.send_to_mobile_rounded, l.sendToEreader, () => _sendToEreader(context, auth));+ }+ if (progress > 0 || isFinished) {+ add(Icons.restart_alt_rounded, l.resetProgress, () => _resetProgress(context, auth, duration));+ }+ if (inContinueListening && !lib.isOffline) {+ add(Icons.playlist_remove_rounded, l.removeFromContinueListening, () => _removeFromContinueListening(context, auth, lib));+ }+ if (continueSeriesId != null && !lib.isOffline) {+ add(Icons.bookmark_remove_rounded, l.removeSeriesFromContinueSeries, () => _removeSeriesFromContinueSeries(context, auth, lib, continueSeriesId));+ }+ if (auth.apiService != null && !lib.isOffline) {+ add(Icons.manage_search_rounded, _hasLocalOverride ? l.reLookupLocalMetadata : l.lookupLocalMetadata,+ () => _openMetadataLookup(context, auth, title, authorName));+ }+ if (_hasLocalOverride) {+ add(Icons.layers_clear_rounded, l.clearLocalMetadata, () => _clearOverride(context));+ }+ if (_showGoodreads) {+ add(Icons.local_library_rounded, l.searchOnGoodreads, () => _openGoodreads(title, authorName));+ }+ if (auth.canUpdateMetadata && !lib.isOffline) {+ add(Icons.edit_rounded, l.edit, () => _openEditPage(auth, title, isEbookOnly));+ }+ if (includeOpenDetails) {+ add(Icons.open_in_full_rounded, l.bookDetailsLabel, () {+ final rc = rootNavigatorKey.currentContext;+ Navigator.of(context).pop();+ if (rc != null) showBookDetailSheet(rc, widget.itemId);+ });+ }+ return Wrap(spacing: gap, runSpacing: gap, children: pills);+ }),+ if (auth.isAdmin && serverPath.isNotEmpty) ...[+ const SizedBox(height: 10),+ GestureDetector(+ onTap: () {+ dismiss();+ Clipboard.setData(ClipboardData(text: serverPath));+ HapticFeedback.lightImpact();+ },+ child: Text(serverPath, maxLines: 1, overflow: TextOverflow.ellipsis, textAlign: TextAlign.center,+ style: TextStyle(color: cs.onSurface.withValues(alpha: 0.25), fontSize: 11)),+ ),+ ],+ ]);+ }++ Widget _quickThumb(double size, Map<String, String> headers, ColorScheme cs) {+ final url = _coverUrl;+ Widget img;+ if (url == null) {+ img = Container(color: cs.surfaceContainerHighest,+ child: Icon(Icons.headphones_rounded, size: 24, color: cs.onSurfaceVariant.withValues(alpha: 0.4)));+ } else if (url.startsWith('/')) {+ img = Image.file(File(url), fit: BoxFit.cover,+ errorBuilder: (_, __, ___) => Container(color: cs.surfaceContainerHighest));+ } else {+ img = CachedNetworkImage(imageUrl: url, fit: BoxFit.cover, httpHeaders: headers,+ placeholder: (_, __) => Container(color: cs.surfaceContainerHighest),+ errorWidget: (_, __, ___) => Container(color: cs.surfaceContainerHighest));+ }+ return ClipRRect(borderRadius: BorderRadius.circular(10),+ child: SizedBox(width: size, height: size, child: img));+ }++ Widget _quickAbsorbButton(BuildContext context, ColorScheme cs, TextTheme tt, AuthProvider auth,+ Color accent, Color onAccent, String title, String author, double duration, List<dynamic> chapters, bool isFinished) {+ return ListenableBuilder(+ listenable: AudioPlayerService(),+ builder: (_, __) {+ final player = AudioPlayerService();+ final isCurrentPlaying = player.currentItemId == widget.itemId && player.isPlaying;+ final showAbsorbingState = _isAbsorbing || isCurrentPlaying;+ return GestureDetector(+ onTap: showAbsorbingState+ ? () {+ Navigator.of(context).popUntil((route) => route.isFirst);+ AppShell.goToAbsorbingGlobal();+ }+ : () {+ setState(() => _isAbsorbing = true);+ _startAbsorb(context, auth: auth, title: title, author: author,+ coverUrl: _coverUrl, duration: duration, chapters: chapters);+ },+ child: Container(+ height: 36,+ decoration: BoxDecoration(color: accent, borderRadius: BorderRadius.circular(14)),+ child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [+ showAbsorbingState+ ? SizedBox(width: 16, height: 16, child: AbsorbingWave(color: onAccent))+ : isFinished+ ? AbsorbReplayIcon(size: 16, color: onAccent)+ : Icon(Icons.waves_rounded, size: 16, color: onAccent),+ const SizedBox(width: 8),+ Flexible(child: Text(+ showAbsorbingState+ ? Wording.of(context).absorbing+ : isFinished+ ? Wording.of(context).absorbAgain+ : Wording.of(context).absorb,+ maxLines: 1, overflow: TextOverflow.ellipsis,+ style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: onAccent),+ )),+ ]),+ ),+ );+ },+ );+ }++ Widget _quickFinishedPill(BuildContext context, ColorScheme cs, AuthProvider auth,+ bool isFinished, double currentTime, double duration) {+ return GestureDetector(+ onTap: () => isFinished+ ? _markNotFinished(context, auth, currentTime, duration)+ : _markFinished(context, auth, duration),+ child: Container(+ height: 36,+ decoration: BoxDecoration(+ color: isFinished ? Colors.green.withValues(alpha: 0.06) : cs.onSurface.withValues(alpha: 0.06),+ borderRadius: BorderRadius.circular(14),+ border: Border.all(color: isFinished ? Colors.green.withValues(alpha: 0.15) : cs.onSurface.withValues(alpha: 0.08)),+ ),+ child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [+ Icon(isFinished ? Icons.check_circle_rounded : Icons.check_circle_outline_rounded,+ size: 16, color: isFinished ? Colors.green : cs.onSurfaceVariant),+ const SizedBox(width: 8),+ Flexible(child: Text(isFinished ? Wording.of(context).fullyAbsorbed : Wording.of(context).fullyAbsorbAction,+ maxLines: 1, overflow: TextOverflow.ellipsis,+ style: TextStyle(color: isFinished ? Colors.green : cs.onSurfaceVariant, fontSize: 13, fontWeight: FontWeight.w500))),+ ]),+ ),+ );+ }++ // Grid pill styled like the admin Users page cells: rounded card, centered+ // icon over a short label, fixed height so the Wrap rows line up.+ Widget _quickPill(ColorScheme cs, TextTheme tt, IconData icon, String label, VoidCallback onTap, {Color? tint}) {+ final iconColor = tint ?? cs.onSurfaceVariant;+ return GestureDetector(+ onTap: onTap,+ child: Container(+ padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 10),+ decoration: BoxDecoration(+ color: cs.surfaceContainerHigh,+ borderRadius: BorderRadius.circular(16),+ border: Border.all(color: cs.onSurface.withValues(alpha: 0.08)),+ ),+ child: Column(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, children: [+ Icon(icon, size: 22, color: iconColor),+ const SizedBox(height: 7),+ // Loose Flexible so an extra-long label ellipsises inside the cell at+ // big font scales rather than overflowing the fixed cell height.+ Flexible(child: Text(label, textAlign: TextAlign.center, maxLines: 2, overflow: TextOverflow.ellipsis,+ style: tt.labelSmall?.copyWith(color: cs.onSurface, fontWeight: FontWeight.w500, height: 1.15, fontSize: 11))),+ ]),+ ),+ );+ }+void _showMoreSheet(BuildContext context, AuthProvider auth, LibraryProvider lib,String title, String authorName, double progress, bool isFinished,double duration, Map<String, dynamic>? ebookFile, bool isEbookOnly, String serverPath) {