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 9b2de36ba..85bdeee27 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -68,6 +68,7 @@ object PreferKey { const val autoRefresh = "auto_refresh" const val defaultToRead = "defaultToRead" const val exportCharset = "exportCharset" + const val exportUseReplace = "exportUseReplace" const val cPrimary = "colorPrimary" const val cAccent = "colorAccent" 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 fef5a084d..5d50224d3 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -9,44 +9,43 @@ import splitties.init.appCtx @Suppress("MemberVisibilityCanBePrivate") object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { - private val context get() = appCtx - val isGooglePlay = context.channel == "google" + val isGooglePlay = appCtx.channel == "google" var userAgent: String = getPrefUserAgent() - var replaceEnableDefault = context.getPrefBoolean(PreferKey.replaceEnableDefault, true) - var isEInkMode = context.getPrefString(PreferKey.themeMode) == "3" - var clickActionTL = context.getPrefInt(PreferKey.clickActionTL, 2) - var clickActionTC = context.getPrefInt(PreferKey.clickActionTC, 2) - var clickActionTR = context.getPrefInt(PreferKey.clickActionTR, 1) - var clickActionML = context.getPrefInt(PreferKey.clickActionML, 2) - var clickActionMC = context.getPrefInt(PreferKey.clickActionMC, 0) - var clickActionMR = context.getPrefInt(PreferKey.clickActionMR, 1) - var clickActionBL = context.getPrefInt(PreferKey.clickActionBL, 2) - var clickActionBC = context.getPrefInt(PreferKey.clickActionBC, 1) - var clickActionBR = context.getPrefInt(PreferKey.clickActionBR, 1) + var replaceEnableDefault = appCtx.getPrefBoolean(PreferKey.replaceEnableDefault, true) + var isEInkMode = appCtx.getPrefString(PreferKey.themeMode) == "3" + var clickActionTL = appCtx.getPrefInt(PreferKey.clickActionTL, 2) + var clickActionTC = appCtx.getPrefInt(PreferKey.clickActionTC, 2) + var clickActionTR = appCtx.getPrefInt(PreferKey.clickActionTR, 1) + var clickActionML = appCtx.getPrefInt(PreferKey.clickActionML, 2) + var clickActionMC = appCtx.getPrefInt(PreferKey.clickActionMC, 0) + var clickActionMR = appCtx.getPrefInt(PreferKey.clickActionMR, 1) + var clickActionBL = appCtx.getPrefInt(PreferKey.clickActionBL, 2) + var clickActionBC = appCtx.getPrefInt(PreferKey.clickActionBC, 1) + var clickActionBR = appCtx.getPrefInt(PreferKey.clickActionBR, 1) override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { - PreferKey.themeMode -> isEInkMode = context.getPrefString(PreferKey.themeMode) == "3" + PreferKey.themeMode -> isEInkMode = appCtx.getPrefString(PreferKey.themeMode) == "3" PreferKey.clickActionTL -> clickActionTL = - context.getPrefInt(PreferKey.clickActionTL, 2) + appCtx.getPrefInt(PreferKey.clickActionTL, 2) PreferKey.clickActionTC -> clickActionTC = - context.getPrefInt(PreferKey.clickActionTC, 2) + appCtx.getPrefInt(PreferKey.clickActionTC, 2) PreferKey.clickActionTR -> clickActionTR = - context.getPrefInt(PreferKey.clickActionTR, 2) + appCtx.getPrefInt(PreferKey.clickActionTR, 2) PreferKey.clickActionML -> clickActionML = - context.getPrefInt(PreferKey.clickActionML, 2) + appCtx.getPrefInt(PreferKey.clickActionML, 2) PreferKey.clickActionMC -> clickActionMC = - context.getPrefInt(PreferKey.clickActionMC, 2) + appCtx.getPrefInt(PreferKey.clickActionMC, 2) PreferKey.clickActionMR -> clickActionMR = - context.getPrefInt(PreferKey.clickActionMR, 2) + appCtx.getPrefInt(PreferKey.clickActionMR, 2) PreferKey.clickActionBL -> clickActionBL = - context.getPrefInt(PreferKey.clickActionBL, 2) + appCtx.getPrefInt(PreferKey.clickActionBL, 2) PreferKey.clickActionBC -> clickActionBC = - context.getPrefInt(PreferKey.clickActionBC, 2) + appCtx.getPrefInt(PreferKey.clickActionBC, 2) PreferKey.clickActionBR -> clickActionBR = - context.getPrefInt(PreferKey.clickActionBR, 2) + appCtx.getPrefInt(PreferKey.clickActionBR, 2) PreferKey.readBodyToLh -> ReadBookConfig.readBodyToLh = - context.getPrefBoolean(PreferKey.readBodyToLh, true) + appCtx.getPrefBoolean(PreferKey.readBodyToLh, true) PreferKey.userAgent -> userAgent = getPrefUserAgent() } } @@ -61,109 +60,115 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { } var isNightTheme: Boolean - get() = isNightTheme(context) + get() = isNightTheme(appCtx) set(value) { if (isNightTheme != value) { if (value) { - context.putPrefString(PreferKey.themeMode, "2") + appCtx.putPrefString(PreferKey.themeMode, "2") } else { - context.putPrefString(PreferKey.themeMode, "1") + appCtx.putPrefString(PreferKey.themeMode, "1") } } } val isTransparentStatusBar: Boolean - get() = context.getPrefBoolean(PreferKey.transparentStatusBar, true) + get() = appCtx.getPrefBoolean(PreferKey.transparentStatusBar, true) val immNavigationBar: Boolean - get() = context.getPrefBoolean(PreferKey.immNavigationBar, true) + get() = appCtx.getPrefBoolean(PreferKey.immNavigationBar, true) val screenOrientation: String? - get() = context.getPrefString(PreferKey.screenOrientation) + get() = appCtx.getPrefString(PreferKey.screenOrientation) var backupPath: String? - get() = context.getPrefString(PreferKey.backupPath) + get() = appCtx.getPrefString(PreferKey.backupPath) set(value) { if (value.isNullOrEmpty()) { - context.removePref(PreferKey.backupPath) + appCtx.removePref(PreferKey.backupPath) } else { - context.putPrefString(PreferKey.backupPath, value) + appCtx.putPrefString(PreferKey.backupPath, value) } } val isShowRSS: Boolean - get() = context.getPrefBoolean(PreferKey.showRss, true) + get() = appCtx.getPrefBoolean(PreferKey.showRss, true) val autoRefreshBook: Boolean - get() = context.getPrefBoolean(PreferKey.autoRefresh) + get() = appCtx.getPrefBoolean(PreferKey.autoRefresh) var threadCount: Int - get() = context.getPrefInt(PreferKey.threadCount, 16) + get() = appCtx.getPrefInt(PreferKey.threadCount, 16) set(value) { - context.putPrefInt(PreferKey.threadCount, value) + appCtx.putPrefInt(PreferKey.threadCount, value) } var importBookPath: String? - get() = context.getPrefString("importBookPath") + get() = appCtx.getPrefString("importBookPath") set(value) { if (value == null) { - context.removePref("importBookPath") + appCtx.removePref("importBookPath") } else { - context.putPrefString("importBookPath", value) + appCtx.putPrefString("importBookPath", value) } } var ttsSpeechRate: Int - get() = context.getPrefInt(PreferKey.ttsSpeechRate, 5) + get() = appCtx.getPrefInt(PreferKey.ttsSpeechRate, 5) set(value) { - context.putPrefInt(PreferKey.ttsSpeechRate, value) + appCtx.putPrefInt(PreferKey.ttsSpeechRate, value) } var chineseConverterType: Int - get() = context.getPrefInt(PreferKey.chineseConverterType) + get() = appCtx.getPrefInt(PreferKey.chineseConverterType) set(value) { - context.putPrefInt(PreferKey.chineseConverterType, value) + appCtx.putPrefInt(PreferKey.chineseConverterType, value) } var systemTypefaces: Int - get() = context.getPrefInt(PreferKey.systemTypefaces) + get() = appCtx.getPrefInt(PreferKey.systemTypefaces) set(value) { - context.putPrefInt(PreferKey.systemTypefaces, value) + appCtx.putPrefInt(PreferKey.systemTypefaces, value) } var elevation: Int - get() = context.getPrefInt(PreferKey.barElevation, AppConst.sysElevation) + get() = appCtx.getPrefInt(PreferKey.barElevation, AppConst.sysElevation) set(value) { - context.putPrefInt(PreferKey.barElevation, value) + appCtx.putPrefInt(PreferKey.barElevation, value) } var exportCharset: String get() { - val c = context.getPrefString(PreferKey.exportCharset) + val c = appCtx.getPrefString(PreferKey.exportCharset) if (c.isNullOrBlank()) { return "UTF-8" } return c } set(value) { - context.putPrefString(PreferKey.exportCharset, value) + appCtx.putPrefString(PreferKey.exportCharset, value) + } + + var exportUseReplace: Boolean + get() = appCtx.getPrefBoolean(PreferKey.exportUseReplace, true) + set(value) { + appCtx.putPrefBoolean(PreferKey.exportUseReplace, value) } val autoChangeSource: Boolean - get() = context.getPrefBoolean(PreferKey.autoChangeSource, true) + get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true) - val changeSourceLoadInfo get() = context.getPrefBoolean(PreferKey.changeSourceLoadToc) + val changeSourceLoadInfo get() = appCtx.getPrefBoolean(PreferKey.changeSourceLoadToc) - val changeSourceLoadToc get() = context.getPrefBoolean(PreferKey.changeSourceLoadToc) + val changeSourceLoadToc get() = appCtx.getPrefBoolean(PreferKey.changeSourceLoadToc) - val importKeepName get() = context.getPrefBoolean(PreferKey.importKeepName) + val importKeepName get() = appCtx.getPrefBoolean(PreferKey.importKeepName) - val syncBookProgress get() = context.getPrefBoolean(PreferKey.syncBookProgress, true) + val syncBookProgress get() = appCtx.getPrefBoolean(PreferKey.syncBookProgress, true) - val preDownload get() = context.getPrefBoolean(PreferKey.preDownload, true) + val preDownload get() = appCtx.getPrefBoolean(PreferKey.preDownload, true) private fun getPrefUserAgent(): String { - val ua = context.getPrefString(PreferKey.userAgent) + val ua = appCtx.getPrefString(PreferKey.userAgent) if (ua.isNullOrBlank()) { return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" } diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 17f6f6319..ab3a60f04 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -27,10 +27,11 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str book: Book, title: String, //已经经过简繁转换 content: String, - isRead: Boolean = true + isRead: Boolean = true, + useReplace: Boolean = book.getUseReplaceRule() ): List { var content1 = content - if (book.getUseReplaceRule()) { + if (useReplace) { replaceRules.forEach { item -> if (item.pattern.isNotEmpty()) { try { 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 c3768991a..b8bae6900 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 @@ -75,6 +75,11 @@ class CacheActivity : VMBaseActivity() return super.onPrepareOptionsMenu(menu) } + override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { + menu.findItem(R.id.menu_enable_replace).isChecked = AppConfig.exportUseReplace + return super.onMenuOpened(featureId, menu) + } + private fun upMenu() { menu?.findItem(R.id.menu_book_group)?.subMenu?.let { subMenu -> subMenu.removeGroup(R.id.menu_group) @@ -100,6 +105,7 @@ class CacheActivity : VMBaseActivity() CacheBook.stop(this@CacheActivity) } } + R.id.menu_enable_replace -> AppConfig.exportUseReplace = !item.isChecked R.id.menu_export_folder -> export(-1) R.id.menu_export_charset -> showCharsetConfig() R.id.menu_log -> 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 9737b618a..4a060c991 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 @@ -9,6 +9,7 @@ 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 import io.legado.app.help.BookHelp import io.legado.app.help.ContentProcessor import io.legado.app.help.storage.BookWebDav @@ -86,6 +87,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private suspend fun getAllContents(book: Book): String { + val useReplace = AppConfig.exportUseReplace val contentProcessor = ContentProcessor(book.name, book.origin) val stringBuilder = StringBuilder() stringBuilder.append(book.name) @@ -94,7 +96,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter -> BookHelp.getContent(book, chapter).let { content -> val content1 = contentProcessor - .getContent(book, chapter.title, content ?: "null", false) + .getContent(book, chapter.title, content ?: "null", false, useReplace) .joinToString("\n") stringBuilder.append("\n\n") .append(content1) diff --git a/app/src/main/res/menu/book_cache.xml b/app/src/main/res/menu/book_cache.xml index 6ceebce28..b84744887 100644 --- a/app/src/main/res/menu/book_cache.xml +++ b/app/src/main/res/menu/book_cache.xml @@ -20,6 +20,12 @@ + +