Updated rule

pull/32/head
atbest 6 years ago
parent 4ab20cedb3
commit 225192c3f4
  1. 5
      app/src/main/java/io/legado/app/constant/AppConst.kt
  2. 2
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  3. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  4. 11
      app/src/main/java/io/legado/app/data/entities/Book.kt
  5. 27
      app/src/main/java/io/legado/app/data/entities/rule/Rule.kt

@ -1,5 +1,8 @@
package io.legado.app.constant
import io.legado.app.App
import io.legado.app.R
object AppConst {
const val channelIdDownload = "channel_download"
const val channelIdReadAloud = "channel_read_aloud"
@ -8,4 +11,6 @@ object AppConst {
const val APP_TAG = "Legado"
const val RC_IMPORT_YUEDU_DATA = 100
val NOT_AVAILABLE = App.INSTANCE.getString(R.string.not_available)
}

@ -21,8 +21,6 @@ abstract class AppDatabase : RoomDatabase() {
companion object {
private const val DATABASE_NAME = "legado.db"
private val MIGRATION_1_2: Migration = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.run {

@ -16,4 +16,7 @@ interface BookDao {
@Query("SELECT descUrl FROM books WHERE `group` = :group")
fun observeUrlsByGroup(group: Int): LiveData<List<String>>
@Query("SELECT * FROM books WHERE `name` in (:names)")
fun findByName(vararg names: String): List<Book>
}

@ -2,6 +2,7 @@ package io.legado.app.data.entities
import android.os.Parcelable
import androidx.room.*
import io.legado.app.constant.AppConst.NOT_AVAILABLE
import io.legado.app.utils.strim
import kotlinx.android.parcel.Parcelize
@ -11,7 +12,7 @@ data class Book(@PrimaryKey
var descUrl: String = "", // 详情页Url(本地书源存储完整文件路径)
var tocUrl: String = "", // 目录页Url (toc=table of Contents)
var sourceId: Int = -1, // 书源规则id(默认-1,表示本地书籍)
var name: String = "", // 书籍名称(书源获取)
var name: String? = null, // 书籍名称(书源获取)
var customName: String? = null, // 书籍名称(用户修改)
var author: String? = null, // 作者名称(书源获取)
var customAuthor: String? = null, // 作者名称(用户修改)
@ -39,12 +40,12 @@ data class Book(@PrimaryKey
fun getUnreadChapterNum() = Math.max(totalChapterNum - durChapterIndex - 1, 0)
fun getDisplayName() = customName.strim() ?: name
fun getDisplayName() = customName ?: name ?: NOT_AVAILABLE
fun getDisplayAuthor() = customAuthor.strim() ?: author
fun getDisplayAuthor() = customAuthor ?: author ?: NOT_AVAILABLE
fun getDisplayCover() = customCoverUrl.strim() ?: coverUrl
fun getDisplayCover() = customCoverUrl ?: coverUrl
fun getDisplayDescription() = customDescription.strim() ?: description
fun getDisplayDescription() = customDescription ?: description
}

@ -18,11 +18,26 @@ data class Rule (
input.startsWith("$.") -> parseJSON(input)
input.startsWith("//") -> parseXPATH(input)
input.startsWith("RE:") -> parseREGEX(input)
input.contains("{{") && input.contains("}}") -> parseJS(input)
input.contains("{") && input.contains("}") -> parseCONST(input)
isJsRule(input) -> parseJS(input)
isConstRule(input) -> parseCONST(input)
else -> parseCSS(input)
}
private fun isJsRule(input: String): Boolean {
val open = input.indexOf("{{")
if (open < 0) return false
val close = input.indexOf("}}", open)
return close > 0
}
private fun isConstRule(input: String): Boolean {
val open = input.indexOf("{")
if (open < 0) return false
val close = input.indexOf("}", open)
return close > 0
}
private fun parseCSS(rawRule: String): List<BaseRule> {
val rules = mutableListOf<BaseRule>()
for (line in rawRule.splitNotBlank("\n")) {
@ -60,10 +75,6 @@ data class Rule (
return rules
}
private fun parseREGEX(rawRule: String): List<BaseRule> {
TODO()
}
private fun parseCONST(rawRule: String): List<BaseRule> {
val rules = mutableListOf<BaseRule>()
val subRule = mutableListOf<String>()
@ -85,6 +96,10 @@ data class Rule (
TODO()
}
private fun parseREGEX(rawRule: String): List<BaseRule> {
TODO()
}
}
}

Loading…
Cancel
Save