订阅更书籍一样可以保存数据

pull/754/head
gedoor 4 years ago
parent c45db4e16e
commit 765222eb75
  1. 12
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 2
      app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt
  3. 6
      app/src/main/java/io/legado/app/data/entities/BaseBook.kt
  4. 28
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  5. 41
      app/src/main/java/io/legado/app/data/entities/RssStar.kt
  6. 9
      app/src/main/java/io/legado/app/model/analyzeRule/RuleData.kt

@ -19,7 +19,7 @@ import java.util.*
RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class,
RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class, Cache::class,
RuleSub::class],
version = 27,
version = 28,
exportSchema = true
)
abstract class AppDatabase : RoomDatabase() {
@ -53,7 +53,8 @@ abstract class AppDatabase : RoomDatabase() {
migration_10_11, migration_11_12, migration_12_13, migration_13_14,
migration_14_15, migration_15_17, migration_17_18, migration_18_19,
migration_19_20, migration_20_21, migration_21_22, migration_22_23,
migration_23_24, migration_24_25, migration_25_26, migration_26_27
migration_23_24, migration_24_25, migration_25_26, migration_26_27,
migration_27_28
)
.allowMainThreadQueries()
.addCallback(dbCallback)
@ -257,6 +258,13 @@ abstract class AppDatabase : RoomDatabase() {
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_bookmarks_time` ON `bookmarks` (`time`)")
}
}
private val migration_27_28 = object : Migration(27, 28) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE rssArticles ADD variable TEXT")
database.execSQL("ALTER TABLE rssStars ADD variable TEXT")
}
}
}
}

@ -12,7 +12,7 @@ interface RssArticleDao {
fun get(origin: String, link: String): RssArticle?
@Query(
"""select t1.link, t1.sort, t1.origin, t1.`order`, t1.title, t1.content, t1.description, t1.image, t1.pubDate, ifNull(t2.read, 0) as read
"""select t1.link, t1.sort, t1.origin, t1.`order`, t1.title, t1.content, t1.description, t1.image, t1.pubDate, t1.variable, ifNull(t2.read, 0) as read
from rssArticles as t1 left join rssReadRecords as t2
on t1.link = t2.record where origin = :origin and sort = :sort
order by `order` desc"""

@ -1,20 +1,18 @@
package io.legado.app.data.entities
import io.legado.app.model.analyzeRule.RuleData
import io.legado.app.utils.splitNotBlank
interface BaseBook {
interface BaseBook : RuleData {
var name: String
var author: String
var bookUrl: String
val variableMap: HashMap<String, String>
var kind: String?
var wordCount: String?
var infoHtml: String?
var tocHtml: String?
fun putVariable(key: String, value: String) {}
fun getKindList(): List<String> {
val kindList = arrayListOf<String>()
wordCount?.let {

@ -1,6 +1,11 @@
package io.legado.app.data.entities
import androidx.room.Entity
import androidx.room.Ignore
import io.legado.app.model.analyzeRule.RuleData
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.parcelize.IgnoredOnParcel
@Entity(
@ -17,16 +22,29 @@ data class RssArticle(
var description: String? = null,
var content: String? = null,
var image: String? = null,
var read: Boolean = false
) {
var read: Boolean = false,
var variable: String? = null
) : RuleData {
override fun hashCode() = link.hashCode()
override fun equals(other: Any?): Boolean {
other ?: return false
return if (other is RssArticle) origin == other.origin && link == other.link else false
}
@delegate:Transient
@delegate:Ignore
@IgnoredOnParcel
override val variableMap by lazy {
GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
}
override fun putVariable(key: String, value: String) {
variableMap[key] = value
variable = GSON.toJson(variableMap)
}
fun toStar() = RssStar(
origin = origin,
sort = sort,

@ -1,6 +1,11 @@
package io.legado.app.data.entities
import androidx.room.Entity
import androidx.room.Ignore
import io.legado.app.model.analyzeRule.RuleData
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.parcelize.IgnoredOnParcel
@Entity(
@ -16,16 +21,30 @@ data class RssStar(
var pubDate: String? = null,
var description: String? = null,
var content: String? = null,
var image: String? = null
) {
var image: String? = null,
var variable: String? = null
) : RuleData {
@delegate:Transient
@delegate:Ignore
@IgnoredOnParcel
override val variableMap by lazy {
GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
}
override fun putVariable(key: String, value: String) {
variableMap[key] = value
variable = GSON.toJson(variableMap)
}
fun toRssArticle() = RssArticle(
origin = origin,
sort = sort,
title = title,
link = link,
pubDate = pubDate,
description = description,
content = content,
image = image
)
origin = origin,
sort = sort,
title = title,
link = link,
pubDate = pubDate,
description = description,
content = content,
image = image
)
}

@ -0,0 +1,9 @@
package io.legado.app.model.analyzeRule
interface RuleData {
val variableMap: HashMap<String, String>
fun putVariable(key: String, value: String)
}
Loading…
Cancel
Save