From e5c430dea965691f6cdc4fb510b74db24280e0bb Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 14 Jun 2019 22:42:41 +0800 Subject: [PATCH] up --- .../io/legado/app/data/dao/SearchBookDao.kt | 18 +++++++ .../java/io/legado/app/data/entities/Book.kt | 6 +++ .../io/legado/app/data/entities/SearchBook.kt | 52 ++++++++++++++++++- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt diff --git a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt new file mode 100644 index 000000000..ff36e8afb --- /dev/null +++ b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt @@ -0,0 +1,18 @@ +package io.legado.app.data.dao + +import androidx.paging.DataSource +import androidx.room.Dao +import androidx.room.Query +import io.legado.app.data.entities.SearchBook + +@Dao +interface SearchBookDao { + + @Query("SELECT * FROM searchBooks") + fun observeAll(): DataSource.Factory + + @Query("SELECT * FROM searchBooks where time >= :time") + fun observeNew(time: Long): DataSource.Factory + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index db22bea23..129135a9b 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -49,6 +49,10 @@ data class Book( @IgnoredOnParcel @Ignore override var variableMap: HashMap? = null + get() = run { + initVariableMap() + return field + } fun getUnreadChapterNum() = Math.max(totalChapterNum - durChapterIndex - 1, 0) @@ -72,5 +76,7 @@ data class Book( override fun putVariable(key: String, value: String) { initVariableMap() + variableMap?.put(key, value) + variable = Gson().toJson(variableMap) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt index 8994f14bd..97a504b3c 100644 --- a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt @@ -1,3 +1,53 @@ package io.legado.app.data.entities -class SearchBook \ No newline at end of file +import android.os.Parcelable +import android.text.TextUtils +import androidx.room.Entity +import androidx.room.Ignore +import androidx.room.Index +import androidx.room.PrimaryKey +import com.google.gson.Gson +import io.legado.app.utils.fromJson +import kotlinx.android.parcel.IgnoredOnParcel +import kotlinx.android.parcel.Parcelize + +@Parcelize +@Entity(tableName = "searchBooks", indices = [(Index(value = ["descUrl"], unique = true))]) +data class SearchBook( + @PrimaryKey + var descUrl: String = "", + var origin: String = "", // 书源规则id(默认-1,表示本地书籍) + var name: String? = null, + var author: String? = null, + var tag: String? = null, + var coverUrl: String? = null, + var description: String? = null, + var latestChapterTitle: String? = null, + var time: Long = 0L, + var variable: String? = null +) : Parcelable, BaseBook { + + @IgnoredOnParcel + @Ignore + override var variableMap: HashMap? = null + get() = run { + initVariableMap() + return field + } + + private fun initVariableMap() { + if (variableMap == null) { + variableMap = if (TextUtils.isEmpty(variable)) { + HashMap() + } else { + Gson().fromJson>(variable!!) + } + } + } + + override fun putVariable(key: String, value: String) { + initVariableMap() + variableMap?.put(key, value) + variable = Gson().toJson(variableMap) + } +} \ No newline at end of file