pull/32/head
gedoor 6 years ago
parent 96048db37d
commit e5c430dea9
  1. 18
      app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
  2. 6
      app/src/main/java/io/legado/app/data/entities/Book.kt
  3. 52
      app/src/main/java/io/legado/app/data/entities/SearchBook.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<Int, SearchBook>
@Query("SELECT * FROM searchBooks where time >= :time")
fun observeNew(time: Long): DataSource.Factory<Int, SearchBook>
}

@ -49,6 +49,10 @@ data class Book(
@IgnoredOnParcel
@Ignore
override var variableMap: HashMap<String, String>? = 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)
}
}

@ -1,3 +1,53 @@
package io.legado.app.data.entities
class SearchBook
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<String, String>? = null
get() = run {
initVariableMap()
return field
}
private fun initVariableMap() {
if (variableMap == null) {
variableMap = if (TextUtils.isEmpty(variable)) {
HashMap()
} else {
Gson().fromJson<HashMap<String, String>>(variable!!)
}
}
}
override fun putVariable(key: String, value: String) {
initVariableMap()
variableMap?.put(key, value)
variable = Gson().toJson(variableMap)
}
}
Loading…
Cancel
Save