From c0bcb32db5e02504366fce5decfbdb47c4520ab9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 6 Jun 2021 17:40:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=96=87=E4=BB=B6=E5=90=8D?= 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 ++++++ .../app/model/analyzeRule/AnalyzeRule.kt | 4 +--- .../legado/app/ui/book/cache/CacheActivity.kt | 14 +++++++++++++ .../app/ui/book/cache/CacheViewModel.kt | 20 +++++++++++++++---- app/src/main/res/menu/book_cache.xml | 5 +++++ app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + 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 | 3 ++- 12 files changed, 50 insertions(+), 8 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 67732823a..cadb256e0 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -28,6 +28,7 @@ object PreferKey { const val showRss = "showRss" const val bookshelfLayout = "bookshelfLayout" const val bookshelfSort = "bookshelfSort" + const val bookExportFileName = "bookExportFileName" const val recordLog = "recordLog" const val processText = "process_text" const val cleanCache = "cleanCache" 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 218efbf7a..4e90f74f9 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -96,6 +96,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { appCtx.putPrefInt(PreferKey.bookGroupStyle, value) } + var bookExportFileName: String? + get() = appCtx.getPrefString(PreferKey.bookExportFileName) + set(value) { + appCtx.putPrefString(PreferKey.bookExportFileName, value) + } + var backupPath: String? get() = appCtx.getPrefString(PreferKey.backupPath) set(value) { diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index f704c7f24..57b3d25a1 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -650,9 +650,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { bindings["title"] = chapter?.title bindings["src"] = content bindings["nextChapterUrl"] = nextChapterUrl - return runBlocking { - SCRIPT_ENGINE.eval(jsStr, bindings) - } + return SCRIPT_ENGINE.eval(jsStr, bindings) } /** 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 fe70f9be6..7016927b5 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 @@ -127,6 +127,7 @@ class CacheActivity : VMBaseActivity() exportPosition = -1 selectExportFolder() } + R.id.menu_export_file_name -> alertExportFileName() R.id.menu_export_type -> showExportTypeConfig() R.id.menu_export_charset -> showCharsetConfig() R.id.menu_log -> @@ -294,6 +295,19 @@ class CacheActivity : VMBaseActivity() } } + private fun alertExportFileName() { + alert(R.string.export_file_name) { + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.setText(AppConfig.bookExportFileName) + } + customView { alertBinding.root } + okButton { + AppConfig.bookExportFileName = alertBinding.editView.text?.toString() + } + cancelButton() + }.show() + } + private fun showExportTypeConfig() { selector(R.string.export_type, arrayListOf("txt", "epub")) { _, i -> AppConfig.exportType = i 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 819686dcf..fab7802b6 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 @@ -10,6 +10,7 @@ import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition import io.legado.app.R import io.legado.app.base.BaseViewModel +import io.legado.app.constant.AppConst import io.legado.app.constant.AppPattern import io.legado.app.data.appDb import io.legado.app.data.entities.Book @@ -26,10 +27,21 @@ import java.io.ByteArrayOutputStream import java.io.File import java.io.FileOutputStream import java.nio.charset.Charset +import javax.script.SimpleBindings class CacheViewModel(application: Application) : BaseViewModel(application) { + fun getExportFileName(book: Book): String { + val jsStr = AppConfig.bookExportFileName + if (jsStr.isNullOrBlank()) { + return "${book.name} by ${book.author}" + } + val bindings = SimpleBindings() + bindings["name"] = book.name + bindings["author"] = book.author + return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString() + } fun export(path: String, book: Book, finally: (msg: String) -> Unit) { execute { @@ -50,7 +62,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { @Suppress("BlockingMethodInNonBlockingContext") private suspend fun export(doc: DocumentFile, book: Book) { - val filename = "${book.name} by ${book.author}.txt" + val filename = "${getExportFileName(book)}.txt" DocumentUtils.delete(doc, filename) DocumentUtils.createFileIfNotExist(doc, filename)?.let { bookDoc -> val stringBuilder = StringBuilder() @@ -80,7 +92,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private suspend fun export(file: File, book: Book) { - val filename = "${book.name} by ${book.author}.txt" + val filename = "${getExportFileName(book)}.txt" val bookPath = FileUtils.getPath(file, filename) val bookFile = FileUtils.createFileWithReplace(bookPath) val stringBuilder = StringBuilder() @@ -161,7 +173,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { @Suppress("BlockingMethodInNonBlockingContext") private fun exportEpub(doc: DocumentFile, book: Book) { - val filename = "${book.name} by ${book.author}.epub" + val filename = "${getExportFileName(book)}.epub" DocumentUtils.delete(doc, filename) val epubBook = EpubBook() epubBook.version = "2.0" @@ -185,7 +197,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { private fun exportEpub(file: File, book: Book) { - val filename = "${book.name} by ${book.author}.epub" + val filename = "${getExportFileName(book)}.epub" val epubBook = EpubBook() epubBook.version = "2.0" //set metadata diff --git a/app/src/main/res/menu/book_cache.xml b/app/src/main/res/menu/book_cache.xml index 71598a744..0f58daf7a 100644 --- a/app/src/main/res/menu/book_cache.xml +++ b/app/src/main/res/menu/book_cache.xml @@ -42,6 +42,11 @@ android:title="@string/export_folder" app:showAsAction="never" /> + + 显示发现 样式 分组样式 + 导出文件名 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 2316617f8..a949fa0ba 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -842,4 +842,5 @@ Mostrar 样式 分组样式 + 导出文件名 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 45cf4f55a..e6de6eeff 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -840,5 +840,6 @@ 显示发现 样式 分组样式 + 导出文件名 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 9e89c0e57..168223c92 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -841,5 +841,6 @@ 显示发现 样式 分组样式 + 导出文件名 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index b4ab34633..20ccc50d9 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -841,5 +841,6 @@ 显示发现 样式 分组样式 + 导出文件名 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cd20abb71..d7d1ba6a8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -808,7 +808,7 @@ Background image Copy book URL Copy chapters URL - Export to a folder + Export folder Exported text coding Export to WebDav Reverse content @@ -842,5 +842,6 @@ Show Style Group style + Export file name