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. 12
      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 rssSourceDao(): RssSourceDao
abstract fun bookmarkDao(): BookmarkDao
abstract fun rssArtivleDao(): RssArticleDao
abstract fun rssArticleDao(): RssArticleDao
}

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

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

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

@ -1,5 +1,6 @@
package io.legado.app.ui.rss.read
import android.annotation.SuppressLint
import android.os.Bundle
import android.webkit.WebViewClient
import androidx.lifecycle.Observer
@ -16,17 +17,18 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
override fun onActivityCreated(savedInstanceState: Bundle?) {
title = intent.getStringExtra("title")
initWebView()
webView.webViewClient = WebViewClient()
initLiveData()
viewModel.initData(intent)
}
private fun initWebView() {
@SuppressLint("SetJavaScriptEnabled")
private fun initLiveData() {
viewModel.rssSourceLiveData.observe(this, Observer {
if (it.enableJs) {
webView.settings.javaScriptEnabled = true
webView.webViewClient = WebViewClient()
}
private fun initLiveData() {
})
viewModel.contentLiveData.observe(this, Observer { content ->
viewModel.rssArticle?.let {
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.base.BaseViewModel
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.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
class ReadRssViewModel(application: Application) : BaseViewModel(application) {
var rssArticle: RssArticle? = null
val rssSourceLiveData = MutableLiveData<RssSource>()
val contentLiveData = MutableLiveData<String>()
val urlLiveData = MutableLiveData<String>()
@ -19,14 +21,18 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
execute {
val origin = intent.getStringExtra("origin")
val title = intent.getStringExtra("title")
val rssSource = App.db.rssSourceDao().getByKey(origin)
rssSource?.let {
rssSourceLiveData.postValue(it)
}
if (origin != null && title != null) {
rssArticle = App.db.rssArtivleDao().get(origin, title)
rssArticle = App.db.rssArticleDao().get(origin, title)
rssArticle?.let { rssArticle ->
if (!rssArticle.description.isNullOrBlank()) {
contentLiveData.postValue(rssArticle.description)
} else {
App.db.rssSourceDao().getByKey(rssArticle.origin)?.let { source ->
val ruleContent = source.ruleContent
rssSource?.let {
val ruleContent = rssSource.ruleContent
if (!ruleContent.isNullOrBlank()) {
loadContent(rssArticle, ruleContent)
} else {

Loading…
Cancel
Save