mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
1786
app/schemas/io.legado.app.data.AppDatabase/61.json
Normal file
1786
app/schemas/io.legado.app.data.AppDatabase/61.json
Normal file
File diff suppressed because it is too large
Load Diff
16
app/src/main/assets/defaultData/dictRules.json
Normal file
16
app/src/main/assets/defaultData/dictRules.json
Normal file
@@ -0,0 +1,16 @@
|
||||
[
|
||||
{
|
||||
"name": "百度汉语",
|
||||
"urlRule": "https://dict.baidu.com/s?wd={{key}}",
|
||||
"showRule": "all",
|
||||
"enabled": true,
|
||||
"sortNumber": 0
|
||||
},
|
||||
{
|
||||
"name": "海词英文",
|
||||
"urlRule": "https://apii.dict.cn/mini.php?q={{key}}",
|
||||
"showRule": "all",
|
||||
"enabled": true,
|
||||
"sortNumber": 1
|
||||
}
|
||||
]
|
||||
@@ -20,7 +20,7 @@ val appDb by lazy {
|
||||
}
|
||||
|
||||
@Database(
|
||||
version = 60,
|
||||
version = 61,
|
||||
exportSchema = true,
|
||||
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
|
||||
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
|
||||
@@ -44,7 +44,8 @@ val appDb by lazy {
|
||||
AutoMigration(from = 56, to = 57),
|
||||
AutoMigration(from = 57, to = 58),
|
||||
AutoMigration(from = 58, to = 59),
|
||||
AutoMigration(from = 59, to = 60)
|
||||
AutoMigration(from = 59, to = 60),
|
||||
AutoMigration(from = 60, to = 61)
|
||||
]
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package io.legado.app.data.entities
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import io.legado.app.model.analyzeRule.AnalyzeRule
|
||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||
|
||||
/**
|
||||
* 字典规则
|
||||
@@ -12,5 +15,23 @@ data class DictRule(
|
||||
val name: String,
|
||||
var urlRule: String,
|
||||
var showRule: String,
|
||||
var enabled: Boolean
|
||||
)
|
||||
@ColumnInfo(defaultValue = "1")
|
||||
var enabled: Boolean = true,
|
||||
@ColumnInfo(defaultValue = "0")
|
||||
var sortNumber: Int = 0
|
||||
) {
|
||||
|
||||
/**
|
||||
* 搜索字典
|
||||
*/
|
||||
suspend fun search(word: String): String? {
|
||||
val analyzeUrl = AnalyzeUrl(urlRule, key = word)
|
||||
val body = analyzeUrl.getStrResponseAwait().body
|
||||
if (showRule.isBlank()) {
|
||||
return body
|
||||
}
|
||||
val analyzeRule = AnalyzeRule()
|
||||
return analyzeRule.getString(showRule, mContent = body)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package io.legado.app.help
|
||||
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.HttpTTS
|
||||
import io.legado.app.data.entities.KeyboardAssist
|
||||
import io.legado.app.data.entities.RssSource
|
||||
import io.legado.app.data.entities.TxtTocRule
|
||||
import io.legado.app.data.entities.*
|
||||
import io.legado.app.help.config.ReadBookConfig
|
||||
import io.legado.app.help.config.ThemeConfig
|
||||
import io.legado.app.model.BookCover
|
||||
@@ -68,6 +65,14 @@ object DefaultData {
|
||||
GSON.fromJsonObject<BookCover.CoverRule>(json).getOrThrow()!!
|
||||
}
|
||||
|
||||
val dictRules: List<DictRule> by lazy {
|
||||
val json = String(
|
||||
appCtx.assets.open("defaultData${File.separator}dictRules.json")
|
||||
.readBytes()
|
||||
)
|
||||
GSON.fromJsonArray<DictRule>(json).getOrThrow()!!
|
||||
}
|
||||
|
||||
val keyboardAssists: List<KeyboardAssist> by lazy {
|
||||
val json = String(
|
||||
appCtx.assets.open("defaultData${File.separator}keyboardAssists.json")
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.legado.app.ui.dict
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.help.DefaultData
|
||||
import io.legado.app.help.http.get
|
||||
import io.legado.app.help.http.newCallStrResponse
|
||||
import io.legado.app.help.http.okHttpClient
|
||||
@@ -49,20 +50,21 @@ class DictViewModel(application: Application) : BaseViewModel(application) {
|
||||
*/
|
||||
private fun baiduDict(word: String) {
|
||||
execute {
|
||||
val body = okHttpClient.newCallStrResponse {
|
||||
get("https://dict.baidu.com/s", mapOf(Pair("wd", word)))
|
||||
}.body
|
||||
val jsoup = Jsoup.parse(body!!)
|
||||
jsoup.select("script").remove()//移除script
|
||||
jsoup.select("#word-header").remove()//移除单字的header
|
||||
jsoup.select("#term-header").remove()//移除词语的header
|
||||
jsoup.select(".more-button").remove()//移除展示更多
|
||||
jsoup.select(".disactive").remove()
|
||||
jsoup.select("#download-wrapper").remove()//移除下载广告
|
||||
jsoup.select("#right-panel").remove()//移除右侧广告
|
||||
jsoup.select("#content-panel")
|
||||
// val body = okHttpClient.newCallStrResponse {
|
||||
// get("https://dict.baidu.com/s", mapOf(Pair("wd", word)))
|
||||
// }.body
|
||||
// val jsoup = Jsoup.parse(body!!)
|
||||
// jsoup.select("script").remove()//移除script
|
||||
// jsoup.select("#word-header").remove()//移除单字的header
|
||||
// jsoup.select("#term-header").remove()//移除词语的header
|
||||
// jsoup.select(".more-button").remove()//移除展示更多
|
||||
// jsoup.select(".disactive").remove()
|
||||
// jsoup.select("#download-wrapper").remove()//移除下载广告
|
||||
// jsoup.select("#right-panel").remove()//移除右侧广告
|
||||
// jsoup.select("#content-panel")
|
||||
DefaultData.dictRules[0].search(word)
|
||||
}.onSuccess {
|
||||
dictHtmlData.postValue(it.html())
|
||||
dictHtmlData.postValue(it)
|
||||
}.onError {
|
||||
context.toastOnUi(it.localizedMessage)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user