pull/37/head
kunfei 5 years ago
parent 7bc04293ce
commit 7bd59483d1
  1. 20
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  2. 12
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt
  3. 2
      app/src/main/res/values/strings.xml

@ -18,6 +18,8 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
override val viewModel: ReadRssViewModel
get() = getViewModel(ReadRssViewModel::class.java)
private var starMenuItem: MenuItem? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
title = intent.getStringExtra("title")
initWebView()
@ -27,12 +29,16 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.rss_read, menu)
starMenuItem = menu.findItem(R.id.menu_rss_star)
upStarMenu()
return super.onCompatCreateOptionsMenu(menu)
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_rss_star -> {
R.id.menu_rss_star -> viewModel.rssArticleLiveData.value?.let {
it.star = !it.star
viewModel.upRssArticle(it)
}
}
return super.onCompatOptionsItemSelected(item)
@ -46,13 +52,14 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
@SuppressLint("SetJavaScriptEnabled")
private fun initLiveData() {
viewModel.rssArticleLiveData.observe(this, Observer { upStarMenu() })
viewModel.rssSourceLiveData.observe(this, Observer {
if (it.enableJs) {
webView.settings.javaScriptEnabled = true
}
})
viewModel.contentLiveData.observe(this, Observer { content ->
viewModel.rssArticle?.let {
viewModel.rssArticleLiveData.value?.let {
val url = NetworkUtils.getAbsoluteURL(it.origin, it.link ?: "")
if (viewModel.rssSourceLiveData.value?.loadWithBaseUrl == true) {
webView.loadDataWithBaseURL(
@ -76,4 +83,13 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
})
}
private fun upStarMenu() {
if (viewModel.rssArticleLiveData.value?.star == true) {
starMenuItem?.setIcon(R.drawable.ic_star)
starMenuItem?.setTitle(R.string.y_store_up)
} else {
starMenuItem?.setIcon(R.drawable.ic_star_border)
starMenuItem?.setTitle(R.string.w_store_up)
}
}
}

@ -12,7 +12,7 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
class ReadRssViewModel(application: Application) : BaseViewModel(application) {
var rssArticle: RssArticle? = null
var rssArticleLiveData = MutableLiveData<RssArticle>()
val rssSourceLiveData = MutableLiveData<RssSource>()
val contentLiveData = MutableLiveData<String>()
val urlLiveData = MutableLiveData<String>()
@ -26,8 +26,8 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
rssSourceLiveData.postValue(it)
}
if (origin != null && title != null) {
rssArticle = App.db.rssArticleDao().get(origin, title)
rssArticle?.let { rssArticle ->
App.db.rssArticleDao().get(origin, title)?.let { rssArticle ->
rssArticleLiveData.postValue(rssArticle)
if (!rssArticle.description.isNullOrBlank()) {
contentLiveData.postValue(rssArticle.description)
} else {
@ -66,4 +66,10 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
}
}
}
fun upRssArticle(rssArticle: RssArticle) {
execute {
App.db.rssArticleDao().update(rssArticle)
}
}
}

@ -35,6 +35,8 @@
<string name="replace_purify_search">替换净化-搜索</string>
<string name="bookshelf">书架</string>
<string name="store_up">收藏</string>
<string name="y_store_up">已收藏</string>
<string name="w_store_up">未收藏</string>
<string name="rss">订阅</string>
<string name="all">全部</string>
<string name="recent_reading">最近阅读</string>

Loading…
Cancel
Save