diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index 89a1d204f..863f9e27a 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.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) + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index f5db6c908..4e3be84f6 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 6e71ae680..aae85f47f 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -16,4 +16,7 @@ interface BookDao { @Query("SELECT descUrl FROM books WHERE `group` = :group") fun observeUrlsByGroup(group: Int): LiveData> + @Query("SELECT * FROM books WHERE `name` in (:names)") + fun findByName(vararg names: String): List + } \ 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 fc601f9fe..1efd170c3 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 @@ -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 } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/rule/Rule.kt b/app/src/main/java/io/legado/app/data/entities/rule/Rule.kt index ad2d16509..7b3810802 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/Rule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/Rule.kt @@ -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 { val rules = mutableListOf() for (line in rawRule.splitNotBlank("\n")) { @@ -60,10 +75,6 @@ data class Rule ( return rules } - private fun parseREGEX(rawRule: String): List { - TODO() - } - private fun parseCONST(rawRule: String): List { val rules = mutableListOf() val subRule = mutableListOf() @@ -85,6 +96,10 @@ data class Rule ( TODO() } + private fun parseREGEX(rawRule: String): List { + TODO() + } + } }