From 6b22ab046eecf1abf6b952ac806cdfebb7687051 Mon Sep 17 00:00:00 2001 From: Seidko Date: Sun, 21 Aug 2022 23:09:26 +0800 Subject: [PATCH] Add: Add ReviewRule and related codes --- .../io.legado.app.data.AppDatabase/52.json | 94 +++++++++++-------- .../io/legado/app/data/dao/BookSourceDao.kt | 3 + .../io/legado/app/data/entities/BookSource.kt | 21 ++++- .../app/data/entities/rule/ReviewRule.kt | 18 ++++ .../res/layout/activity_book_source_edit.xml | 21 ++++- app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 12 files changed, 119 insertions(+), 45 deletions(-) create mode 100644 app/src/main/java/io/legado/app/data/entities/rule/ReviewRule.kt diff --git a/app/schemas/io.legado.app.data.AppDatabase/52.json b/app/schemas/io.legado.app.data.AppDatabase/52.json index 4f3ee4e9a..e9a5947e9 100644 --- a/app/schemas/io.legado.app.data.AppDatabase/52.json +++ b/app/schemas/io.legado.app.data.AppDatabase/52.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 52, - "identityHash": "0221c385ed7393f47afe9579d3106541", + "identityHash": "c55dac79aa9cc3dcdb72e91da4282005", "entities": [ { "tableName": "books", @@ -208,10 +208,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "bookUrl" - ] + ], + "autoGenerate": false }, "indices": [ { @@ -263,17 +263,17 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "groupId" - ] + ], + "autoGenerate": false }, "indices": [], "foreignKeys": [] }, { "tableName": "book_sources", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`bookSourceUrl` TEXT NOT NULL, `bookSourceName` TEXT NOT NULL, `bookSourceGroup` TEXT, `bookSourceType` INTEGER NOT NULL, `bookUrlPattern` TEXT, `customOrder` INTEGER NOT NULL, `enabled` INTEGER NOT NULL, `enabledExplore` INTEGER NOT NULL, `enabledCookieJar` INTEGER DEFAULT 0, `concurrentRate` TEXT, `header` TEXT, `loginUrl` TEXT, `loginUi` TEXT, `loginCheckJs` TEXT, `bookSourceComment` TEXT, `variableComment` TEXT, `lastUpdateTime` INTEGER NOT NULL, `respondTime` INTEGER NOT NULL, `weight` INTEGER NOT NULL, `exploreUrl` TEXT, `ruleExplore` TEXT, `searchUrl` TEXT, `ruleSearch` TEXT, `ruleBookInfo` TEXT, `ruleToc` TEXT, `ruleContent` TEXT, PRIMARY KEY(`bookSourceUrl`))", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`bookSourceUrl` TEXT NOT NULL, `bookSourceName` TEXT NOT NULL, `bookSourceGroup` TEXT, `bookSourceType` INTEGER NOT NULL, `bookUrlPattern` TEXT, `customOrder` INTEGER NOT NULL, `enabled` INTEGER NOT NULL, `enabledExplore` INTEGER NOT NULL, `enabledCookieJar` INTEGER DEFAULT 0, `concurrentRate` TEXT, `header` TEXT, `loginUrl` TEXT, `loginUi` TEXT, `enabledReview` INTEGER, `loginCheckJs` TEXT, `bookSourceComment` TEXT, `variableComment` TEXT, `lastUpdateTime` INTEGER NOT NULL, `respondTime` INTEGER NOT NULL, `weight` INTEGER NOT NULL, `exploreUrl` TEXT, `ruleExplore` TEXT, `searchUrl` TEXT, `ruleSearch` TEXT, `ruleBookInfo` TEXT, `ruleToc` TEXT, `ruleContent` TEXT, `ruleReview` TEXT, PRIMARY KEY(`bookSourceUrl`))", "fields": [ { "fieldPath": "bookSourceUrl", @@ -354,6 +354,12 @@ "affinity": "TEXT", "notNull": false }, + { + "fieldPath": "enabledReview", + "columnName": "enabledReview", + "affinity": "INTEGER", + "notNull": false + }, { "fieldPath": "loginCheckJs", "columnName": "loginCheckJs", @@ -431,13 +437,19 @@ "columnName": "ruleContent", "affinity": "TEXT", "notNull": false + }, + { + "fieldPath": "ruleReview", + "columnName": "ruleReview", + "affinity": "TEXT", + "notNull": false } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "bookSourceUrl" - ] + ], + "autoGenerate": false }, "indices": [ { @@ -548,11 +560,11 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "url", "bookUrl" - ] + ], + "autoGenerate": false }, "indices": [ { @@ -676,10 +688,10 @@ } ], "primaryKey": { - "autoGenerate": true, "columnNames": [ "id" - ] + ], + "autoGenerate": true }, "indices": [ { @@ -790,10 +802,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "bookUrl" - ] + ], + "autoGenerate": false }, "indices": [ { @@ -853,10 +865,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "word" - ] + ], + "autoGenerate": false }, "indices": [ { @@ -889,10 +901,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "url" - ] + ], + "autoGenerate": false }, "indices": [ { @@ -1082,10 +1094,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "sourceUrl" - ] + ], + "autoGenerate": false }, "indices": [ { @@ -1154,10 +1166,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "time" - ] + ], + "autoGenerate": false }, "indices": [ { @@ -1245,11 +1257,11 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "origin", "link" - ] + ], + "autoGenerate": false }, "indices": [], "foreignKeys": [] @@ -1272,10 +1284,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "record" - ] + ], + "autoGenerate": false }, "indices": [], "foreignKeys": [] @@ -1346,11 +1358,11 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "origin", "link" - ] + ], + "autoGenerate": false }, "indices": [], "foreignKeys": [] @@ -1397,10 +1409,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "id" - ] + ], + "autoGenerate": false }, "indices": [], "foreignKeys": [] @@ -1437,11 +1449,11 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "deviceId", "bookName" - ] + ], + "autoGenerate": false }, "indices": [], "foreignKeys": [] @@ -1521,10 +1533,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "id" - ] + ], + "autoGenerate": false }, "indices": [], "foreignKeys": [] @@ -1553,10 +1565,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "key" - ] + ], + "autoGenerate": false }, "indices": [ { @@ -1619,10 +1631,10 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "id" - ] + ], + "autoGenerate": false }, "indices": [], "foreignKeys": [] @@ -1661,11 +1673,11 @@ } ], "primaryKey": { - "autoGenerate": false, "columnNames": [ "type", "key" - ] + ], + "autoGenerate": false }, "indices": [], "foreignKeys": [] @@ -1674,7 +1686,7 @@ "views": [], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0221c385ed7393f47afe9579d3106541')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c55dac79aa9cc3dcdb72e91da4282005')" ] } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index f98063115..c9aff1b65 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -50,6 +50,9 @@ interface BookSourceDao { @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") fun flowExplore(): Flow> +// @Query("select * from book_sources where enabledReview = 1 order by customOrder asc") +// fun flowReview(): Flow> + @Query("select * from book_sources where loginUrl is not null and loginUrl != ''") fun flowLogin(): Flow> diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 9f27a31a7..f1302d091 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -49,6 +49,8 @@ data class BookSource( override var loginUrl: String? = null, // 登录UI override var loginUi: String? = null, + // 启用段评 + var enabledReview: Boolean? = false, // 登录检测js var loginCheckJs: String? = null, // 注释 @@ -74,7 +76,9 @@ data class BookSource( // 目录页规则 var ruleToc: TocRule? = null, // 正文页规则 - var ruleContent: ContentRule? = null + var ruleContent: ContentRule? = null, + // 段评规则 + var ruleReview: ReviewRule? = null ) : Parcelable, BaseSource { override fun getTag(): String { @@ -170,6 +174,13 @@ data class BookSource( return rule } + fun getReviewRule(): ReviewRule { + ruleReview?.let { return it } + val rule = ReviewRule() + ruleReview = rule + return rule + } + fun getDisPlayNameGroup(): String { return if (bookSourceGroup.isNullOrBlank()) { bookSourceName @@ -303,5 +314,13 @@ data class BookSource( fun stringToContentRule(json: String?) = GSON.fromJsonObject(json).getOrNull() + @TypeConverter + fun stringToReviewRule(json: String?) = + GSON.fromJsonObject(json).getOrNull() + + @TypeConverter + fun reviewRuleToString(reviewRule: ReviewRule?): String = + GSON.toJson(reviewRule) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ReviewRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ReviewRule.kt new file mode 100644 index 000000000..80bed45eb --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/rule/ReviewRule.kt @@ -0,0 +1,18 @@ +package io.legado.app.data.entities.rule + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize +data class ReviewRule( + var reviewUrl: String? = null, // 段评URL + var avatarRule: String? = null, // 段评发布者头像 + var contentRule: String? = null, // 段评内容 + var postTimeRule: String? = null, // 段评发布时间 + var reviewReplyUrl: String? = null, // 获取段评回复URL + + // 这些功能将在以上功能完成以后实现 + var voteUpUrl: String? = null, // 点赞URL + var voteDownUrl: String? = null, // 点踩URL + var replyUrl: String? = null // 回复URL +): Parcelable \ No newline at end of file diff --git a/app/src/main/res/layout/activity_book_source_edit.xml b/app/src/main/res/layout/activity_book_source_edit.xml index ceae414f2..4b6366974 100644 --- a/app/src/main/res/layout/activity_book_source_edit.xml +++ b/app/src/main/res/layout/activity_book_source_edit.xml @@ -40,18 +40,33 @@ android:checked="true" android:text="@string/auto_save_cookie" /> - + + + + + diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index c94c43ea5..48bf4a0b8 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1010,4 +1010,5 @@ 选中所选区间 返回时提示放入书架 阅读未放入书架的书籍在返回时提示放入书架 + Review diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 0fa495693..fad7b4f6d 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1013,4 +1013,5 @@ 选中所选区间 返回时提示放入书架 阅读未放入书架的书籍在返回时提示放入书架 + Review diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 3ad76156f..2f95b824a 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1013,4 +1013,5 @@ 选中所选区间 返回时提示放入书架 阅读未放入书架的书籍在返回时提示放入书架 + Review diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 9948080db..e44b8780d 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1010,4 +1010,5 @@ 选中所选区间 返回时提示放入书架 阅读未放入书架的书籍在返回时提示放入书架 + 段评 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 5210c961a..811ef3d55 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1012,4 +1012,5 @@ 选中所选区间 返回时提示放入书架 阅读未放入书架的书籍在返回时提示放入书架 + 段评 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index cc6801538..8fddc6150 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1012,4 +1012,5 @@ 选中所选区间 返回时提示放入书架 阅读未放入书架的书籍在返回时提示放入书架 + 段评 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d64ef8432..a5e5b0889 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1013,4 +1013,5 @@ 选中所选区间 返回时提示放入书架 阅读未放入书架的书籍在返回时提示放入书架 + Review