pull/90/head^2
kunfei 5 years ago
parent 29bebf4995
commit 3d1a8eb281
  1. 5
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 10
      app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt
  3. 7
      app/src/main/java/io/legado/app/data/entities/RssReadRecord.kt
  4. 4
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt

@ -16,8 +16,9 @@ import kotlinx.coroutines.launch
@Database(
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
RssSource::class, Bookmark::class, RssArticle::class, RssStar::class, TxtTocRule::class],
version = 7,
RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class,
RssStar::class, TxtTocRule::class],
version = 8,
exportSchema = true
)
abstract class AppDatabase : RoomDatabase() {

@ -3,6 +3,7 @@ package io.legado.app.data.dao
import androidx.lifecycle.LiveData
import androidx.room.*
import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssReadRecord
@Dao
interface RssArticleDao {
@ -10,7 +11,11 @@ interface RssArticleDao {
@Query("select * from rssArticles where origin = :origin and link = :link")
fun get(origin: String, link: String): RssArticle?
@Query("select * from rssArticles where origin = :origin order by `order` desc")
@Query(
"""select t1.link, t1.origin, t1.`order`, t1.title, t1.content, t1.description, t1.image, t1.pubDate, ifNull(t2.read, 0) as read
from rssArticles as t1 left join rssReadRecords as t2
on t1.link = t2.record where origin = :origin order by `order` desc"""
)
fun liveByOrigin(origin: String): LiveData<List<RssArticle>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
@ -24,4 +29,7 @@ interface RssArticleDao {
@Query("delete from rssArticles where origin = :origin")
fun delete(origin: String)
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insertRecord(vararg rssReadRecord: RssReadRecord)
}

@ -0,0 +1,7 @@
package io.legado.app.data.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "rssReadRecords")
data class RssReadRecord(@PrimaryKey val record: String, val read: Boolean = true)

@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssReadRecord
import io.legado.app.data.entities.RssSource
import io.legado.app.model.Rss
import kotlinx.coroutines.Dispatchers.IO
@ -101,8 +102,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
fun read(rssArticle: RssArticle) {
execute {
rssArticle.read = true
App.db.rssArticleDao().update(rssArticle)
App.db.rssArticleDao().insertRecord(RssReadRecord(rssArticle.link))
}
}

Loading…
Cancel
Save