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 1b3de026c..d355c6ab6 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -13,7 +13,7 @@ import io.legado.app.help.storage.Restore @Database( entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::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, exportSchema = true ) @@ -45,5 +45,6 @@ abstract class AppDatabase : RoomDatabase() { abstract fun rssSourceDao(): RssSourceDao abstract fun bookmarkDao(): BookmarkDao abstract fun rssArticleDao(): RssArticleDao + abstract fun rssStarDao(): RssStarDao abstract fun cookieDao(): CookieDao } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt b/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt new file mode 100644 index 000000000..82640a049 --- /dev/null +++ b/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt @@ -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> + + @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) +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt index 484129121..76637dc13 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt @@ -16,6 +16,5 @@ data class RssArticle( var description: String? = null, var content: String? = null, var image: String? = null, - var read: Boolean = false, - var star: Boolean = false + var read: Boolean = false ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/RssStar.kt b/app/src/main/java/io/legado/app/data/entities/RssStar.kt new file mode 100644 index 000000000..39a1f4a95 --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/RssStar.kt @@ -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 +) \ No newline at end of file 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 5bee434a2..2012481b4 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 @@ -38,10 +38,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_rss_star -> viewModel.rssArticleLiveData.value?.let { - it.star = !it.star - viewModel.upRssArticle(it) { upStarMenu() } - } + R.id.menu_rss_star -> viewModel.star() } return super.onCompatOptionsItemSelected(item) } @@ -92,7 +89,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } private fun upStarMenu() { - if (viewModel.rssArticleLiveData.value?.star == true) { + if (viewModel.star) { starMenuItem?.setIcon(R.drawable.ic_star) starMenuItem?.setTitle(R.string.y_store_up) } else { 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 b0312bb9d..16e2f6c7a 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 @@ -15,13 +15,15 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) { val rssArticleLiveData = MutableLiveData() val contentLiveData = MutableLiveData() val urlLiveData = MutableLiveData() + var star = false fun initData(intent: Intent) { execute { val origin = intent.getStringExtra("origin") val link = intent.getStringExtra("link") - rssSource = App.db.rssSourceDao().getByKey(origin) 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) if (!rssArticle.description.isNullOrBlank()) { @@ -58,11 +60,11 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) { } } - fun upRssArticle(rssArticle: RssArticle, success: () -> Unit) { + fun star() { execute { - App.db.rssArticleDao().update(rssArticle) - }.onSuccess { - success() + if (star) { + + } } } } \ No newline at end of file