From c96774783b5ae0114cdef13438ae9e762af9fa4f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 9 Nov 2019 18:38:17 +0800 Subject: [PATCH] up --- app/src/main/assets/rssSource.json | 319 ++++++++++++++++++ .../io/legado/app/data/dao/RssSourceDao.kt | 3 + .../io/legado/app/ui/main/MainActivity.kt | 6 +- .../io/legado/app/ui/main/MainViewModel.kt | 21 +- 4 files changed, 344 insertions(+), 5 deletions(-) create mode 100644 app/src/main/assets/rssSource.json diff --git a/app/src/main/assets/rssSource.json b/app/src/main/assets/rssSource.json new file mode 100644 index 000000000..1cdc02066 --- /dev/null +++ b/app/src/main/assets/rssSource.json @@ -0,0 +1,319 @@ +[ + { + "customOrder": 14, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "class.wrap", + "ruleContent": "@js:String(result).replace(/
').replace(/
[\\s\\S]*/,\"\")", + "ruleImage": "tag.img@src", + "ruleLink": "class.link-button@href", + "rulePubDate": "", + "ruleTitle": "class.title@text", + "sourceGroup": "Origin", + "sourceIcon": "http://static.daily.zhihu.com/img/app-logo.png", + "sourceName": "知乎日報", + "sourceUrl": "https://daily.zhihu.com" + }, + { + "customOrder": 2, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "@css:.cell.item", + "ruleContent": "@js:var doc=org.jsoup.Jsoup.parse(result);\n\"

\"+doc.select(\"h1\").text()+\"

\"+String(doc.select(\"#img-content\").html()).replace(/data-src=/g,\"src=\")", + "ruleImage": "@css:.topic_image>img@src", + "ruleLink": "@css:.item_title>a@href", + "rulePubDate": "@css:.fade@text", + "ruleTitle": "@css:.item_title@text", + "sourceGroup": "JTKS", + "sourceIcon": "https://gitee.com/alanskycn/yuedu/raw/master/JS/xiaoshuoshiyi.jpg", + "sourceName": "小說拾遺", + "sourceUrl": "http://www.jintiankansha.me/column/LoglHJhFTR" + }, + { + "customOrder": 1, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "@css:.cell.item", + "ruleContent": "var doc=org.jsoup.Jsoup.parse(result);\n\"

\"+doc.select(\"h1\").text()+\"

\"+String(doc.select(\"#img-content\").html()).replace(/data-src=/g,\"src=\")
", + "ruleImage": "@css:.topic_image>img@src", + "ruleLink": "@css:.item_title>a@href", + "rulePubDate": "@css:.fade@text", + "ruleTitle": "@css:.item_title@text", + "sourceGroup": "JTKS", + "sourceIcon": "http://img.100weidu.com/weixin/head/MzI5NTA4NjgwNw==", + "sourceName": "赤戟的书荒救济所", + "sourceUrl": "http://www.jintiankansha.me/column/qOcZgyKfdi" + }, + { + "customOrder": 3, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "@css:.t_news", + "ruleContent": "@js:org.jsoup.Jsoup.parse(result).select(\".news_content\").html()", + "ruleImage": "@css:.img_t>a:eq(0)>img@src##^##https:", + "ruleLink": "@css:.news_tit02 a@href", + "rulePubDate": "@css:.news_info>span:eq(1)@text", + "ruleTitle": "@css:.news_tit02 a@text", + "sourceGroup": "", + "sourceIcon": "https://file.thepaper.cn/wap/v3/img/deskicon.png", + "sourceName": "澎湃新闻", + "sourceUrl": "https://m.thepaper.cn/" + }, + { + "customOrder": 6, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/qdaily.jpg", + "sourceName": "好奇心日报", + "sourceUrl": "http://47.105.79.245/v3/article?feedId=13&articleId=0&pageSize=20&isLookDown=true" + }, + { + "customOrder": 5, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/mtime.jpg", + "sourceName": "时光网", + "sourceUrl": "http://47.105.79.245/v3/article?feedId=27&articleId=0&pageSize=20&isLookDown=true" + }, + { + "customOrder": 8, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/zimuzu-9999x0w.jpg", + "sourceName": "字幕组", + "sourceUrl": "http://47.105.79.245/v3/article?feedId=3&articleId=0&pageSize=20&isLookDown=true" + }, + { + "customOrder": 11, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/doubanmoviereview.jpg", + "sourceName": "豆瓣最受欢迎的影评", + "sourceUrl": "http://47.105.79.245/v3/article?feedId=76&articleId=0&pageSize=20&isLookDown=true" + }, + { + "customOrder": 7, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/anitama.jpg", + "sourceName": "Anitama", + "sourceUrl": "http://47.105.79.245/v3/article?feedId=86&articleId=0&pageSize=20&isLookDown=true" + }, + { + "customOrder": 12, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/nfw.png", + "sourceName": "南方要闻", + "sourceUrl": "http://47.105.79.245/v2/article/newest,{\n \"headers\": \"{User-Agent:\\\"okhttp/3.10.0\\\",Content-Type:\\\"application/json; charset=UTF-8\\\",Content-Length:27}\",\n \"method\": \"POST\",\n \"body\": \"{\\\"articleId\\\":0,\\\"feedId\\\":80}\"\n}" + }, + { + "customOrder": 9, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/iplaysoft.png", + "sourceName": "异次元软件世界", + "sourceUrl": "http://47.105.79.245/v2/article/newest,{\n \"headers\": \"{User-Agent:\\\"okhttp/3.10.0\\\",Content-Type:\\\"application/json; charset=UTF-8\\\",Content-Length:27}\",\n \"method\": \"POST\",\n \"body\": \"{\\\"articleId\\\":0,\\\"feedId\\\":51}\"\n}" + }, + { + "customOrder": 13, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/appin.png", + "sourceName": "小众软件", + "sourceUrl": "http://47.105.79.245/v2/article/newest,{\n \"headers\": \"{User-Agent:\\\"okhttp/3.10.0\\\",Content-Type:\\\"application/json; charset=UTF-8\\\",Content-Length:27}\",\n \"method\": \"POST\",\n \"body\": \"{\\\"articleId\\\":0,\\\"feedId\\\":14}\"\n}" + }, + { + "customOrder": 15, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/zhangzishi.png", + "sourceName": "涨姿势", + "sourceUrl": "http://47.105.79.245/v2/article/newest,{\n \"headers\": \"{User-Agent:\\\"okhttp/3.10.0\\\",Content-Type:\\\"application/json; charset=UTF-8\\\",Content-Length:27}\",\n \"method\": \"POST\",\n \"body\": \"{\\\"articleId\\\":0,\\\"feedId\\\":78}\"\n}" + }, + { + "customOrder": 16, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/penti.png", + "sourceName": "喷嚏图卦", + "sourceUrl": "http://47.105.79.245/v3/article?feedId=66&articleId=0&pageSize=20&isLookDown=true" + }, + { + "customOrder": 17, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/guancha.jpg", + "sourceName": "观察者 要闻", + "sourceUrl": "http://47.105.79.245/v2/article/newest,{\n \"headers\": \"{User-Agent:\\\"okhttp/3.10.0\\\",Content-Type:\\\"application/json; charset=UTF-8\\\",Content-Length:28}\",\n \"method\": \"POST\",\n \"body\": \"{\\\"articleId\\\":0,\\\"feedId\\\":105}\"\n}" + }, + { + "customOrder": 18, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/meiriyiwen.png", + "sourceName": "每日一文", + "sourceUrl": "http://47.105.79.245/v2/article/newest,{\n \"headers\": \"{User-Agent:\\\"okhttp/3.10.0\\\",Content-Type:\\\"application/json; charset=UTF-8\\\",Content-Length:27}\",\n \"method\": \"POST\",\n \"body\": \"{\\\"articleId\\\":0,\\\"feedId\\\":87}\"\n}" + }, + { + "customOrder": 4, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": false, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "http://47.105.79.245/netease.jpg", + "sourceName": "网易要闻", + "sourceUrl": "http://47.105.79.245/v2/article/newest,{\n \"headers\": \"{User-Agent:\\\"okhttp/3.10.0\\\",Content-Type:\\\"application/json; charset=UTF-8\\\",Content-Length:27}\",\n \"method\": \"POST\",\n \"body\": \"{\\\"articleId\\\":0,\\\"feedId\\\":98}\"\n}" + }, + { + "customOrder": 19, + "enableJs": false, + "enabled": true, + "loadWithBaseUrl": false, + "ruleArticles": "$.data.data[*]", + "ruleContent": "

{$.data.title}

时间:{$.data.createTimeString}({$.data.createTime})

{$.data.content}原文链接", + "ruleDescription": "", + "ruleImage": "$.thumbnail", + "ruleLink": "http://47.105.79.245/v2/text/{$.id}", + "rulePubDate": "$.createTimeString", + "ruleTitle": "$.title", + "sourceGroup": "", + "sourceIcon": "https://static.zhihu.com/heifetz/assets/apple-touch-icon-120.b3e6278d.png", + "sourceName": "知乎每日精选", + "sourceUrl": "http://47.105.79.245/v2/article/newest,{\n \"headers\": \"{User-Agent:\\\"okhttp/3.10.0\\\",Content-Type:\\\"application/json; charset=UTF-8\\\",Content-Length:26}\",\n \"method\": \"POST\",\n \"body\": \"{\\\"articleId\\\":0,\\\"feedId\\\":8}\"\n}" + }, + { + "customOrder": 0, + "enableJs": true, + "enabled": true, + "loadWithBaseUrl": true, + "ruleArticles": "@css:.booklist-card", + "ruleContent": "", + "ruleLink": "@css:.booklist-card-content>a@href##^##http://www\\.yousuu\\.com", + "rulePubDate": "@css:.ResultBooklistItemClasses,.ResultBooklistItemUpdateAt@text##,,##,", + "ruleTitle": "@css:.booklist-card-content>a@text", + "sourceGroup": "", + "sourceIcon": "https://gitee.com/alanskycn/yuedu/raw/master/JS/youshuwang.png", + "sourceName": "优书网", + "sourceUrl": "http://www.yousuu.com/booklists?type=man&screen=latest&page=1" + } +] \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index 6a70e4666..273dcb20d 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -13,6 +13,9 @@ interface RssSourceDao { @get:Query("SELECT * FROM rssSources") val all: List + @get:Query("select count(sourceUrl) from rssSources") + val size: Int + @Query("SELECT * FROM rssSources order by customOrder") fun liveAll(): LiveData> diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 1c9e0a18b..d02003ddc 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -68,10 +68,12 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), PermissionsCompat.Builder(this@MainActivity) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) - .onGranted { viewModel.restore() } + .onGranted { viewModel.importYueDuData() } .request() } - noButton { } + noButton { + viewModel.initRssSource() + } }.show().applyTint() } } 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 d1146aae8..23c4b7511 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 @@ -5,19 +5,22 @@ import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.constant.BookType import io.legado.app.constant.Bus +import io.legado.app.data.entities.RssSource import io.legado.app.help.storage.Restore import io.legado.app.model.WebBook +import io.legado.app.utils.GSON +import io.legado.app.utils.fromJsonArray import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.delay -import kotlinx.coroutines.launch class MainViewModel(application: Application) : BaseViewModel(application) { val updateList = arrayListOf() - fun restore() { - launch(IO) { + fun importYueDuData() { + execute { Restore.importYueDuData(getApplication()) + initRssSource() } } @@ -57,4 +60,16 @@ class MainViewModel(application: Application) : BaseViewModel(application) { } } } + + fun initRssSource() { + execute { + if (App.db.rssSourceDao().size == 0) { + val json = String(context.assets.open("rssSource.json").readBytes()) + val sources = GSON.fromJsonArray(json) + if (sources != null) { + App.db.rssSourceDao().insert(*sources.toTypedArray()) + } + } + } + } } \ No newline at end of file