pull/49/head
kunfei 5 years ago
parent 973579c9e5
commit 10875e11b5
  1. 3
      app/src/main/java/io/legado/app/data/dao/RssStarDao.kt
  2. 16
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  3. 3
      app/src/main/java/io/legado/app/data/entities/RssStar.kt
  4. 9
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  5. 23
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt

@ -21,4 +21,7 @@ interface RssStarDao {
@Query("delete from rssStars where origin = :origin") @Query("delete from rssStars where origin = :origin")
fun delete(origin: String) fun delete(origin: String)
@Query("delete from rssStars where origin = :origin and link = :link")
fun delete(origin: String, link: String)
} }

@ -17,4 +17,18 @@ data class RssArticle(
var content: String? = null, var content: String? = null,
var image: String? = null, var image: String? = null,
var read: Boolean = false var read: Boolean = false
) ) {
fun toStar(): RssStar {
return RssStar(
origin = origin,
title = title,
starTime = System.currentTimeMillis(),
link = link,
pubDate = pubDate,
description = description,
content = content,
image = image
)
}
}

@ -15,6 +15,5 @@ data class RssStar(
var pubDate: String? = null, var pubDate: String? = null,
var description: String? = null, var description: String? = null,
var content: String? = null, var content: String? = null,
var image: String? = null, var image: String? = null
var read: Boolean = false
) )

@ -15,7 +15,8 @@ import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_rss_read.* import kotlinx.android.synthetic.main.activity_rss_read.*
class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_read) { class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_read),
ReadRssViewModel.CallBack {
override val viewModel: ReadRssViewModel override val viewModel: ReadRssViewModel
get() = getViewModel(ReadRssViewModel::class.java) get() = getViewModel(ReadRssViewModel::class.java)
@ -23,6 +24,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
private var starMenuItem: MenuItem? = null private var starMenuItem: MenuItem? = null
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.callBack = this
title = intent.getStringExtra("title") title = intent.getStringExtra("title")
initWebView() initWebView()
initLiveData() initLiveData()
@ -53,9 +55,8 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
private fun initLiveData() { private fun initLiveData() {
viewModel.rssArticleLiveData.observe(this, Observer { upStarMenu() })
viewModel.contentLiveData.observe(this, Observer { content -> viewModel.contentLiveData.observe(this, Observer { content ->
viewModel.rssArticleLiveData.value?.let { viewModel.rssArticle?.let {
upJavaScriptEnable() upJavaScriptEnable()
val url = NetworkUtils.getAbsoluteURL(it.origin, it.link) val url = NetworkUtils.getAbsoluteURL(it.origin, it.link)
if (viewModel.rssSource?.loadWithBaseUrl == true) { if (viewModel.rssSource?.loadWithBaseUrl == true) {
@ -88,7 +89,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
} }
} }
private fun upStarMenu() { override fun upStarMenu() {
if (viewModel.star) { if (viewModel.star) {
starMenuItem?.setIcon(R.drawable.ic_star) starMenuItem?.setIcon(R.drawable.ic_star)
starMenuItem?.setTitle(R.string.y_store_up) starMenuItem?.setTitle(R.string.y_store_up)

@ -11,8 +11,9 @@ import io.legado.app.model.Rss
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
class ReadRssViewModel(application: Application) : BaseViewModel(application) { class ReadRssViewModel(application: Application) : BaseViewModel(application) {
var callBack: CallBack? = null
var rssSource: RssSource? = null var rssSource: RssSource? = null
val rssArticleLiveData = MutableLiveData<RssArticle>() var rssArticle: RssArticle? = null
val contentLiveData = MutableLiveData<String>() val contentLiveData = MutableLiveData<String>()
val urlLiveData = MutableLiveData<AnalyzeUrl>() val urlLiveData = MutableLiveData<AnalyzeUrl>()
var star = false var star = false
@ -24,8 +25,8 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
if (origin != null && link != null) { if (origin != null && link != null) {
rssSource = App.db.rssSourceDao().getByKey(origin) rssSource = App.db.rssSourceDao().getByKey(origin)
star = App.db.rssStarDao().get(origin, link) != null star = App.db.rssStarDao().get(origin, link) != null
App.db.rssArticleDao().get(origin, link)?.let { rssArticle -> rssArticle = App.db.rssArticleDao().get(origin, link)
rssArticleLiveData.postValue(rssArticle) rssArticle?.let { rssArticle ->
if (!rssArticle.description.isNullOrBlank()) { if (!rssArticle.description.isNullOrBlank()) {
contentLiveData.postValue(rssArticle.description) contentLiveData.postValue(rssArticle.description)
} else { } else {
@ -40,6 +41,8 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
} }
} }
} }
}.onFinally {
callBack?.upStarMenu()
} }
} }
@ -62,9 +65,19 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
fun star() { fun star() {
execute { execute {
if (star) { rssArticle?.let {
if (star) {
App.db.rssStarDao().delete(it.origin, it.link)
} else {
App.db.rssStarDao().insert(it.toStar())
}
} }
}.onSuccess {
callBack?.upStarMenu()
} }
} }
interface CallBack {
fun upStarMenu()
}
} }
Loading…
Cancel
Save