pull/49/head
kunfei 5 years ago
parent 94ec767e31
commit 973579c9e5
  1. 3
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 24
      app/src/main/java/io/legado/app/data/dao/RssStarDao.kt
  3. 3
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  4. 20
      app/src/main/java/io/legado/app/data/entities/RssStar.kt
  5. 7
      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

@ -13,7 +13,7 @@ import io.legado.app.help.storage.Restore
@Database( @Database(
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
RssSource::class, Bookmark::class, RssArticle::class], RssSource::class, Bookmark::class, RssArticle::class, RssStar::class],
version = 4, version = 4,
exportSchema = true exportSchema = true
) )
@ -45,5 +45,6 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun rssSourceDao(): RssSourceDao abstract fun rssSourceDao(): RssSourceDao
abstract fun bookmarkDao(): BookmarkDao abstract fun bookmarkDao(): BookmarkDao
abstract fun rssArticleDao(): RssArticleDao abstract fun rssArticleDao(): RssArticleDao
abstract fun rssStarDao(): RssStarDao
abstract fun cookieDao(): CookieDao abstract fun cookieDao(): CookieDao
} }

@ -0,0 +1,24 @@
package io.legado.app.data.dao
import androidx.lifecycle.LiveData
import androidx.room.*
import io.legado.app.data.entities.RssStar
@Dao
interface RssStarDao {
@Query("select * from rssStars where origin = :origin and link = :link")
fun get(origin: String, link: String): RssStar?
@Query("select * from rssStars order by starTime desc")
fun liveAll(): LiveData<List<RssStar>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg rssStar: RssStar)
@Update
fun update(vararg rssStar: RssStar)
@Query("delete from rssStars where origin = :origin")
fun delete(origin: String)
}

@ -16,6 +16,5 @@ data class RssArticle(
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, var read: Boolean = false
var star: Boolean = false
) )

@ -0,0 +1,20 @@
package io.legado.app.data.entities
import androidx.room.Entity
@Entity(
tableName = "rssStars",
primaryKeys = ["origin", "link"]
)
data class RssStar(
var origin: String = "",
var title: String = "",
var starTime: Long = 0,
var link: String = "",
var pubDate: String? = null,
var description: String? = null,
var content: String? = null,
var image: String? = null,
var read: Boolean = false
)

@ -38,10 +38,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_rss_star -> viewModel.rssArticleLiveData.value?.let { R.id.menu_rss_star -> viewModel.star()
it.star = !it.star
viewModel.upRssArticle(it) { upStarMenu() }
}
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }
@ -92,7 +89,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
} }
private fun upStarMenu() { private fun upStarMenu() {
if (viewModel.rssArticleLiveData.value?.star == true) { 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)
} else { } else {

@ -15,13 +15,15 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
val rssArticleLiveData = MutableLiveData<RssArticle>() val rssArticleLiveData = MutableLiveData<RssArticle>()
val contentLiveData = MutableLiveData<String>() val contentLiveData = MutableLiveData<String>()
val urlLiveData = MutableLiveData<AnalyzeUrl>() val urlLiveData = MutableLiveData<AnalyzeUrl>()
var star = false
fun initData(intent: Intent) { fun initData(intent: Intent) {
execute { execute {
val origin = intent.getStringExtra("origin") val origin = intent.getStringExtra("origin")
val link = intent.getStringExtra("link") val link = intent.getStringExtra("link")
rssSource = App.db.rssSourceDao().getByKey(origin)
if (origin != null && link != null) { 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 -> App.db.rssArticleDao().get(origin, link)?.let { rssArticle ->
rssArticleLiveData.postValue(rssArticle) rssArticleLiveData.postValue(rssArticle)
if (!rssArticle.description.isNullOrBlank()) { if (!rssArticle.description.isNullOrBlank()) {
@ -58,11 +60,11 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun upRssArticle(rssArticle: RssArticle, success: () -> Unit) { fun star() {
execute { execute {
App.db.rssArticleDao().update(rssArticle) if (star) {
}.onSuccess {
success() }
} }
} }
} }
Loading…
Cancel
Save