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. 108
      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,31 +1,89 @@
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))]
@ColumnInfo(name = "sourceId") )
var id: Int = 0, // 编号 data class Source (
var name: String = "", // 名称 @PrimaryKey(autoGenerate = true)
var origin: String = "", // 地址,包括 http/https @ColumnInfo(name = "sourceId")
var type: Int = 0, // 类型,0 文本,1 音频 var id: Int = 0, // 编号
var group: String? = null, // 分组 var name: String = "", // 名称
var header: String? = null, // header var origin: String = "", // 地址,包括 http/https
var loginUrl: String? = null, // 登录地址 var type: Int = 0, // 类型,0 文本,1 音频
var isEnabled: Boolean = true, // 是否启用 var group: String? = null, // 分组
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序 var header: String? = null, // header
var customOrder: Int = 0, // 手动排序编号 var loginUrl: String? = null, // 登录地址
var weight: Int = 0, // 智能排序的权重 var isEnabled: Boolean = true, // 是否启用
var exploreRule: String? = null, // 发现规则 var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
var searchRule: String? = null, // 搜索规则 var customOrder: Int = 0, // 手动排序编号
var bookInfoRule: String? = null, // 书籍信息页规则 var weight: Int = 0, // 智能排序的权重
var chapterRule: String? = null, // 目录页规则 var exploreRule: String? = null, // 发现规则
var contentRule: String? = null // 正文页规则 var searchRule: String? = null, // 搜索规则
) : Parcelable var bookInfoRule: String? = null, // 书籍信息页规则
var chapterRule: String? = null, // 目录页规则
var contentRule: String? = null // 正文页规则
) : 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