diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 3b17435d5..630925c89 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.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 } \ No newline at end of file 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 f4fa0b838..79e74a496 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 @@ -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 \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index f2291a141..46825ee16 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -75,7 +75,7 @@ class RssArticlesActivity : VMBaseActivity(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) }) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index ccc939105..745216ba4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -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) } } 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 117d601df..f5f8a2d98 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 @@ -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(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() { - webView.settings.javaScriptEnabled = true - webView.webViewClient = WebViewClient() - } - + @SuppressLint("SetJavaScriptEnabled") private fun initLiveData() { + viewModel.rssSourceLiveData.observe(this, Observer { + if (it.enableJs) { + webView.settings.javaScriptEnabled = true + } + }) viewModel.contentLiveData.observe(this, Observer { content -> viewModel.rssArticle?.let { val url = NetworkUtils.getAbsoluteURL(it.origin, it.link ?: "") diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 89a1e0825..3e8737a35 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -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() val contentLiveData = MutableLiveData() val urlLiveData = MutableLiveData() @@ -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 {