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. 21
      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")
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 image: String? = null,
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 description: String? = null,
var content: String? = null,
var image: String? = null,
var read: Boolean = false
var image: String? = null
)

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

@ -11,8 +11,9 @@ import io.legado.app.model.Rss
import io.legado.app.model.analyzeRule.AnalyzeUrl
class ReadRssViewModel(application: Application) : BaseViewModel(application) {
var callBack: CallBack? = null
var rssSource: RssSource? = null
val rssArticleLiveData = MutableLiveData<RssArticle>()
var rssArticle: RssArticle? = null
val contentLiveData = MutableLiveData<String>()
val urlLiveData = MutableLiveData<AnalyzeUrl>()
var star = false
@ -24,8 +25,8 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
if (origin != null && link != null) {
rssSource = App.db.rssSourceDao().getByKey(origin)
star = App.db.rssStarDao().get(origin, link) != null
App.db.rssArticleDao().get(origin, link)?.let { rssArticle ->
rssArticleLiveData.postValue(rssArticle)
rssArticle = App.db.rssArticleDao().get(origin, link)
rssArticle?.let { rssArticle ->
if (!rssArticle.description.isNullOrBlank()) {
contentLiveData.postValue(rssArticle.description)
} 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() {
execute {
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