From e3be6c345fe3392dd8556100edcf5c331a21d8e9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 21 Feb 2021 19:07:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/PreferKey.kt | 2 +- app/src/main/java/io/legado/app/help/AppConfig.kt | 6 ++++++ .../java/io/legado/app/ui/book/cache/CacheActivity.kt | 4 +++- .../java/io/legado/app/ui/book/cache/CacheViewModel.kt | 6 ++---- app/src/main/res/menu/book_cache.xml | 6 ++++++ 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 + app/src/main/res/xml/pref_config_backup.xml | 9 --------- 10 files changed, 22 insertions(+), 15 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 85bdeee27..31fa6fc05 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -39,7 +39,7 @@ object PreferKey { const val webDavAccount = "web_dav_account" const val webDavPassword = "web_dav_password" const val webDavCreateDir = "webDavCreateDir" - const val webDavCacheBackup = "webDavCacheBackup" + const val exportToWebDav = "webDavCacheBackup" 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 5d50224d3..ec4890e66 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -154,6 +154,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { appCtx.putPrefBoolean(PreferKey.exportUseReplace, value) } + var exportToWebDav: Boolean + get() = appCtx.getPrefBoolean(PreferKey.exportToWebDav) + set(value) { + appCtx.putPrefBoolean(PreferKey.exportToWebDav, 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 b8bae6900..0573005f7 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 @@ -77,6 +77,7 @@ class CacheActivity : VMBaseActivity() override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { menu.findItem(R.id.menu_enable_replace).isChecked = AppConfig.exportUseReplace + menu.findItem(R.id.menu_export_web_dav).isChecked = AppConfig.exportToWebDav return super.onMenuOpened(featureId, menu) } @@ -106,6 +107,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_charset -> showCharsetConfig() R.id.menu_log -> @@ -200,7 +202,7 @@ class CacheActivity : VMBaseActivity() override fun export(position: Int) { exportPosition = position val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey) - if (path.isNullOrEmpty()) { + if (path.isNullOrEmpty() || position < 0) { selectExportFolder() } else { startExport(path) 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 28c7d1500..d420372c6 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 @@ -6,7 +6,6 @@ import androidx.documentfile.provider.DocumentFile import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppPattern -import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.help.AppConfig @@ -14,7 +13,6 @@ import io.legado.app.help.BookHelp import io.legado.app.help.ContentProcessor import io.legado.app.help.storage.BookWebDav import io.legado.app.utils.* -import splitties.init.appCtx import java.io.File import java.nio.charset.Charset @@ -51,7 +49,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { stringBuilder.append(it) } } - if (appCtx.getPrefBoolean(PreferKey.webDavCacheBackup, false)) { + if (AppConfig.exportToWebDav) { // 导出到webdav val byteArray = stringBuilder.toString().toByteArray(Charset.forName(AppConfig.exportCharset)) @@ -79,7 +77,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { bookFile.appendText(it, Charset.forName(AppConfig.exportCharset)) stringBuilder.append(it) } - if (appCtx.getPrefBoolean(PreferKey.webDavCacheBackup, false)) { + if (AppConfig.exportToWebDav) { val byteArray = stringBuilder.toString().toByteArray(Charset.forName(AppConfig.exportCharset)) BookWebDav.exportWebDav(byteArray, filename) // 导出到webdav diff --git a/app/src/main/res/menu/book_cache.xml b/app/src/main/res/menu/book_cache.xml index b84744887..a0dca539f 100644 --- a/app/src/main/res/menu/book_cache.xml +++ b/app/src/main/res/menu/book_cache.xml @@ -26,6 +26,12 @@ android:checkable="true" app:showAsAction="never" /> + + 背景图片 导出文件夹 导出编码 + 导出到WebDav diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 214d4f5c8..6d77794e7 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -807,5 +807,6 @@ 背景图片 导出文件夹 导出编码 + 导出到WebDav diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index a50882b00..d4dad82b7 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -807,5 +807,6 @@ 背景图片 导出文件夹 导出编码 + 导出到WebDav diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 37d94f288..227aeb400 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -810,5 +810,6 @@ 背景图片 导出文件夹 导出编码 + 导出到WebDav diff --git a/app/src/main/res/xml/pref_config_backup.xml b/app/src/main/res/xml/pref_config_backup.xml index fe51a816a..6a57dcc87 100644 --- a/app/src/main/res/xml/pref_config_backup.xml +++ b/app/src/main/res/xml/pref_config_backup.xml @@ -45,15 +45,6 @@ app:allowDividerBelow="false" app:iconSpaceReserved="false" /> - -