pull/37/head
kunfei 5 years ago
parent 14a14a60fe
commit c441b86216
  1. 2
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 1
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  3. 2
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt
  4. 6
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt
  5. 14
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  6. 12
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt

@ -58,5 +58,5 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun sourceCookieDao(): SourceCookieDao abstract fun sourceCookieDao(): SourceCookieDao
abstract fun rssSourceDao(): RssSourceDao abstract fun rssSourceDao(): RssSourceDao
abstract fun bookmarkDao(): BookmarkDao abstract fun bookmarkDao(): BookmarkDao
abstract fun rssArtivleDao(): RssArticleDao abstract fun rssArticleDao(): RssArticleDao
} }

@ -27,5 +27,6 @@ data class RssSource(
var ruleImage: String? = null, var ruleImage: String? = null,
var ruleLink: String? = null, var ruleLink: String? = null,
var ruleContent: String? = null, var ruleContent: String? = null,
var enableJs: Boolean = false,
var customOrder: Int = 0 var customOrder: Int = 0
) : Parcelable ) : Parcelable

@ -75,7 +75,7 @@ class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activi
private fun initData(origin: String) { private fun initData(origin: String) {
rssArticlesData?.removeObservers(this) rssArticlesData?.removeObservers(this)
rssArticlesData = App.db.rssArtivleDao().liveByOrigin(origin) rssArticlesData = App.db.rssArticleDao().liveByOrigin(origin)
rssArticlesData?.observe(this, Observer { rssArticlesData?.observe(this, Observer {
adapter?.setItems(it) adapter?.setItems(it)
}) })

@ -25,7 +25,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
Rss.getArticles(rssSource, this) Rss.getArticles(rssSource, this)
.onSuccess(IO) { .onSuccess(IO) {
it?.let { it?.let {
App.db.rssArtivleDao().insert(*it.toTypedArray()) App.db.rssArticleDao().insert(*it.toTypedArray())
} }
}.onError { }.onError {
toast(it.localizedMessage) toast(it.localizedMessage)
@ -38,13 +38,13 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
fun read(rssArticle: RssArticle) { fun read(rssArticle: RssArticle) {
execute { execute {
rssArticle.read = true rssArticle.read = true
App.db.rssArtivleDao().update(rssArticle) App.db.rssArticleDao().update(rssArticle)
} }
} }
fun clear(url: String, onFinally: () -> Unit) { fun clear(url: String, onFinally: () -> Unit) {
execute { execute {
App.db.rssArtivleDao().delete(url) App.db.rssArticleDao().delete(url)
loadContent(url, onFinally) loadContent(url, onFinally)
} }
} }

@ -1,5 +1,6 @@
package io.legado.app.ui.rss.read package io.legado.app.ui.rss.read
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.webkit.WebViewClient import android.webkit.WebViewClient
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
@ -16,17 +17,18 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
title = intent.getStringExtra("title") title = intent.getStringExtra("title")
initWebView() webView.webViewClient = WebViewClient()
initLiveData() initLiveData()
viewModel.initData(intent) viewModel.initData(intent)
} }
private fun initWebView() { @SuppressLint("SetJavaScriptEnabled")
webView.settings.javaScriptEnabled = true
webView.webViewClient = WebViewClient()
}
private fun initLiveData() { private fun initLiveData() {
viewModel.rssSourceLiveData.observe(this, Observer {
if (it.enableJs) {
webView.settings.javaScriptEnabled = true
}
})
viewModel.contentLiveData.observe(this, Observer { content -> viewModel.contentLiveData.observe(this, Observer { content ->
viewModel.rssArticle?.let { viewModel.rssArticle?.let {
val url = NetworkUtils.getAbsoluteURL(it.origin, it.link ?: "") val url = NetworkUtils.getAbsoluteURL(it.origin, it.link ?: "")

@ -6,12 +6,14 @@ import androidx.lifecycle.MutableLiveData
import io.legado.app.App import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
class ReadRssViewModel(application: Application) : BaseViewModel(application) { class ReadRssViewModel(application: Application) : BaseViewModel(application) {
var rssArticle: RssArticle? = null var rssArticle: RssArticle? = null
val rssSourceLiveData = MutableLiveData<RssSource>()
val contentLiveData = MutableLiveData<String>() val contentLiveData = MutableLiveData<String>()
val urlLiveData = MutableLiveData<String>() val urlLiveData = MutableLiveData<String>()
@ -19,14 +21,18 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
val origin = intent.getStringExtra("origin") val origin = intent.getStringExtra("origin")
val title = intent.getStringExtra("title") val title = intent.getStringExtra("title")
val rssSource = App.db.rssSourceDao().getByKey(origin)
rssSource?.let {
rssSourceLiveData.postValue(it)
}
if (origin != null && title != null) { if (origin != null && title != null) {
rssArticle = App.db.rssArtivleDao().get(origin, title) rssArticle = App.db.rssArticleDao().get(origin, title)
rssArticle?.let { rssArticle -> rssArticle?.let { rssArticle ->
if (!rssArticle.description.isNullOrBlank()) { if (!rssArticle.description.isNullOrBlank()) {
contentLiveData.postValue(rssArticle.description) contentLiveData.postValue(rssArticle.description)
} else { } else {
App.db.rssSourceDao().getByKey(rssArticle.origin)?.let { source -> rssSource?.let {
val ruleContent = source.ruleContent val ruleContent = rssSource.ruleContent
if (!ruleContent.isNullOrBlank()) { if (!ruleContent.isNullOrBlank()) {
loadContent(rssArticle, ruleContent) loadContent(rssArticle, ruleContent)
} else { } else {

Loading…
Cancel
Save