From c44da6be9e600351eb6d603a3471d69b64ab3eaa Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 9 May 2021 18:11:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=87=8F=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/cache/CacheActivity.kt | 64 ++++++++++++++++--- 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 + 6 files changed, 63 insertions(+), 10 deletions(-) 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 fbdae644b..87e52de40 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 @@ -115,9 +115,13 @@ class CacheActivity : VMBaseActivity() CacheBook.stop(this@CacheActivity) } } + R.id.menu_export_all -> exportAll() 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_folder -> { + exportPosition = -1 + selectExportFolder() + } R.id.menu_export_type -> showExportTypeConfig() R.id.menu_export_charset -> showCharsetConfig() R.id.menu_log -> @@ -212,7 +216,17 @@ class CacheActivity : VMBaseActivity() override fun export(position: Int) { exportPosition = position val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey) - if (path.isNullOrEmpty() || position < 0) { + if (path.isNullOrEmpty()) { + selectExportFolder() + } else { + startExport(path) + } + } + + private fun exportAll() { + exportPosition = -10 + val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey) + if (path.isNullOrEmpty()) { selectExportFolder() } else { startExport(path) @@ -233,15 +247,45 @@ class CacheActivity : VMBaseActivity() } private fun startExport(path: String) { - adapter.getItem(exportPosition)?.let { book -> - Snackbar.make(binding.titleBar, R.string.exporting, Snackbar.LENGTH_INDEFINITE) - .show() - when (AppConfig.exportType) { - 1 -> viewModel.exportEPUB(path, book) { - binding.titleBar.snackbar(it) + if (exportPosition == -10) { + if (adapter.getItems().isNotEmpty()) { + Snackbar.make(binding.titleBar, R.string.exporting, Snackbar.LENGTH_INDEFINITE) + .show() + var exportSize = adapter.getItems().size + adapter.getItems().forEach { book -> + when (AppConfig.exportType) { + 1 -> viewModel.exportEPUB(path, book) { + exportSize-- + if (exportSize <= 0) { + binding.titleBar.snackbar(it) + } else { + toastOnUi(it) + } + } + else -> viewModel.export(path, book) { + exportSize-- + if (exportSize <= 0) { + binding.titleBar.snackbar(it) + } else { + toastOnUi(it) + } + } + } } - else -> viewModel.export(path, book) { - binding.titleBar.snackbar(it) + } else { + toastOnUi(R.string.no_book) + } + } else if (exportPosition > 0) { + adapter.getItem(exportPosition)?.let { book -> + Snackbar.make(binding.titleBar, R.string.exporting, Snackbar.LENGTH_INDEFINITE) + .show() + when (AppConfig.exportType) { + 1 -> viewModel.exportEPUB(path, book) { + binding.titleBar.snackbar(it) + } + else -> viewModel.export(path, book) { + binding.titleBar.snackbar(it) + } } } } diff --git a/app/src/main/res/menu/book_cache.xml b/app/src/main/res/menu/book_cache.xml index 42c873c82..71598a744 100644 --- a/app/src/main/res/menu/book_cache.xml +++ b/app/src/main/res/menu/book_cache.xml @@ -20,6 +20,11 @@ + + 此url已订阅 高刷 使用屏幕最高刷新率 + 导出所有 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index de3414c63..1899df105 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -826,5 +826,6 @@ 此url已訂閱 高刷 使用螢幕最高刷新率 + 导出所有 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index e25c7283c..238ed1a32 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -826,5 +826,6 @@ 此url已订阅 高刷 使用屏幕最高刷新率 + 导出所有 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2b302583a..73982b13e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -827,5 +827,6 @@ 此url已订阅 高刷 使用屏幕最高刷新率 + export_all