优化
This commit is contained in:
Vendored
+2
-2
@@ -250,8 +250,8 @@
|
|||||||
## 对外提供api
|
## 对外提供api
|
||||||
-keep class io.legado.app.api.ReturnData{*;}
|
-keep class io.legado.app.api.ReturnData{*;}
|
||||||
|
|
||||||
# Apache Commons Compress
|
# 繁简转换
|
||||||
-keep class org.apache.commons.compress.archivers.** {*;}
|
-keep class com.github.liuyueyi.quick.transfer.** {*;}
|
||||||
|
|
||||||
|
|
||||||
#-------------------Cronet------------------------------------
|
#-------------------Cronet------------------------------------
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.content.Context
|
|||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import com.github.liuyueyi.quick.transfer.ChineseUtils
|
|
||||||
import com.github.liuyueyi.quick.transfer.constants.TransType
|
import com.github.liuyueyi.quick.transfer.constants.TransType
|
||||||
import com.jeremyliao.liveeventbus.LiveEventBus
|
import com.jeremyliao.liveeventbus.LiveEventBus
|
||||||
import io.legado.app.base.AppContextWrapper
|
import io.legado.app.base.AppContextWrapper
|
||||||
@@ -31,6 +30,7 @@ import io.legado.app.help.http.okHttpClient
|
|||||||
import io.legado.app.help.source.SourceHelp
|
import io.legado.app.help.source.SourceHelp
|
||||||
import io.legado.app.help.storage.Backup
|
import io.legado.app.help.storage.Backup
|
||||||
import io.legado.app.model.BookCover
|
import io.legado.app.model.BookCover
|
||||||
|
import io.legado.app.utils.ChineseUtils
|
||||||
import io.legado.app.utils.defaultSharedPreferences
|
import io.legado.app.utils.defaultSharedPreferences
|
||||||
import io.legado.app.utils.getPrefBoolean
|
import io.legado.app.utils.getPrefBoolean
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -73,7 +73,10 @@ class App : Application() {
|
|||||||
Backup.clearCache()
|
Backup.clearCache()
|
||||||
//初始化简繁转换引擎
|
//初始化简繁转换引擎
|
||||||
when (AppConfig.chineseConverterType) {
|
when (AppConfig.chineseConverterType) {
|
||||||
1 -> ChineseUtils.preLoad(true, TransType.TRADITIONAL_TO_SIMPLE)
|
1 -> launch {
|
||||||
|
ChineseUtils.fixT2sDict()
|
||||||
|
}
|
||||||
|
|
||||||
2 -> ChineseUtils.preLoad(true, TransType.SIMPLE_TO_TRADITIONAL)
|
2 -> ChineseUtils.preLoad(true, TransType.SIMPLE_TO_TRADITIONAL)
|
||||||
}
|
}
|
||||||
//调整排序序号
|
//调整排序序号
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import androidx.room.Entity
|
|||||||
import androidx.room.ForeignKey
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.Ignore
|
import androidx.room.Ignore
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import com.github.liuyueyi.quick.transfer.ChineseUtils
|
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.constant.AppPattern
|
import io.legado.app.constant.AppPattern
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import android.webkit.WebSettings
|
|||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
import cn.hutool.core.codec.Base64
|
import cn.hutool.core.codec.Base64
|
||||||
import cn.hutool.core.util.HexUtil
|
import cn.hutool.core.util.HexUtil
|
||||||
import com.github.liuyueyi.quick.transfer.ChineseUtils
|
import io.legado.app.utils.ChineseUtils
|
||||||
import io.legado.app.constant.AppConst
|
import io.legado.app.constant.AppConst
|
||||||
import io.legado.app.constant.AppConst.dateFormat
|
import io.legado.app.constant.AppConst.dateFormat
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package io.legado.app.help.book
|
package io.legado.app.help.book
|
||||||
|
|
||||||
import com.github.liuyueyi.quick.transfer.ChineseUtils
|
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.constant.AppPattern.spaceRegex
|
import io.legado.app.constant.AppPattern.spaceRegex
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
@@ -10,6 +9,7 @@ import io.legado.app.data.entities.ReplaceRule
|
|||||||
import io.legado.app.exception.RegexTimeoutException
|
import io.legado.app.exception.RegexTimeoutException
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.help.config.ReadBookConfig
|
import io.legado.app.help.config.ReadBookConfig
|
||||||
|
import io.legado.app.utils.ChineseUtils
|
||||||
import io.legado.app.utils.escapeRegex
|
import io.legado.app.utils.escapeRegex
|
||||||
import io.legado.app.utils.replace
|
import io.legado.app.utils.replace
|
||||||
import io.legado.app.utils.stackTraceStr
|
import io.legado.app.utils.stackTraceStr
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.core.view.get
|
import androidx.core.view.get
|
||||||
import com.github.liuyueyi.quick.transfer.ChineseUtils
|
|
||||||
import com.github.liuyueyi.quick.transfer.constants.TransType
|
import com.github.liuyueyi.quick.transfer.constants.TransType
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseDialogFragment
|
import io.legado.app.base.BaseDialogFragment
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package io.legado.app.ui.book.searchContent
|
|||||||
|
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import com.github.liuyueyi.quick.transfer.ChineseUtils
|
|
||||||
import io.legado.app.base.BaseViewModel
|
import io.legado.app.base.BaseViewModel
|
||||||
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
|
||||||
@@ -10,13 +9,14 @@ import io.legado.app.data.entities.BookChapter
|
|||||||
import io.legado.app.help.book.BookHelp
|
import io.legado.app.help.book.BookHelp
|
||||||
import io.legado.app.help.book.ContentProcessor
|
import io.legado.app.help.book.ContentProcessor
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
|
import io.legado.app.utils.ChineseUtils
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
import kotlin.coroutines.coroutineContext
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
class SearchContentViewModel(application: Application) : BaseViewModel(application) {
|
class SearchContentViewModel(application: Application) : BaseViewModel(application) {
|
||||||
var bookUrl: String = ""
|
var bookUrl: String = ""
|
||||||
var book: Book? = null
|
var book: Book? = null
|
||||||
var contentProcessor: ContentProcessor? = null
|
private var contentProcessor: ContentProcessor? = null
|
||||||
var lastQuery: String = ""
|
var lastQuery: String = ""
|
||||||
var searchResultCounts = 0
|
var searchResultCounts = 0
|
||||||
val cacheChapterNames = hashSetOf<String>()
|
val cacheChapterNames = hashSetOf<String>()
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package io.legado.app.utils
|
||||||
|
|
||||||
|
import com.github.liuyueyi.quick.transfer.ChineseUtils
|
||||||
|
import com.github.liuyueyi.quick.transfer.constants.TransType
|
||||||
|
import com.github.liuyueyi.quick.transfer.dictionary.DictionaryContainer
|
||||||
|
|
||||||
|
object ChineseUtils {
|
||||||
|
|
||||||
|
private var fixed = false
|
||||||
|
|
||||||
|
fun s2t(content: String): String {
|
||||||
|
return ChineseUtils.s2t(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun t2s(content: String): String {
|
||||||
|
if (!fixed) {
|
||||||
|
fixed = true
|
||||||
|
fixT2sDict()
|
||||||
|
}
|
||||||
|
return ChineseUtils.t2s(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun preLoad(async: Boolean, vararg transType: TransType) {
|
||||||
|
ChineseUtils.preLoad(async, *transType)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unLoad(vararg transType: TransType) {
|
||||||
|
ChineseUtils.unLoad(*transType)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fixT2sDict() {
|
||||||
|
val dict = DictionaryContainer.getInstance().getDictionary(TransType.TRADITIONAL_TO_SIMPLE)
|
||||||
|
dict.chars.run {
|
||||||
|
remove('劈')
|
||||||
|
remove('脊')
|
||||||
|
}
|
||||||
|
kotlin.runCatching {
|
||||||
|
dict.dict.run {
|
||||||
|
remove("支援")
|
||||||
|
remove("路易斯")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package io.legado.app.utils
|
||||||
|
|
||||||
|
import com.github.liuyueyi.quick.transfer.Trie
|
||||||
|
import com.github.liuyueyi.quick.transfer.TrieNode
|
||||||
|
import java.util.HashMap
|
||||||
|
|
||||||
|
fun <T> Trie<T>.getRoot(): TrieNode<T> {
|
||||||
|
val rootField = javaClass.getDeclaredField("root")
|
||||||
|
.apply { isAccessible = true }
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return rootField.get(this) as TrieNode<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> TrieNode<T>.getChildren(): HashMap<Char, TrieNode<T>> {
|
||||||
|
val childrenField = javaClass.getDeclaredField("children")
|
||||||
|
.apply { isAccessible = true }
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return childrenField.get(this) as HashMap<Char, TrieNode<T>>
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> Trie<T>.remove(value: String) {
|
||||||
|
var node = getRoot()
|
||||||
|
val nodes = arrayListOf<TrieNode<T>>()
|
||||||
|
val chars = value.toCharArray()
|
||||||
|
for (c in chars) {
|
||||||
|
nodes.add(node)
|
||||||
|
node = node.getChildren()[c] ?: break
|
||||||
|
if (!node.isLeaf) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for ((ch, n) in chars.reversed().zip(nodes.reversed())) {
|
||||||
|
val children = n.getChildren()
|
||||||
|
children.remove(ch)
|
||||||
|
if (children.isNotEmpty()) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user