From f21682229f12bd5f8ea4679dba9a9792b4b03413 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 16 Jan 2021 12:09:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=AE=A2=E9=98=85=E6=BA=90,=E9=98=85=E8=AF=BB?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/assets/defaultData/rssSources.json | 21 +++++++++++++++++++ .../java/io/legado/app/help/DefaultData.kt | 13 ++++++++++++ .../java/io/legado/app/help/LocalConfig.kt | 3 +++ .../java/io/legado/app/help/storage/Backup.kt | 4 ++-- .../io/legado/app/help/storage/Restore.kt | 2 +- .../io/legado/app/ui/main/MainViewModel.kt | 3 +++ 6 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 app/src/main/assets/defaultData/rssSources.json diff --git a/app/src/main/assets/defaultData/rssSources.json b/app/src/main/assets/defaultData/rssSources.json new file mode 100644 index 000000000..b4b2a70e0 --- /dev/null +++ b/app/src/main/assets/defaultData/rssSources.json @@ -0,0 +1,21 @@ +[ + { + "articleStyle": 0, + "customOrder": 1, + "enableJs": true, + "enabled": true, + "loadWithBaseUrl": false, + "ruleArticles": "class.release-main-section||tbody@tr", + "ruleContent": "@js:\nif(baseUrl.match(\/90pan\/)){\nresult=result.replace(\/true\\||<.*?>([^<]+)<\\\/span><\\\/a>\/g,'

$2<\/a><\/h4>

$1<\/p>\\n\\n')}\nelse{\nhtml=String(java.getString(\"@@class.markdown-body@html\",false)+java.getString(\"@@class.flex-justify-between.-1@html\",false));\nhref='https:\/\/github.com'+String(java.getString(\"@@class.flex-justify-between.-1@class.Box-body.0@a@href\",false))\nhtml+'

下载地址:<\/p>'+href+'<\/a>'\n}", + "ruleImage": "@js:if(baseUrl.match(\/legado|704\/g)){\nresult='https:\/\/urlmin.cn\/034'\n}else{result=\"https:\/\/urlmin.cn\/15c\"}", + "ruleLink": "tag.a.0@href\n@js:if(baseUrl.match(\/90pan\/)){\nresult='https:\/\/www.90pan.com\/ajax.php,{\"method\": \"POST\",\"body\": \"action=load_down_addr1&file_id='+result.match(\/b(\\d+)\/)[1]+'\"}'}else{\nresult='https:\/\/github.com'+result\n}", + "ruleNextPage": "text.Next@href", + "rulePubDate": "tag.td!0@text||class.markdown-body@text##\\n##·", + "ruleTitle": "tag.a.0@text", + "sortUrl": "阅读2.0·GitHub::https:\/\/github.com\/gedoor\/MyBookshelf\/releases\n阅读3.0·GitHub::https:\/\/github.com\/gedoor\/legado\/releases\n阅读2.0·90盘::https:\/\/www.90pan.com\/o138703\n阅读3.0·90盘::https:\/\/www.90pan.com\/o138704", + "sourceIcon": "http:\/\/ku.mumuceo.com\/static\/images\/applogo\/yuedu.png", + "sourceName": "阅读下载", + "sourceUrl": "https:\/\/github.com\/gedoor\/legado\/releases", + "style": "" + } +] \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/DefaultData.kt b/app/src/main/java/io/legado/app/help/DefaultData.kt index d2bab07f1..26d94814a 100644 --- a/app/src/main/java/io/legado/app/help/DefaultData.kt +++ b/app/src/main/java/io/legado/app/help/DefaultData.kt @@ -2,6 +2,7 @@ package io.legado.app.help import io.legado.app.App import io.legado.app.data.entities.HttpTTS +import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.TxtTocRule import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonArray @@ -45,6 +46,14 @@ object DefaultData { GSON.fromJsonArray(json)!! } + val rssSources by lazy { + val json = String( + App.INSTANCE.assets.open("defaultData${File.separator}rssSources.json") + .readBytes() + ) + GSON.fromJsonArray(json)!! + } + fun importDefaultHttpTTS() { App.db.httpTTSDao.deleteDefault() httpTTS.let { @@ -58,4 +67,8 @@ object DefaultData { App.db.txtTocRule.insert(*it.toTypedArray()) } } + + fun importDefaultRssSources() { + App.db.rssSourceDao.insert(*rssSources.toTypedArray()) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/LocalConfig.kt b/app/src/main/java/io/legado/app/help/LocalConfig.kt index ac0d3034d..71c529a04 100644 --- a/app/src/main/java/io/legado/app/help/LocalConfig.kt +++ b/app/src/main/java/io/legado/app/help/LocalConfig.kt @@ -69,4 +69,7 @@ object LocalConfig { val hasUpTxtTocRule: Boolean get() = isLastVersion(1, "txtTocRuleVersion") + + val hasUpRssSources: Boolean + get() = isLastVersion(1, "rssSourceVersion") } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 1686df19e..a26f5174f 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -29,7 +29,7 @@ object Backup { "bookmark.json", "bookGroup.json", "bookSource.json", - "rssSource.json", + "rssSources.json", "rssStar.json", "replaceRule.json", "readRecord.json", @@ -61,7 +61,7 @@ object Backup { writeListToJson(App.db.bookmarkDao.all, "bookmark.json", backupPath) writeListToJson(App.db.bookGroupDao.all, "bookGroup.json", backupPath) writeListToJson(App.db.bookSourceDao.all, "bookSource.json", backupPath) - writeListToJson(App.db.rssSourceDao.all, "rssSource.json", backupPath) + writeListToJson(App.db.rssSourceDao.all, "rssSources.json", backupPath) writeListToJson(App.db.rssStarDao.all, "rssStar.json", backupPath) writeListToJson(App.db.replaceRuleDao.all, "replaceRule.json", backupPath) writeListToJson(App.db.readRecordDao.all, "readRecord.json", backupPath) diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index b0d833b0c..212152849 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -122,7 +122,7 @@ object Restore { fileToListT(path, "bookSource.json")?.let { App.db.bookSourceDao.insert(*it.toTypedArray()) } - fileToListT(path, "rssSource.json")?.let { + fileToListT(path, "rssSources.json")?.let { App.db.rssSourceDao.insert(*it.toTypedArray()) } fileToListT(path, "rssStar.json")?.let { diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 88969fe5d..c115e661a 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -157,6 +157,9 @@ class MainViewModel(application: Application) : BaseViewModel(application) { if (LocalConfig.hasUpTxtTocRule) { DefaultData.importDefaultTocRules() } + if (LocalConfig.hasUpRssSources) { + DefaultData.importDefaultRssSources() + } } } } \ No newline at end of file