diff --git a/app/src/main/assets/help/ExtensionContentType.md b/app/src/main/assets/help/ExtensionContentType.md new file mode 100644 index 000000000..84b0babc1 --- /dev/null +++ b/app/src/main/assets/help/ExtensionContentType.md @@ -0,0 +1,156 @@ +```java +public enum MimeTypeEnum { + + AAC("acc", "AAC音频", "audio/aac"), + + ABW("abw", "AbiWord文件", "application/x-abiword"), + + ARC("arc", "存档文件", "application/x-freearc"), + + AVI("avi", "音频视频交错格式", "video/x-msvideo"), + + AZW("azw", "亚马逊Kindle电子书格式", "application/vnd.amazon.ebook"), + + BIN("bin", "任何类型的二进制数据", "application/octet-stream"), + + BMP("bmp", "Windows OS / 2位图图形", "image/bmp"), + + BZ("bz", "BZip存档", "application/x-bzip"), + + BZ2("bz2", "BZip2存档", "application/x-bzip2"), + + CSH("csh", "C-Shell脚本", "application/x-csh"), + + CSS("css", "级联样式表(CSS)", "text/css"), + + CSV("csv", "逗号分隔值(CSV)", "text/csv"), + + DOC("doc", "微软Word文件", "application/msword"), + + DOCX("docx", "Microsoft Word(OpenXML)", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"), + + EOT("eot", "MS Embedded OpenType字体", "application/vnd.ms-fontobject"), + + EPUB("epub", "电子出版物(EPUB)", "application/epub+zip"), + + GZ("gz", "GZip压缩档案", "application/gzip"), + + GIF("gif", "图形交换格式(GIF)", "image/gif"), + + HTM("htm", "超文本标记语言(HTML)", "text/html"), + + HTML("html", "超文本标记语言(HTML)", "text/html"), + + ICO("ico", "图标格式", "image/vnd.microsoft.icon"), + + ICS("ics", "iCalendar格式", "text/calendar"), + + JAR("jar", "Java存档", "application/java-archive"), + + JPEG("jpeg", "JPEG图像", "image/jpeg"), + + JPG("jpg", "JPEG图像", "image/jpeg"), + + JS("js", "JavaScript", "text/javascript"), + + JSON("json", "JSON格式", "application/json"), + + JSONLD("jsonld", "JSON-LD格式", "application/ld+json"), + + MID("mid", "乐器数字接口(MIDI)", "audio/midi"), + + MIDI("midi", "乐器数字接口(MIDI)", "audio/midi"), + + MJS("mjs", "JavaScript模块", "text/javascript"), + + MP3("mp3", "MP3音频", "audio/mpeg"), + + MPEG("mpeg", "MPEG视频", "video/mpeg"), + + MPKG("mpkg", "苹果安装程序包", "application/vnd.apple.installer+xml"), + + ODP("odp", "OpenDocument演示文稿文档", "application/vnd.oasis.opendocument.presentation"), + + ODS("ods", "OpenDocument电子表格文档", "application/vnd.oasis.opendocument.spreadsheet"), + + ODT("odt", "OpenDocument文字文件", "application/vnd.oasis.opendocument.text"), + + OGA("oga", "OGG音讯", "audio/ogg"), + + OGV("ogv", "OGG视频", "video/ogg"), + + OGX("ogx", "OGG", "application/ogg"), + + OPUS("opus", "OPUS音频", "audio/opus"), + + OTF("otf", "otf字体", "font/otf"), + + PNG("png", "便携式网络图形", "image/png"), + + PDF("pdf", "Adobe 可移植文档格式(PDF)", "application/pdf"), + + PHP("php", "php", "application/x-httpd-php"), + + PPT("ppt", "Microsoft PowerPoint", "application/vnd.ms-powerpoint"), + + PPTX("pptx", "Microsoft PowerPoint(OpenXML)", "application/vnd.openxmlformats-officedocument.presentationml.presentation"), + + RAR("rar", "RAR档案", "application/vnd.rar"), + + RTF("rtf", "富文本格式", "application/rtf"), + + SH("sh", "Bourne Shell脚本", "application/x-sh"), + + SVG("svg", "可缩放矢量图形(SVG)", "image/svg+xml"), + + SWF("swf", "小型Web格式(SWF)或Adobe Flash文档", "application/x-shockwave-flash"), + + TAR("tar", "磁带存档(TAR)", "application/x-tar"), + + TIF("tif", "标记图像文件格式(TIFF)", "image/tiff"), + + TIFF("tiff", "标记图像文件格式(TIFF)", "image/tiff"), + + TS("ts", "MPEG传输流", "video/mp2t"), + + TTF("ttf", "ttf字体", "font/ttf"), + + TXT("txt", "文本(通常为ASCII或ISO 8859- n", "text/plain"), + + VSD("vsd", "微软Visio", "application/vnd.visio"), + + WAV("wav", "波形音频格式", "audio/wav"), + + WEBA("weba", "WEBM音频", "audio/webm"), + + WEBM("webm", "WEBM视频", "video/webm"), + + WEBP("webp", "WEBP图像", "image/webp"), + + WOFF("woff", "Web开放字体格式(WOFF)", "font/woff"), + + WOFF2("woff2", "Web开放字体格式(WOFF)", "font/woff2"), + + XHTML("xhtml", "XHTML", "application/xhtml+xml"), + + XLS("xls", "微软Excel", "application/vnd.ms-excel"), + + XLSX("xlsx", "微软Excel(OpenXML)", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"), + + XML("xml", "XML", "application/xml"), + + XUL("xul", "XUL", "application/vnd.mozilla.xul+xml"), + + ZIP("zip", "ZIP", "application/zip"), + + MIME_3GP("3gp", "3GPP audio/video container", "video/3gpp"), + + MIME_3GP_WITHOUT_VIDEO("3gp", "3GPP audio/video container doesn't contain video", "audio/3gpp2"), + + MIME_3G2("3g2", "3GPP2 audio/video container", "video/3gpp2"), + + MIME_3G2_WITHOUT_VIDEO("3g2", "3GPP2 audio/video container doesn't contain video", "audio/3gpp2"), + + MIME_7Z("7z", "7-zip存档", "application/x-7z-compressed") +} +``` \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt b/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt index fdaa30e9e..d10e98ff1 100644 --- a/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt +++ b/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt @@ -9,7 +9,7 @@ object DirectLinkUpload { private const val uploadUrlKey = "directLinkUploadUrl" private const val downloadUrlRuleKey = "directLinkDownloadUrlRule" - suspend fun upLoad(fileName: String, byteArray: ByteArray): String { + suspend fun upLoad(fileName: String, file: ByteArray, contentType: String): String { val url = getUploadUrl() if (url.isNullOrBlank()) { error("上传url未配置") @@ -19,7 +19,7 @@ object DirectLinkUpload { error("下载地址规则未配置") } val analyzeUrl = AnalyzeUrl(url) - val res = analyzeUrl.upload(fileName, byteArray, "application/json") + val res = analyzeUrl.upload(fileName, file, contentType) val analyzeRule = AnalyzeRule(RuleData()).setContent(res.body, res.url) val downloadUrl = analyzeRule.getString(downloadUrlRule) if (downloadUrl.isBlank()) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 73d6929c6..e8a5bc700 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -128,8 +128,11 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener R.id.menu_import_onLine -> importAlert() R.id.menu_export -> exportDirResult.launch { mode = HandleFileContract.EXPORT - fileName = "httpTts.json" - file = GSON.toJson(adapter.getItems()).toByteArray() + fileData = Triple( + "httpTts.json", + GSON.toJson(adapter.getItems()).toByteArray(), + "application/json" + ) } } return true diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 51490b8d1..c6e52563d 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -332,8 +332,11 @@ class BookSourceActivity : VMBaseActivity selectionRemoveFromGroups() R.id.menu_export_selection -> exportDir.launch { mode = HandleFileContract.EXPORT - fileName = "bookSource.json" - file = GSON.toJson(adapter.selection).toByteArray() + fileData = Triple( + "bookSource.json", + GSON.toJson(adapter.selection).toByteArray(), + "application/json" + ) } } return true diff --git a/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt b/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt index 800399cfc..9c77c9f50 100644 --- a/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt +++ b/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt @@ -95,7 +95,7 @@ class HandleFileActivity : ) } 111 -> getFileData()?.let { - viewModel.upload(it.first, it.second) { url -> + viewModel.upload(it.first, it.second, it.third) { url -> val uri = Uri.parse(url) setResult(RESULT_OK, Intent().setData(uri)) finish() @@ -118,13 +118,14 @@ class HandleFileActivity : }.show() } - private fun getFileData(): Pair? { + private fun getFileData(): Triple? { val fileName = intent.getStringExtra("fileName") val file = intent.getStringExtra("fileKey")?.let { IntentDataHelp.getData(it) } - if (fileName != null && file != null) { - return Pair(fileName, file) + val contentType = intent.getStringExtra("contentType") + if (fileName != null && file != null && contentType != null) { + return Triple(fileName, file, contentType) } return null } diff --git a/app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt b/app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt index a90169a6c..6ac04153d 100644 --- a/app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt +++ b/app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt @@ -29,11 +29,10 @@ class HandleFileContract : intent.putExtra("title", it.title) intent.putExtra("allowExtensions", it.allowExtensions) intent.putExtra("otherActions", it.otherActions) - it.fileName?.let { fileName -> - intent.putExtra("fileName", fileName) - } - it.file?.let { file -> - intent.putExtra("fileKey", IntentDataHelp.putData(file)) + it.fileData?.let { fileData -> + intent.putExtra("fileName", fileData.first) + intent.putExtra("fileKey", IntentDataHelp.putData(fileData.second)) + intent.putExtra("contentType", fileData.third) } } return intent @@ -52,8 +51,7 @@ class HandleFileContract : var title: String? = null, var allowExtensions: Array = arrayOf(), var otherActions: ArrayList? = null, - var fileName: String? = null, - var file: ByteArray? = null + var fileData: Triple? = null ) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt b/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt index e6cbc718c..60405b6c0 100644 --- a/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt @@ -15,9 +15,14 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application) val errorLiveData = MutableLiveData() - fun upload(fileName: String, byteArray: ByteArray, success: (url: String) -> Unit) { + fun upload( + fileName: String, + file: ByteArray, + contentType: String, + success: (url: String) -> Unit + ) { execute { - DirectLinkUpload.upLoad(fileName, byteArray) + DirectLinkUpload.upLoad(fileName, file, contentType) }.onSuccess { success.invoke(it) }.onError { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt index 1923583af..deaa097c6 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt @@ -70,8 +70,11 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment viewModel.exportBookshelf(books) { exportBookshelf.launch { mode = HandleFileContract.EXPORT - fileName = "bookshelf.json" - file = it.toByteArray() + fileData = Triple( + "bookshelf.json", + it.toByteArray(), + "application/json" + ) } } R.id.menu_import_bookshelf -> importBookshelfAlert(groupId) diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index c4ae61ac1..ab786bbf7 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -232,8 +232,11 @@ class ReplaceRuleActivity : VMBaseActivity viewModel.bottomSelect(adapter.selection) R.id.menu_export_selection -> exportDir.launch { mode = HandleFileContract.EXPORT - fileName = "exportReplaceRule.json" - file = GSON.toJson(adapter.selection).toByteArray() + fileData = Triple( + "exportReplaceRule.json", + GSON.toJson(adapter.selection).toByteArray(), + "application/json" + ) } } return false diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 8e4562176..104d501e4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -127,8 +127,11 @@ class RssSourceActivity : VMBaseActivity viewModel.delSelection(adapter.selection) R.id.menu_export_selection -> exportDir.launch { mode = HandleFileContract.EXPORT - fileName = "exportRssSource.json" - file = GSON.toJson(adapter.selection).toByteArray() + fileData = Triple( + "exportRssSource.json", + GSON.toJson(adapter.selection).toByteArray(), + "application/json" + ) } R.id.menu_top_sel -> viewModel.topSource(*adapter.selection.toTypedArray()) R.id.menu_bottom_sel -> viewModel.bottomSource(*adapter.selection.toTypedArray())