导出添加使用替换配置

pull/862/head
gedoor 4 years ago
parent e8af634e89
commit d263d0e6f1
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 119
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 5
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  4. 6
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  6. 6
      app/src/main/res/menu/book_cache.xml

@ -68,6 +68,7 @@ object PreferKey {
const val autoRefresh = "auto_refresh" const val autoRefresh = "auto_refresh"
const val defaultToRead = "defaultToRead" const val defaultToRead = "defaultToRead"
const val exportCharset = "exportCharset" const val exportCharset = "exportCharset"
const val exportUseReplace = "exportUseReplace"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"

@ -9,44 +9,43 @@ import splitties.init.appCtx
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
private val context get() = appCtx val isGooglePlay = appCtx.channel == "google"
val isGooglePlay = context.channel == "google"
var userAgent: String = getPrefUserAgent() var userAgent: String = getPrefUserAgent()
var replaceEnableDefault = context.getPrefBoolean(PreferKey.replaceEnableDefault, true) var replaceEnableDefault = appCtx.getPrefBoolean(PreferKey.replaceEnableDefault, true)
var isEInkMode = context.getPrefString(PreferKey.themeMode) == "3" var isEInkMode = appCtx.getPrefString(PreferKey.themeMode) == "3"
var clickActionTL = context.getPrefInt(PreferKey.clickActionTL, 2) var clickActionTL = appCtx.getPrefInt(PreferKey.clickActionTL, 2)
var clickActionTC = context.getPrefInt(PreferKey.clickActionTC, 2) var clickActionTC = appCtx.getPrefInt(PreferKey.clickActionTC, 2)
var clickActionTR = context.getPrefInt(PreferKey.clickActionTR, 1) var clickActionTR = appCtx.getPrefInt(PreferKey.clickActionTR, 1)
var clickActionML = context.getPrefInt(PreferKey.clickActionML, 2) var clickActionML = appCtx.getPrefInt(PreferKey.clickActionML, 2)
var clickActionMC = context.getPrefInt(PreferKey.clickActionMC, 0) var clickActionMC = appCtx.getPrefInt(PreferKey.clickActionMC, 0)
var clickActionMR = context.getPrefInt(PreferKey.clickActionMR, 1) var clickActionMR = appCtx.getPrefInt(PreferKey.clickActionMR, 1)
var clickActionBL = context.getPrefInt(PreferKey.clickActionBL, 2) var clickActionBL = appCtx.getPrefInt(PreferKey.clickActionBL, 2)
var clickActionBC = context.getPrefInt(PreferKey.clickActionBC, 1) var clickActionBC = appCtx.getPrefInt(PreferKey.clickActionBC, 1)
var clickActionBR = context.getPrefInt(PreferKey.clickActionBR, 1) var clickActionBR = appCtx.getPrefInt(PreferKey.clickActionBR, 1)
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) { when (key) {
PreferKey.themeMode -> isEInkMode = context.getPrefString(PreferKey.themeMode) == "3" PreferKey.themeMode -> isEInkMode = appCtx.getPrefString(PreferKey.themeMode) == "3"
PreferKey.clickActionTL -> clickActionTL = PreferKey.clickActionTL -> clickActionTL =
context.getPrefInt(PreferKey.clickActionTL, 2) appCtx.getPrefInt(PreferKey.clickActionTL, 2)
PreferKey.clickActionTC -> clickActionTC = PreferKey.clickActionTC -> clickActionTC =
context.getPrefInt(PreferKey.clickActionTC, 2) appCtx.getPrefInt(PreferKey.clickActionTC, 2)
PreferKey.clickActionTR -> clickActionTR = PreferKey.clickActionTR -> clickActionTR =
context.getPrefInt(PreferKey.clickActionTR, 2) appCtx.getPrefInt(PreferKey.clickActionTR, 2)
PreferKey.clickActionML -> clickActionML = PreferKey.clickActionML -> clickActionML =
context.getPrefInt(PreferKey.clickActionML, 2) appCtx.getPrefInt(PreferKey.clickActionML, 2)
PreferKey.clickActionMC -> clickActionMC = PreferKey.clickActionMC -> clickActionMC =
context.getPrefInt(PreferKey.clickActionMC, 2) appCtx.getPrefInt(PreferKey.clickActionMC, 2)
PreferKey.clickActionMR -> clickActionMR = PreferKey.clickActionMR -> clickActionMR =
context.getPrefInt(PreferKey.clickActionMR, 2) appCtx.getPrefInt(PreferKey.clickActionMR, 2)
PreferKey.clickActionBL -> clickActionBL = PreferKey.clickActionBL -> clickActionBL =
context.getPrefInt(PreferKey.clickActionBL, 2) appCtx.getPrefInt(PreferKey.clickActionBL, 2)
PreferKey.clickActionBC -> clickActionBC = PreferKey.clickActionBC -> clickActionBC =
context.getPrefInt(PreferKey.clickActionBC, 2) appCtx.getPrefInt(PreferKey.clickActionBC, 2)
PreferKey.clickActionBR -> clickActionBR = PreferKey.clickActionBR -> clickActionBR =
context.getPrefInt(PreferKey.clickActionBR, 2) appCtx.getPrefInt(PreferKey.clickActionBR, 2)
PreferKey.readBodyToLh -> ReadBookConfig.readBodyToLh = PreferKey.readBodyToLh -> ReadBookConfig.readBodyToLh =
context.getPrefBoolean(PreferKey.readBodyToLh, true) appCtx.getPrefBoolean(PreferKey.readBodyToLh, true)
PreferKey.userAgent -> userAgent = getPrefUserAgent() PreferKey.userAgent -> userAgent = getPrefUserAgent()
} }
} }
@ -61,109 +60,115 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
} }
var isNightTheme: Boolean var isNightTheme: Boolean
get() = isNightTheme(context) get() = isNightTheme(appCtx)
set(value) { set(value) {
if (isNightTheme != value) { if (isNightTheme != value) {
if (value) { if (value) {
context.putPrefString(PreferKey.themeMode, "2") appCtx.putPrefString(PreferKey.themeMode, "2")
} else { } else {
context.putPrefString(PreferKey.themeMode, "1") appCtx.putPrefString(PreferKey.themeMode, "1")
} }
} }
} }
val isTransparentStatusBar: Boolean val isTransparentStatusBar: Boolean
get() = context.getPrefBoolean(PreferKey.transparentStatusBar, true) get() = appCtx.getPrefBoolean(PreferKey.transparentStatusBar, true)
val immNavigationBar: Boolean val immNavigationBar: Boolean
get() = context.getPrefBoolean(PreferKey.immNavigationBar, true) get() = appCtx.getPrefBoolean(PreferKey.immNavigationBar, true)
val screenOrientation: String? val screenOrientation: String?
get() = context.getPrefString(PreferKey.screenOrientation) get() = appCtx.getPrefString(PreferKey.screenOrientation)
var backupPath: String? var backupPath: String?
get() = context.getPrefString(PreferKey.backupPath) get() = appCtx.getPrefString(PreferKey.backupPath)
set(value) { set(value) {
if (value.isNullOrEmpty()) { if (value.isNullOrEmpty()) {
context.removePref(PreferKey.backupPath) appCtx.removePref(PreferKey.backupPath)
} else { } else {
context.putPrefString(PreferKey.backupPath, value) appCtx.putPrefString(PreferKey.backupPath, value)
} }
} }
val isShowRSS: Boolean val isShowRSS: Boolean
get() = context.getPrefBoolean(PreferKey.showRss, true) get() = appCtx.getPrefBoolean(PreferKey.showRss, true)
val autoRefreshBook: Boolean val autoRefreshBook: Boolean
get() = context.getPrefBoolean(PreferKey.autoRefresh) get() = appCtx.getPrefBoolean(PreferKey.autoRefresh)
var threadCount: Int var threadCount: Int
get() = context.getPrefInt(PreferKey.threadCount, 16) get() = appCtx.getPrefInt(PreferKey.threadCount, 16)
set(value) { set(value) {
context.putPrefInt(PreferKey.threadCount, value) appCtx.putPrefInt(PreferKey.threadCount, value)
} }
var importBookPath: String? var importBookPath: String?
get() = context.getPrefString("importBookPath") get() = appCtx.getPrefString("importBookPath")
set(value) { set(value) {
if (value == null) { if (value == null) {
context.removePref("importBookPath") appCtx.removePref("importBookPath")
} else { } else {
context.putPrefString("importBookPath", value) appCtx.putPrefString("importBookPath", value)
} }
} }
var ttsSpeechRate: Int var ttsSpeechRate: Int
get() = context.getPrefInt(PreferKey.ttsSpeechRate, 5) get() = appCtx.getPrefInt(PreferKey.ttsSpeechRate, 5)
set(value) { set(value) {
context.putPrefInt(PreferKey.ttsSpeechRate, value) appCtx.putPrefInt(PreferKey.ttsSpeechRate, value)
} }
var chineseConverterType: Int var chineseConverterType: Int
get() = context.getPrefInt(PreferKey.chineseConverterType) get() = appCtx.getPrefInt(PreferKey.chineseConverterType)
set(value) { set(value) {
context.putPrefInt(PreferKey.chineseConverterType, value) appCtx.putPrefInt(PreferKey.chineseConverterType, value)
} }
var systemTypefaces: Int var systemTypefaces: Int
get() = context.getPrefInt(PreferKey.systemTypefaces) get() = appCtx.getPrefInt(PreferKey.systemTypefaces)
set(value) { set(value) {
context.putPrefInt(PreferKey.systemTypefaces, value) appCtx.putPrefInt(PreferKey.systemTypefaces, value)
} }
var elevation: Int var elevation: Int
get() = context.getPrefInt(PreferKey.barElevation, AppConst.sysElevation) get() = appCtx.getPrefInt(PreferKey.barElevation, AppConst.sysElevation)
set(value) { set(value) {
context.putPrefInt(PreferKey.barElevation, value) appCtx.putPrefInt(PreferKey.barElevation, value)
} }
var exportCharset: String var exportCharset: String
get() { get() {
val c = context.getPrefString(PreferKey.exportCharset) val c = appCtx.getPrefString(PreferKey.exportCharset)
if (c.isNullOrBlank()) { if (c.isNullOrBlank()) {
return "UTF-8" return "UTF-8"
} }
return c return c
} }
set(value) { 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 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 { private fun getPrefUserAgent(): String {
val ua = context.getPrefString(PreferKey.userAgent) val ua = appCtx.getPrefString(PreferKey.userAgent)
if (ua.isNullOrBlank()) { 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" return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
} }

@ -27,10 +27,11 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
book: Book, book: Book,
title: String, //已经经过简繁转换 title: String, //已经经过简繁转换
content: String, content: String,
isRead: Boolean = true isRead: Boolean = true,
useReplace: Boolean = book.getUseReplaceRule()
): List<String> { ): List<String> {
var content1 = content var content1 = content
if (book.getUseReplaceRule()) { if (useReplace) {
replaceRules.forEach { item -> replaceRules.forEach { item ->
if (item.pattern.isNotEmpty()) { if (item.pattern.isNotEmpty()) {
try { try {

@ -75,6 +75,11 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
return super.onPrepareOptionsMenu(menu) 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() { private fun upMenu() {
menu?.findItem(R.id.menu_book_group)?.subMenu?.let { subMenu -> menu?.findItem(R.id.menu_book_group)?.subMenu?.let { subMenu ->
subMenu.removeGroup(R.id.menu_group) subMenu.removeGroup(R.id.menu_group)
@ -100,6 +105,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
CacheBook.stop(this@CacheActivity) CacheBook.stop(this@CacheActivity)
} }
} }
R.id.menu_enable_replace -> AppConfig.exportUseReplace = !item.isChecked
R.id.menu_export_folder -> export(-1) R.id.menu_export_folder -> export(-1)
R.id.menu_export_charset -> showCharsetConfig() R.id.menu_export_charset -> showCharsetConfig()
R.id.menu_log -> R.id.menu_log ->

@ -9,6 +9,7 @@ import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.ContentProcessor import io.legado.app.help.ContentProcessor
import io.legado.app.help.storage.BookWebDav import io.legado.app.help.storage.BookWebDav
@ -86,6 +87,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
} }
private suspend fun getAllContents(book: Book): String { private suspend fun getAllContents(book: Book): String {
val useReplace = AppConfig.exportUseReplace
val contentProcessor = ContentProcessor(book.name, book.origin) val contentProcessor = ContentProcessor(book.name, book.origin)
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
stringBuilder.append(book.name) stringBuilder.append(book.name)
@ -94,7 +96,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter -> appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
BookHelp.getContent(book, chapter).let { content -> BookHelp.getContent(book, chapter).let { content ->
val content1 = contentProcessor val content1 = contentProcessor
.getContent(book, chapter.title, content ?: "null", false) .getContent(book, chapter.title, content ?: "null", false, useReplace)
.joinToString("\n") .joinToString("\n")
stringBuilder.append("\n\n") stringBuilder.append("\n\n")
.append(content1) .append(content1)

@ -20,6 +20,12 @@
</item> </item>
<item
android:id="@+id/menu_enable_replace"
android:title="@string/replace_purify"
android:checkable="true"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_export_folder" android:id="@+id/menu_export_folder"
android:title="@string/export_folder" android:title="@string/export_folder"

Loading…
Cancel
Save