Updated rule

pull/32/head
atbest 6 years ago
parent f898a8ed35
commit 4ab20cedb3
  1. 12
      app/src/main/java/io/legado/app/constant/AppUtils.kt
  2. 74
      app/src/main/java/io/legado/app/data/entities/Source.kt

@ -0,0 +1,12 @@
package io.legado.app.constant
import com.google.gson.Gson
import com.google.gson.GsonBuilder
object AppUtils {
val GSON_CONVERTER: Gson = GsonBuilder()
.disableHtmlEscaping()
.setPrettyPrinting()
.setDateFormat("yyyy-MM-dd HH:mm:ssZ")
.create()
}

@ -1,16 +1,19 @@
package io.legado.app.data.entities package io.legado.app.data.entities
import android.os.Parcelable import android.os.Parcelable
import androidx.room.ColumnInfo import androidx.room.*
import androidx.room.Entity import io.legado.app.constant.AppUtils.GSON_CONVERTER
import androidx.room.Index import io.legado.app.data.entities.rule.*
import androidx.room.PrimaryKey import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
@Parcelize @Parcelize
@Entity(tableName = "sources", @Entity(
indices = [(Index(value = ["sourceId"]))]) tableName = "sources",
data class Source(@PrimaryKey(autoGenerate = true) indices = [(Index(value = ["sourceId"])), (Index(value = ["origin"], unique = false))]
)
data class Source (
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "sourceId") @ColumnInfo(name = "sourceId")
var id: Int = 0, // 编号 var id: Int = 0, // 编号
var name: String = "", // 名称 var name: String = "", // 名称
@ -28,4 +31,59 @@ data class Source(@PrimaryKey(autoGenerate = true)
var bookInfoRule: String? = null, // 书籍信息页规则 var bookInfoRule: String? = null, // 书籍信息页规则
var chapterRule: String? = null, // 目录页规则 var chapterRule: String? = null, // 目录页规则
var contentRule: String? = null // 正文页规则 var contentRule: String? = null // 正文页规则
) : Parcelable ) : Parcelable {
@Transient
@IgnoredOnParcel
var parsedExploreRule: ExploreRule? = null
@Transient
@IgnoredOnParcel
var parsedSearchRule: SearchRule? = null
@Transient
@IgnoredOnParcel
var parsedBookInfoRule: BookInfoRule? = null
@Transient
@IgnoredOnParcel
var parsedChapterRule: ChapterRule? = null
@Transient
@IgnoredOnParcel
var parsedContentRule: ContentRule? = null
fun initAllRules() {
initSearchRule()
initExploreRule()
initBookInfoRule()
initChapterRule()
initContentRule()
}
fun initSearchRule() {
if (searchRule != null) {
parsedSearchRule = GSON_CONVERTER.fromJson(searchRule, SearchRule::class.java)
}
}
fun initExploreRule() {
if (exploreRule != null) {
parsedExploreRule = GSON_CONVERTER.fromJson(exploreRule, ExploreRule::class.java)
}
}
fun initBookInfoRule() {
if (bookInfoRule != null) {
parsedBookInfoRule = GSON_CONVERTER.fromJson(bookInfoRule, BookInfoRule::class.java)
}
}
fun initChapterRule() {
if (chapterRule != null) {
parsedChapterRule = GSON_CONVERTER.fromJson(chapterRule, ChapterRule::class.java)
}
}
fun initContentRule() {
if (contentRule != null) {
parsedContentRule = GSON_CONVERTER.fromJson(contentRule, ContentRule::class.java)
}
}
}
Loading…
Cancel
Save