From c3a0fa66897c48feb0ba19843f99f1e5f083ba36 Mon Sep 17 00:00:00 2001 From: niuhuan Date: Sat, 25 Feb 2023 18:05:37 +0800 Subject: [PATCH] :sparkles: Export bare JPEG.ZIP --- lib/basic/Method.dart | 21 +- lib/screens/DownloadExportToFileScreen.dart | 322 ++++++++++++++++++++ pubspec.lock | 60 ++-- 3 files changed, 369 insertions(+), 34 deletions(-) diff --git a/lib/basic/Method.dart b/lib/basic/Method.dart index 6da2933..8c82203 100644 --- a/lib/basic/Method.dart +++ b/lib/basic/Method.dart @@ -582,10 +582,10 @@ class Method { /// 导出下载的图片到HTML+JPG Future exportComicDownloadToJPG( - String comicId, - String dir, - String name, - ) { + String comicId, + String dir, + String name, + ) { return _flatInvoke("exportComicDownloadToJPG", { "comicId": comicId, "dir": dir, @@ -593,6 +593,19 @@ class Method { }); } + /// 导出下载的图片到HTML+JPG + Future exportComicDownloadJpegZip( + String comicId, + String dir, + String name, + ) { + return _flatInvoke("exportComicDownloadJpegZip", { + "comicId": comicId, + "dir": dir, + "name": name, + }); + } + /// 导出下载的图片到PKZ Future exportComicDownloadToPkz( List comicIds, diff --git a/lib/screens/DownloadExportToFileScreen.dart b/lib/screens/DownloadExportToFileScreen.dart index 80d9b77..3cd9ff1 100644 --- a/lib/screens/DownloadExportToFileScreen.dart +++ b/lib/screens/DownloadExportToFileScreen.dart @@ -453,6 +453,328 @@ class _DownloadExportToFileScreenState return widgets; } + List _buildExportToJpegZipButtons() { + List widgets = []; + if (Platform.isWindows || + Platform.isMacOS || + Platform.isLinux || + Platform.isAndroid) { + widgets.add(MaterialButton( + onPressed: () async { + late String? path; + try { + path = Platform.isIOS + ? await method.iosGetDocumentDir() + : await chooseFolder(context); + } catch (e) { + defaultToast(context, "$e"); + return; + } + var name = ""; + if (currentExportRename()) { + var rename = await inputString( + context, + "请输入保存后的名称", + defaultValue: _task.title, + ); + if (rename != null && rename.isNotEmpty) { + name = rename; + } else { + return; + } + } + print("path $path"); + if (path != null) { + try { + setState(() { + exporting = true; + }); + await method.exportComicDownloadJpegZip( + widget.comicId, + path, + name, + ); + setState(() { + exportResult = "导出成功"; + }); + } catch (e) { + setState(() { + exportResult = "导出失败 $e"; + }); + } finally { + setState(() { + exporting = false; + }); + } + } + }, + child: _buildButtonInner('导出阅读器用JPGS.zip\n(不可再导入)'), + )); + widgets.add(Container(height: 10)); + ///////////////////// + widgets.add(MaterialButton( + onPressed: () async { + late String? path; + try { + path = Platform.isIOS + ? await method.iosGetDocumentDir() + : await chooseFolder(context); + } catch (e) { + defaultToast(context, "$e"); + return; + } + var name = ""; + if (currentExportRename()) { + var rename = await inputString( + context, + "请输入保存后的名称", + defaultValue: _task.title, + ); + if (rename != null && rename.isNotEmpty) { + name = rename; + } else { + return; + } + } + print("path $path"); + if (path != null) { + try { + setState(() { + exporting = true; + }); + await method.exportComicDownloadToPkz( + [widget.comicId], + path, + name, + ); + setState(() { + exportResult = "导出成功"; + }); + } catch (e) { + setState(() { + exportResult = "导出失败 $e"; + }); + } finally { + setState(() { + exporting = false; + }); + } + } + }, + child: + _buildButtonInner('导出到xxx.pkz\n(可直接打开观看的格式,不支持导入)\n(可以躲避网盘或者聊天软件的扫描)'), + )); + widgets.add(Container(height: 10)); + ///////////////////// + ///////////////////// + widgets.add(MaterialButton( + onPressed: () async { + late String? path; + try { + path = Platform.isIOS + ? await method.iosGetDocumentDir() + : await chooseFolder(context); + } catch (e) { + defaultToast(context, "$e"); + return; + } + var name = ""; + if (currentExportRename()) { + var rename = await inputString( + context, + "请输入保存后的名称", + defaultValue: _task.title, + ); + if (rename != null && rename.isNotEmpty) { + name = rename; + } else { + return; + } + } + print("path $path"); + if (path != null) { + try { + setState(() { + exporting = true; + }); + await method.exportComicDownloadToPki( + widget.comicId, + path, + name, + ); + setState(() { + exportResult = "导出成功"; + }); + } catch (e) { + setState(() { + exportResult = "导出失败 $e"; + }); + } finally { + setState(() { + exporting = false; + }); + } + } + }, + child: + _buildButtonInner('导出到xxx.pki\n(只支持导入, 不支持直接阅读)\n(可以躲避网盘或者聊天软件的扫描)\n(后期版本可能支持直接阅读)'), + )); + widgets.add(Container(height: 10)); + ///////////////////// + widgets.add(MaterialButton( + onPressed: () async { + late String? path; + try { + path = Platform.isIOS + ? await method.iosGetDocumentDir() + : await chooseFolder(context); + } catch (e) { + defaultToast(context, "$e"); + return; + } + var name = ""; + if (currentExportRename()) { + var rename = await inputString( + context, + "请输入保存后的名称", + defaultValue: _task.title, + ); + if (rename != null && rename.isNotEmpty) { + name = rename; + } else { + return; + } + } + print("path $path"); + if (path != null) { + try { + setState(() { + exporting = true; + }); + await method.exportComicDownload( + widget.comicId, + path, + name, + ); + setState(() { + exportResult = "导出成功"; + }); + } catch (e) { + setState(() { + exportResult = "导出失败 $e"; + }); + } finally { + setState(() { + exporting = false; + }); + } + } + }, + child: _buildButtonInner('导出到HTML.zip\n(可从其他设备导入 / 解压后可阅读)'), + )); + widgets.add(Container(height: 10)); + ////////////////////// + widgets.add(MaterialButton( + onPressed: () async { + late String? path; + try { + path = Platform.isIOS + ? await method.iosGetDocumentDir() + : await chooseFolder(context); + } catch (e) { + defaultToast(context, "$e"); + return; + } + var name = ""; + if (currentExportRename()) { + var rename = await inputString( + context, + "请输入保存后的名称", + defaultValue: _task.title, + ); + if (rename != null && rename.isNotEmpty) { + name = rename; + } else { + return; + } + } + print("path $path"); + if (path != null) { + try { + setState(() { + exporting = true; + }); + await method.exportComicJpegsEvenNotFinish( + widget.comicId, + path, + name, + ); + setState(() { + exportResult = "导出成功"; + }); + } catch (e) { + setState(() { + exportResult = "导出失败 $e"; + }); + } finally { + setState(() { + exporting = false; + }); + } + } + }, + child: _buildButtonInner('导出到HTML+JPG\n(即使没有下载成功)'), + )); + widgets.add(Container(height: 10)); + } + if (Platform.isIOS || Platform.isAndroid) { + widgets.add(MaterialButton( + onPressed: () async { + if (!(await confirmDialog(context, "导出确认", "将本漫画所有图片到相册?"))) { + return; + } + if (!(await Permission.storage.request()).isGranted) { + return; + } + try { + setState(() { + exporting = true; + }); + // 导出所有图片数据 + var count = 0; + List eps = await method.downloadEpList(widget.comicId); + for (var i = 0; i < eps.length; i++) { + var pics = await method.downloadPicturesByEpId(eps[i].id); + for (var j = 0; j < pics.length; j++) { + setState(() { + exportMessage = "导出图片 ${count++} 张"; + }); + await saveImageQuiet( + await method.downloadImagePath(pics[j].localPath), + context, + ); + } + } + setState(() { + exportResult = "导出成功"; + }); + } catch (e) { + setState(() { + exportResult = "导出失败 $e"; + }); + } finally { + setState(() { + exporting = false; + }); + } + }, + child: _buildButtonInner('将所有图片导出到手机相册'), + )); + widgets.add(Container(height: 10)); + } + return widgets; + } + Widget _buildButtonInner(String text) { return LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { diff --git a/pubspec.lock b/pubspec.lock index 325f835..06035e3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -175,10 +175,10 @@ packages: dependency: transitive description: name: flutter_plugin_android_lifecycle - sha256: "60fc7b78455b94e6de2333d2f95196d32cf5c22f4b0b0520a628804cb463503b" + sha256: "4bef634684b2c7f3468c77c766c831229af829a0cd2d4ee6c1b99558bd14e5d2" url: "https://pub.dev" source: hosted - version: "2.0.7" + version: "2.0.8" flutter_search_bar: dependency: "direct main" description: @@ -249,42 +249,42 @@ packages: dependency: "direct main" description: name: image_picker - sha256: f98d76672d309c8b7030c323b3394669e122d52b307d2bbd8d06bd70f5b2aabe + sha256: "22207768556b82d55ec70166824350fee32298732d5efa4d6e756f848f51f66a" url: "https://pub.dev" source: hosted - version: "0.8.6+1" + version: "0.8.6+3" image_picker_android: dependency: transitive description: name: image_picker_android - sha256: "385f12ee9c7288575572c7873a332016ec45ebd092e1c2f6bd421b4a9ad21f1d" + sha256: "68d067baf7f6e401b1124ee83dd6967e67847314250fd68012aab34a69beb344" url: "https://pub.dev" source: hosted - version: "0.8.5+6" + version: "0.8.5+7" image_picker_for_web: dependency: transitive description: name: image_picker_for_web - sha256: "7d319fb74955ca46d9bf7011497860e3923bb67feebcf068f489311065863899" + sha256: "66fc6e3877bbde82c33d122f3588777c3784ac5bd7d1cdd79213ef7aecb85b34" url: "https://pub.dev" source: hosted - version: "2.1.10" + version: "2.1.11" image_picker_ios: dependency: transitive description: name: image_picker_ios - sha256: "8ffb14b43713d7c43fb21299cc18181cc5b39bd3ea1cc427a085c6400fe5aa52" + sha256: "39aa70b5f1e5e7c94585b9738632d5fdb764a5655e40cd9e7b95fbd2fc50c519" url: "https://pub.dev" source: hosted - version: "0.8.6+7" + version: "0.8.6+9" image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface - sha256: "7cef2f28f4f2fef99180f636c3d446b4ccbafd6ba0fad2adc9a80c4040f656b8" + sha256: "1991219d9dbc42a99aff77e663af8ca51ced592cd6685c9485e3458302d3d4f8" url: "https://pub.dev" source: hosted - version: "2.6.2" + version: "2.6.3" intl: dependency: transitive description: @@ -441,10 +441,10 @@ packages: dependency: transitive description: name: plugin_platform_interface - sha256: dbf0f707c78beedc9200146ad3cb0ab4d5da13c246336987be6940f026500d3a + sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc" url: "https://pub.dev" source: hosted - version: "2.1.3" + version: "2.1.4" pointycastle: dependency: transitive description: @@ -558,66 +558,66 @@ packages: dependency: "direct main" description: name: url_launcher - sha256: e8f2efc804810c0f2f5b485f49e7942179f56eabcfe81dce3387fec4bb55876b + sha256: "75f2846facd11168d007529d6cd8fcb2b750186bea046af9711f10b907e1587e" url: "https://pub.dev" source: hosted - version: "6.1.9" + version: "6.1.10" url_launcher_android: dependency: transitive description: name: url_launcher_android - sha256: "3e2f6dfd2c7d9cd123296cab8ef66cfc2c1a13f5845f42c7a0f365690a8a7dd1" + sha256: "1f4d9ebe86f333c15d318f81dcdc08b01d45da44af74552608455ebdc08d9732" url: "https://pub.dev" source: hosted - version: "6.0.23" + version: "6.0.24" url_launcher_ios: dependency: transitive description: name: url_launcher_ios - sha256: "0a5af0aefdd8cf820dd739886efb1637f1f24489900204f50984634c07a54815" + sha256: c9cd648d2f7ab56968e049d4e9116f96a85517f1dd806b96a86ea1018a3a82e5 url: "https://pub.dev" source: hosted - version: "6.1.0" + version: "6.1.1" url_launcher_linux: dependency: transitive description: name: url_launcher_linux - sha256: "318c42cba924e18180c029be69caf0a1a710191b9ec49bb42b5998fdcccee3cc" + sha256: e29039160ab3730e42f3d811dc2a6d5f2864b90a70fb765ea60144b03307f682 url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "3.0.3" url_launcher_macos: dependency: transitive description: name: url_launcher_macos - sha256: "41988b55570df53b3dd2a7fc90c76756a963de6a8c5f8e113330cb35992e2094" + sha256: "2dddb3291a57b074dade66b5e07e64401dd2487caefd4e9e2f467138d8c7eb06" url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "3.0.3" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface - sha256: "4eae912628763eb48fc214522e58e942fd16ce195407dbf45638239523c759a6" + sha256: "6c9ca697a5ae218ce56cece69d46128169a58aa8653c1b01d26fcd4aad8c4370" url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" url_launcher_web: dependency: transitive description: name: url_launcher_web - sha256: "44d79408ce9f07052095ef1f9a693c258d6373dc3944249374e30eff7219ccb0" + sha256: "574cfbe2390666003c3a1d129bdc4574aaa6728f0c00a4829a81c316de69dd9b" url: "https://pub.dev" source: hosted - version: "2.0.14" + version: "2.0.15" url_launcher_windows: dependency: transitive description: name: url_launcher_windows - sha256: b6217370f8eb1fd85c8890c539f5a639a01ab209a36db82c921ebeacefc7a615 + sha256: "97c9067950a0d09cbd93e2e3f0383d1403989362b97102fbf446473a48079a4b" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.4" vector_math: dependency: transitive description: