pull/37/head
kunfei 5 years ago
parent a65e2d3f0b
commit 975fac2772
  1. 2
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  2. 10
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  3. 23
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  4. 4
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  5. 19
      app/src/main/res/layout/activity_rss_source_edit.xml
  6. 1
      app/src/main/res/values/strings.xml

@ -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

@ -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<AnalyzeRule.SourceRule>,
ruleAuthor: List<AnalyzeRule.SourceRule>,
rulePubDate: List<AnalyzeRule.SourceRule>,
ruleCategories: List<AnalyzeRule.SourceRule>,
ruleDescription: List<AnalyzeRule.SourceRule>,
ruleImage: List<AnalyzeRule.SourceRule>,
ruleContent: List<AnalyzeRule.SourceRule>,
ruleLink: List<AnalyzeRule.SourceRule>
): 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
}

@ -26,6 +26,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(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<ReadRssViewModel>(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,
"<style>img{max-width:100%}</style>$content",
"text/html",
"utf-8",
url
)
if (viewModel.rssSourceLiveData.value?.loadWithBaseUrl == true) {
webView.loadDataWithBaseURL(
url,
"<style>img{max-width:100%}</style>$content",
"text/html",
"utf-8",
url
)
} else {
webView.loadData(
"<style>img{max-width:100%}</style>$content",
"text/html",
"utf-8"
)
}
}
})
viewModel.urlLiveData.observe(this, Observer {

@ -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

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -18,7 +19,8 @@
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="horizontal"
android:layout_gravity="center_vertical">
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/cb_is_enable"
@ -27,6 +29,14 @@
android:checked="true"
android:text="@string/is_enable" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="WebView:"
tools:ignore="HardcodedText" />
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/cb_enable_js"
android:layout_width="wrap_content"
@ -34,6 +44,13 @@
android:checked="false"
android:text="@string/enable_js" />
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/cb_enable_base_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/load_with_base_url" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView

@ -494,6 +494,7 @@
<string name="audio">音频</string>
<string name="is_enable">启用</string>
<string name="enable_js">启用JS</string>
<string name="load_with_base_url">加载BaseUrl</string>
<string name="all_source">全部书源</string>
<string name="cannot_empty">输入不能为空</string>
<string name="clear_find_cache">清空发现缓存</string>

Loading…
Cancel
Save