A cross platform Audiobookshelf client for Android and iOS
Dart
Show the download prompt as soon as you tap Export clip on iPhone
Barnabasf09a82c720d0
diff --git a/lib/widgets/bookmark_detail_dialog.dart b/lib/widgets/bookmark_detail_dialog.dartindex 0ed8dab8..679a9b92 100644--- a/lib/widgets/bookmark_detail_dialog.dart+++ b/lib/widgets/bookmark_detail_dialog.dart@@ -1,9 +1,14 @@+import 'dart:io';+import 'package:flutter/material.dart';+import 'package:provider/provider.dart';import '../l10n/app_localizations.dart';+import '../providers/library_provider.dart';import '../services/api_service.dart';import '../services/bookmark_service.dart';import '../services/bookmark_preview_player.dart';+import '../services/download_service.dart';import 'clip_editor_sheet.dart';/// Result of [BookmarkDetailSheet]. [action] is 'jump' (caller should seek@@ -96,6 +101,13 @@ class _BookmarkDetailSheetState extends State<BookmarkDetailSheet> {Future<void> _openClipEditor() async {await _preview.stop();if (!mounted) return;+ // iOS can't export from a streaming book, so prompt to download up front+ // rather than letting the user trim a clip and only fail at Save. Android+ // exports streamed clips fine, so it always opens the editor.+ if (Platform.isIOS && !DownloadService().isDownloaded(widget.itemId)) {+ await _promptDownload();+ return;+ }await showModalBottomSheet<void>(context: context,isScrollControlled: true,@@ -114,6 +126,51 @@ class _BookmarkDetailSheetState extends State<BookmarkDetailSheet> {);}+ Future<void> _promptDownload() async {+ final l = AppLocalizations.of(context)!;+ final go = await showDialog<bool>(+ context: context,+ builder: (ctx) => AlertDialog(+ content: Text(l.clipDownloadToExport),+ actions: [+ TextButton(+ onPressed: () => Navigator.pop(ctx, false),+ child: Text(l.cancel),+ ),+ FilledButton(+ onPressed: () => Navigator.pop(ctx, true),+ child: Text(l.download),+ ),+ ],+ ),+ );+ if (go == true) await _startDownload();+ }++ Future<void> _startDownload() async {+ final api = widget.api;+ if (api == null) return;+ final libraryId = context.read<LibraryProvider>().selectedLibraryId;+ var title =+ _titleC.text.trim().isEmpty ? widget.bookmark.title : _titleC.text.trim();+ var author = '';+ try {+ final item = await api.getLibraryItem(widget.itemId);+ final meta = (item?['media'] as Map<String, dynamic>?)?['metadata']+ as Map<String, dynamic>?;+ title = meta?['title'] as String? ?? title;+ author = meta?['authorName'] as String? ?? '';+ } catch (_) {}+ await DownloadService().downloadItem(+ api: api,+ itemId: widget.itemId,+ title: title,+ author: author,+ coverUrl: api.getCoverUrl(widget.itemId, width: 400),+ libraryId: libraryId,+ );+ }+Future<void> _persist() async {setState(() => _saving = true);await _preview.stop();diff --git a/lib/widgets/clip_editor_sheet.dart b/lib/widgets/clip_editor_sheet.dartindex ffc1c22d..121dce5e 100644--- a/lib/widgets/clip_editor_sheet.dart+++ b/lib/widgets/clip_editor_sheet.dart@@ -3,14 +3,11 @@ import 'dart:typed_data';import 'package:file_picker/file_picker.dart';import 'package:flutter/material.dart';-import 'package:provider/provider.dart';import '../l10n/app_localizations.dart';-import '../providers/library_provider.dart';import '../services/api_service.dart';import '../services/clip_editor_controller.dart';import '../services/clip_export_service.dart';-import '../services/download_service.dart';/// Play-and-mark clip editor. Opened from the bookmark sheet's "Export clip"./// Plays a navigable window around the bookmark; the user marks in/out by ear@@ -117,11 +114,6 @@ class _ClipEditorSheetState extends State<ClipEditorSheet> {debugPrint('[ClipEditor] save failed: $e');if (!mounted) return;setState(() => _saving = false);- // iOS can't export from a streaming URL - offer to download the book.- if (e is ClipExportException && e.code == 'needs_download') {- await _promptDownload();- return;- }// Show the reason in a dialog rather than a SnackBar: the editor is a// bottom sheet, and on iPad a SnackBar shown from within it hides behind// the sheet, so a failure looked like "nothing happened".@@ -142,56 +134,6 @@ class _ClipEditorSheetState extends State<ClipEditorSheet> {}}- // iOS streamed export isn't possible, so offer to download the book; the user- // re-exports once it finishes. Cancel just closes the dialog.- Future<void> _promptDownload() async {- final l = AppLocalizations.of(context)!;- final go = await showDialog<bool>(- context: context,- builder: (ctx) => AlertDialog(- content: Text(l.clipDownloadToExport),- actions: [- TextButton(- onPressed: () => Navigator.pop(ctx, false),- child: Text(l.cancel),- ),- FilledButton(- onPressed: () => Navigator.pop(ctx, true),- child: Text(l.download),- ),- ],- ),- );- if (go == true) await _startDownload();- }-- Future<void> _startDownload() async {- final api = widget.api;- if (api == null) return;- final navigator = Navigator.of(context);- final libraryId = context.read<LibraryProvider>().selectedLibraryId;- var title = widget.bookmarkTitle;- var author = '';- try {- final item = await api.getLibraryItem(widget.itemId);- final meta = (item?['media'] as Map<String, dynamic>?)?['metadata']- as Map<String, dynamic>?;- title = meta?['title'] as String? ?? title;- author = meta?['authorName'] as String? ?? '';- } catch (_) {}- await DownloadService().downloadItem(- api: api,- itemId: widget.itemId,- title: title,- author: author,- coverUrl: api.getCoverUrl(widget.itemId, width: 400),- libraryId: libraryId,- );- // Close the editor - the user re-exports once the download finishes (the- // download has its own progress notification).- if (mounted) navigator.pop();- }-@overrideWidget build(BuildContext context) {final l = AppLocalizations.of(context)!;