diff --git a/lib/component/download_list_item_component.dart b/lib/component/download_list_item_component.dart index f8bd769..24f4f73 100644 --- a/lib/component/download_list_item_component.dart +++ b/lib/component/download_list_item_component.dart @@ -1,11 +1,15 @@ import 'package:background_downloader/background_downloader.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_font_icons/flutter_font_icons.dart'; import 'package:nowser/const/base.dart'; import 'package:nowser/main.dart'; import 'package:nowser/util/file_size_util.dart'; import 'package:path/path.dart' as path; +import '../generated/l10n.dart'; + class DownloadListItemComponent extends StatefulWidget { // DownloadLog downloadLog; TaskRecord taskRecord; @@ -21,9 +25,12 @@ class DownloadListItemComponent extends StatefulWidget { } class _DownloadListItemComponent extends State { + late S s; + @override Widget build(BuildContext context) { var themeData = Theme.of(context); + s = S.of(context); var taskRecord = widget.taskRecord; @@ -69,11 +76,33 @@ class _DownloadListItemComponent extends State { ); } - Widget rightIcon = GestureDetector( - onTap: () {}, + Widget rightIcon = PopupMenuButton( child: const Icon( Icons.more_horiz, ), + itemBuilder: (context) { + return [ + PopupMenuItem( + child: Text(s.Copy_Link), + onTap: () { + Clipboard.setData( + ClipboardData(text: widget.taskRecord.task.url)); + BotToast.showText(text: s.Copy_success); + }, + ), + PopupMenuItem( + child: Text( + s.Delete, + style: TextStyle( + color: Colors.red, + ), + ), + onTap: () { + downloadProvider.deleteTasks([widget.taskRecord.taskId]); + }, + ), + ]; + }, ); if (taskRecord.status == TaskStatus.running) { rightIcon = GestureDetector( @@ -83,7 +112,7 @@ class _DownloadListItemComponent extends State { } }, child: const Icon( - Icons.stop_circle_outlined, + Icons.pause_circle_outline, ), ); } else if (taskRecord.status == TaskStatus.paused) { diff --git a/lib/component/webview/webview_component.dart b/lib/component/webview/webview_component.dart index e1b5460..90b319e 100644 --- a/lib/component/webview/webview_component.dart +++ b/lib/component/webview/webview_component.dart @@ -227,7 +227,7 @@ class _WebViewComponent extends State }, onDownloadStartRequest: (InAppWebViewController controller, DownloadStartRequest downloadStartRequest) { - String downloadUrl = downloadStartRequest.url.path; + String downloadUrl = downloadStartRequest.url.toString(); DownloadTaskDialog.show(context, downloadUrl); }, ), diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index fb5ff21..3ce5b30 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -66,6 +66,7 @@ class MessageLookup extends MessageLookupByLibrary { "Decrypt_zap_event": MessageLookupByLibrary.simpleMessage( "Decrypt zap event", ), + "Delete": MessageLookupByLibrary.simpleMessage("Delete"), "Desktop": MessageLookupByLibrary.simpleMessage("Desktop"), "Download_image": MessageLookupByLibrary.simpleMessage("Download image"), "Downloads": MessageLookupByLibrary.simpleMessage("Downloads"), diff --git a/lib/generated/intl/messages_zh.dart b/lib/generated/intl/messages_zh.dart index bcf4699..8c268a0 100644 --- a/lib/generated/intl/messages_zh.dart +++ b/lib/generated/intl/messages_zh.dart @@ -58,6 +58,7 @@ class MessageLookup extends MessageLookupByLibrary { "Decrypt04_name": MessageLookupByLibrary.simpleMessage("解密 (NIP-04)"), "Decrypt44_name": MessageLookupByLibrary.simpleMessage("解密 (NIP-44)"), "Decrypt_zap_event": MessageLookupByLibrary.simpleMessage("解密私密Zap"), + "Delete": MessageLookupByLibrary.simpleMessage("删除"), "Desktop": MessageLookupByLibrary.simpleMessage("桌面"), "Download_image": MessageLookupByLibrary.simpleMessage("下载图片"), "Downloads": MessageLookupByLibrary.simpleMessage("下载"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 1fab61a..6051e2a 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -724,6 +724,11 @@ class S { String get Login_fail { return Intl.message('Login_fail', name: 'Login_fail', desc: '', args: []); } + + /// `Delete` + String get Delete { + return Intl.message('Delete', name: 'Delete', desc: '', args: []); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index e7f9fcc..d35a4f4 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -94,5 +94,6 @@ "Download_image": "Download image", "or": "or", "Login_with_Nesigner": "Login with Nesigner", - "Login_fail": "Login_fail" + "Login_fail": "Login_fail", + "Delete": "Delete" } \ No newline at end of file diff --git a/lib/l10n/intl_zh.arb b/lib/l10n/intl_zh.arb index f9daf5d..355a650 100644 --- a/lib/l10n/intl_zh.arb +++ b/lib/l10n/intl_zh.arb @@ -94,5 +94,6 @@ "Download_image": "下载图片", "or": "或者", "Login_with_Nesigner": "使用 Nesigner 登录", - "Login_fail": "登录失败" + "Login_fail": "登录失败", + "Delete": "删除" } \ No newline at end of file diff --git a/lib/provider/download_provider.dart b/lib/provider/download_provider.dart index 906e786..b05539b 100644 --- a/lib/provider/download_provider.dart +++ b/lib/provider/download_provider.dart @@ -43,7 +43,7 @@ class DownloadProvider extends ChangeNotifier { var downloadDirPath = downloadDir.absolute.path; - print("url $url fileName $fileName downloadDirPath $downloadDirPath"); + // print("url $url fileName $fileName downloadDirPath $downloadDirPath"); final task = DownloadTask( url: url, @@ -56,7 +56,7 @@ class DownloadProvider extends ChangeNotifier { allowPause: true, ); - var downloadResult = await fileDownloader.download( + fileDownloader.download( task, onProgress: (progress) { print('Progress: ${progress * 100}%'); @@ -64,11 +64,12 @@ class DownloadProvider extends ChangeNotifier { }, onStatus: (status) { print('Status: $status'); + if (status == TaskStatus.running) { + reloadData(); + } notifyListeners(); }, ); - - await reloadData(); notifyListeners(); } }