From 975fac27727ef64d31764a66cffd1846d21b4759 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 12 Oct 2019 14:34:47 +0800 Subject: [PATCH] up --- .../io/legado/app/data/entities/RssSource.kt | 2 +- .../legado/app/model/rss/RssParserByRule.kt | 10 +------- .../legado/app/ui/rss/read/ReadRssActivity.kt | 23 +++++++++++++------ .../rss/source/edit/RssSourceEditActivity.kt | 4 ++-- .../res/layout/activity_rss_source_edit.xml | 19 ++++++++++++++- app/src/main/res/values/strings.xml | 1 + 6 files changed, 39 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index 79e74a496..89c25d75a 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -18,7 +18,6 @@ data class RssSource( //列表规则 var ruleArticles: String? = null, var ruleTitle: String? = null, - var ruleAuthor: String? = null, var rulePubDate: String? = null, //类别规则 var ruleCategories: String? = null, @@ -28,5 +27,6 @@ data class RssSource( var ruleLink: String? = null, var ruleContent: String? = null, var enableJs: Boolean = false, + var loadWithBaseUrl: Boolean = true, var customOrder: Int = 0 ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index 476c6a49e..d5fea37fd 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -35,12 +35,10 @@ object RssParserByRule { } val collections = analyzeRule.getElements(ruleArticles) val ruleTitle = analyzeRule.splitSourceRule(rssSource.ruleTitle ?: "") - val ruleAuthor = analyzeRule.splitSourceRule(rssSource.ruleAuthor ?: "") val rulePubDate = analyzeRule.splitSourceRule(rssSource.rulePubDate ?: "") val ruleCategories = analyzeRule.splitSourceRule(rssSource.ruleCategories ?: "") val ruleDescription = analyzeRule.splitSourceRule(rssSource.ruleDescription ?: "") val ruleImage = analyzeRule.splitSourceRule(rssSource.ruleImage ?: "") - val ruleContent = analyzeRule.splitSourceRule(rssSource.ruleContent ?: "") val ruleLink = analyzeRule.splitSourceRule(rssSource.ruleLink ?: "") for ((index, item) in collections.withIndex()) { getItem( @@ -48,12 +46,10 @@ object RssParserByRule { analyzeRule, index == 0, ruleTitle, - ruleAuthor, rulePubDate, ruleCategories, ruleDescription, ruleImage, - ruleContent, ruleLink )?.let { it.origin = rssSource.sourceUrl @@ -75,24 +71,20 @@ object RssParserByRule { analyzeRule: AnalyzeRule, printLog: Boolean, ruleTitle: List, - ruleAuthor: List, rulePubDate: List, ruleCategories: List, ruleDescription: List, ruleImage: List, - ruleContent: List, ruleLink: List ): RssArticle? { val rssArticle = RssArticle() analyzeRule.setContent(item) rssArticle.title = analyzeRule.getString(ruleTitle) - rssArticle.author = analyzeRule.getString(ruleAuthor) rssArticle.pubDate = analyzeRule.getString(rulePubDate) rssArticle.categories = analyzeRule.getString(ruleCategories) rssArticle.description = analyzeRule.getString(ruleDescription) - rssArticle.image = analyzeRule.getString(ruleImage) + rssArticle.image = analyzeRule.getString(ruleImage, true) rssArticle.link = analyzeRule.getString(ruleLink) - rssArticle.content = analyzeRule.getString(ruleContent) if (rssArticle.title.isBlank()) { return null } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 40419697a..5813ec48d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -26,6 +26,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r private fun initWebView() { webView.webViewClient = WebViewClient() webView.settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW + webView.settings.domStorageEnabled = true } @SuppressLint("SetJavaScriptEnabled") @@ -38,13 +39,21 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r viewModel.contentLiveData.observe(this, Observer { content -> viewModel.rssArticle?.let { val url = NetworkUtils.getAbsoluteURL(it.origin, it.link ?: "") - webView.loadDataWithBaseURL( - url, - "$content", - "text/html", - "utf-8", - url - ) + if (viewModel.rssSourceLiveData.value?.loadWithBaseUrl == true) { + webView.loadDataWithBaseURL( + url, + "$content", + "text/html", + "utf-8", + url + ) + } else { + webView.loadData( + "$content", + "text/html", + "utf-8" + ) + } } }) viewModel.urlLiveData.observe(this, Observer { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 9233ef8fa..a27b81025 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -102,6 +102,7 @@ class RssSourceEditActivity : rssSource?.let { cb_is_enable.isChecked = rssSource.enabled cb_enable_js.isChecked = rssSource.enableJs + cb_enable_base_url.isChecked = rssSource.loadWithBaseUrl } sourceEntities.clear() sourceEntities.apply { @@ -111,7 +112,6 @@ class RssSourceEditActivity : add(EditEntity("sourceGroup", rssSource?.sourceGroup, R.string.rss_source_group)) add(EditEntity("ruleArticles", rssSource?.ruleArticles, R.string.rss_rule_articles)) add(EditEntity("ruleTitle", rssSource?.ruleTitle, R.string.rss_rule_title)) - add(EditEntity("ruleAuthor", rssSource?.ruleAuthor, R.string.rss_rule_author)) add(EditEntity("rulePubDate", rssSource?.rulePubDate, R.string.rss_rule_date)) add( EditEntity( @@ -138,6 +138,7 @@ class RssSourceEditActivity : val source = viewModel.sourceLiveData.value ?: RssSource() source.enabled = cb_is_enable.isChecked source.enableJs = cb_enable_js.isChecked + source.loadWithBaseUrl = cb_enable_base_url.isChecked sourceEntities.forEach { when (it.key) { "sourceName" -> source.sourceName = it.value ?: "" @@ -146,7 +147,6 @@ class RssSourceEditActivity : "sourceGroup" -> source.sourceGroup = it.value "ruleArticles" -> source.ruleArticles = it.value "ruleTitle" -> source.ruleTitle = it.value - "ruleAuthor" -> source.ruleAuthor = it.value "rulePubDate" -> source.rulePubDate = it.value "ruleCategories" -> source.ruleCategories = it.value "ruleDescription" -> source.ruleDescription = it.value diff --git a/app/src/main/res/layout/activity_rss_source_edit.xml b/app/src/main/res/layout/activity_rss_source_edit.xml index c7ce22473..2f78c1006 100644 --- a/app/src/main/res/layout/activity_rss_source_edit.xml +++ b/app/src/main/res/layout/activity_rss_source_edit.xml @@ -1,6 +1,7 @@ + android:orientation="horizontal" + android:layout_gravity="center_vertical"> + + + + 音频 启用 启用JS + 加载BaseUrl 全部书源 输入不能为空 清空发现缓存