From c37e00f2fd7fb9100fd21bde0c9b75ce6de9ea57 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 3 Apr 2021 22:21:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=BC=E5=87=BAepub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../main/java/io/legado/app/help/AppConfig.kt | 6 ++++++ .../legado/app/ui/book/cache/CacheActivity.kt | 17 +++++++++++++++-- .../legado/app/ui/book/cache/CacheViewModel.kt | 10 +++++----- app/src/main/res/menu/book_cache.xml | 5 +++++ app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index e9801a743..7e8f68da5 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -40,6 +40,7 @@ object PreferKey { const val webDavPassword = "web_dav_password" const val webDavCreateDir = "webDavCreateDir" const val exportToWebDav = "webDavCacheBackup" + const val exportType = "exportType" const val changeSourceLoadToc = "changeSourceLoadToc" const val changeSourceLoadInfo = "changeSourceLoadInfo" const val chineseConverterType = "chineseConverterType" diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 7468fbef5..4e4ce33c9 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -161,6 +161,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { appCtx.putPrefBoolean(PreferKey.exportToWebDav, value) } + var exportType: Int + get() = appCtx.getPrefInt(PreferKey.exportType) + set(value) { + appCtx.putPrefInt(PreferKey.exportType, value) + } + val autoChangeSource: Boolean get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true) diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 52feb9489..23b4289f3 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -23,6 +23,7 @@ import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.selector import io.legado.app.service.help.CacheBook import io.legado.app.ui.document.FilePicker import io.legado.app.ui.document.FilePickerParam @@ -122,6 +123,7 @@ class CacheActivity : VMBaseActivity() R.id.menu_enable_replace -> AppConfig.exportUseReplace = !item.isChecked R.id.menu_export_web_dav -> AppConfig.exportToWebDav = !item.isChecked R.id.menu_export_folder -> export(-1) + R.id.menu_export_type -> showExportTypeConfig() R.id.menu_export_charset -> showCharsetConfig() R.id.menu_log -> TextListDialog.show(supportFragmentManager, getString(R.string.log), CacheBook.logs) @@ -239,12 +241,23 @@ class CacheActivity : VMBaseActivity() adapter.getItem(exportPosition)?.let { book -> Snackbar.make(binding.titleBar, R.string.exporting, Snackbar.LENGTH_INDEFINITE) .show() - viewModel.exportEPUB(path, book) { - binding.titleBar.snackbar(it) + when (AppConfig.exportType) { + 1 -> viewModel.exportEPUB(path, book) { + binding.titleBar.snackbar(it) + } + else -> viewModel.export(path, book) { + binding.titleBar.snackbar(it) + } } } } + private fun showExportTypeConfig() { + selector(R.string.export_type, arrayListOf("txt", "epub")) { _, i -> + AppConfig.exportType = i + } + } + private fun showCharsetConfig() { alert(R.string.set_charset) { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index e60a7d3d0..ef0cc2aea 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -106,7 +106,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } } - private suspend fun getAllContents(book: Book, append: (text: String) -> Unit) { + private fun getAllContents(book: Book, append: (text: String) -> Unit) { val useReplace = AppConfig.exportUseReplace val contentProcessor = ContentProcessor(book.name, book.origin) append("${book.name}\n${context.getString(R.string.author_show, book.author)}") @@ -159,13 +159,13 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } @Suppress("BlockingMethodInNonBlockingContext") - private suspend fun exportEpub(doc: DocumentFile, book: Book) { + private fun exportEpub(doc: DocumentFile, book: Book) { val filename = "${book.name} by ${book.author}.epub" DocumentUtils.delete(doc, filename) val epubBook = EpubBook() epubBook.version = "2.0" //set metadata - setEpubMetadata(book,epubBook) + setEpubMetadata(book, epubBook) //set cover setCover(book, epubBook) @@ -187,12 +187,12 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } } - private suspend fun exportEpub(file: File, book: Book) { + private fun exportEpub(file: File, book: Book) { val filename = "${book.name} by ${book.author}.epub" val epubBook = EpubBook() epubBook.version = "2.0" //set metadata - setEpubMetadata(book,epubBook) + setEpubMetadata(book, epubBook) //set cover setCover(book, epubBook) diff --git a/app/src/main/res/menu/book_cache.xml b/app/src/main/res/menu/book_cache.xml index a0dca539f..42c873c82 100644 --- a/app/src/main/res/menu/book_cache.xml +++ b/app/src/main/res/menu/book_cache.xml @@ -37,6 +37,11 @@ android:title="@string/export_folder" app:showAsAction="never" /> + + 使用自定义中文分行 图片样式 系统TTS + 导出格式 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 6ea300b43..ab85be403 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -813,5 +813,6 @@ 调试 图片样式 系统TTS + 导出格式 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 910a08008..196d02455 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -815,5 +815,6 @@ 使用自定义中文分行 图片样式 系统TTS + 导出格式 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 57077eafb..983a21e48 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -818,5 +818,6 @@ 使用自定义中文分行 Image style System TTS + 导出格式