Преглед изворни кода

Add: Add ReviewRule and related codes

Seidko пре 4 година
родитељ
комит
cabf70e406

+ 53 - 41
app/schemas/io.legado.app.data.AppDatabase/52.json

@@ -2,7 +2,7 @@
   "formatVersion": 1,
   "formatVersion": 1,
   "database": {
   "database": {
     "version": 52,
     "version": 52,
-    "identityHash": "0221c385ed7393f47afe9579d3106541",
+    "identityHash": "c55dac79aa9cc3dcdb72e91da4282005",
     "entities": [
     "entities": [
       {
       {
         "tableName": "books",
         "tableName": "books",
@@ -208,10 +208,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "bookUrl"
             "bookUrl"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [
         "indices": [
           {
           {
@@ -263,17 +263,17 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "groupId"
             "groupId"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [],
         "indices": [],
         "foreignKeys": []
         "foreignKeys": []
       },
       },
       {
       {
         "tableName": "book_sources",
         "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": [
         "fields": [
           {
           {
             "fieldPath": "bookSourceUrl",
             "fieldPath": "bookSourceUrl",
@@ -354,6 +354,12 @@
             "affinity": "TEXT",
             "affinity": "TEXT",
             "notNull": false
             "notNull": false
           },
           },
+          {
+            "fieldPath": "enabledReview",
+            "columnName": "enabledReview",
+            "affinity": "INTEGER",
+            "notNull": false
+          },
           {
           {
             "fieldPath": "loginCheckJs",
             "fieldPath": "loginCheckJs",
             "columnName": "loginCheckJs",
             "columnName": "loginCheckJs",
@@ -431,13 +437,19 @@
             "columnName": "ruleContent",
             "columnName": "ruleContent",
             "affinity": "TEXT",
             "affinity": "TEXT",
             "notNull": false
             "notNull": false
+          },
+          {
+            "fieldPath": "ruleReview",
+            "columnName": "ruleReview",
+            "affinity": "TEXT",
+            "notNull": false
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "bookSourceUrl"
             "bookSourceUrl"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [
         "indices": [
           {
           {
@@ -548,11 +560,11 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "url",
             "url",
             "bookUrl"
             "bookUrl"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [
         "indices": [
           {
           {
@@ -676,10 +688,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": true,
           "columnNames": [
           "columnNames": [
             "id"
             "id"
-          ]
+          ],
+          "autoGenerate": true
         },
         },
         "indices": [
         "indices": [
           {
           {
@@ -790,10 +802,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "bookUrl"
             "bookUrl"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [
         "indices": [
           {
           {
@@ -853,10 +865,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "word"
             "word"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [
         "indices": [
           {
           {
@@ -889,10 +901,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "url"
             "url"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [
         "indices": [
           {
           {
@@ -1082,10 +1094,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "sourceUrl"
             "sourceUrl"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [
         "indices": [
           {
           {
@@ -1154,10 +1166,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "time"
             "time"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [
         "indices": [
           {
           {
@@ -1245,11 +1257,11 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "origin",
             "origin",
             "link"
             "link"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [],
         "indices": [],
         "foreignKeys": []
         "foreignKeys": []
@@ -1272,10 +1284,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "record"
             "record"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [],
         "indices": [],
         "foreignKeys": []
         "foreignKeys": []
@@ -1346,11 +1358,11 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "origin",
             "origin",
             "link"
             "link"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [],
         "indices": [],
         "foreignKeys": []
         "foreignKeys": []
@@ -1397,10 +1409,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "id"
             "id"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [],
         "indices": [],
         "foreignKeys": []
         "foreignKeys": []
@@ -1437,11 +1449,11 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "deviceId",
             "deviceId",
             "bookName"
             "bookName"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [],
         "indices": [],
         "foreignKeys": []
         "foreignKeys": []
@@ -1521,10 +1533,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "id"
             "id"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [],
         "indices": [],
         "foreignKeys": []
         "foreignKeys": []
@@ -1553,10 +1565,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "key"
             "key"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [
         "indices": [
           {
           {
@@ -1619,10 +1631,10 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "id"
             "id"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [],
         "indices": [],
         "foreignKeys": []
         "foreignKeys": []
@@ -1661,11 +1673,11 @@
           }
           }
         ],
         ],
         "primaryKey": {
         "primaryKey": {
-          "autoGenerate": false,
           "columnNames": [
           "columnNames": [
             "type",
             "type",
             "key"
             "key"
-          ]
+          ],
+          "autoGenerate": false
         },
         },
         "indices": [],
         "indices": [],
         "foreignKeys": []
         "foreignKeys": []
@@ -1674,7 +1686,7 @@
     "views": [],
     "views": [],
     "setupQueries": [
     "setupQueries": [
       "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
       "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')"
     ]
     ]
   }
   }
 }
 }

+ 3 - 0
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")
     @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc")
     fun flowExplore(): Flow<List<BookSource>>
     fun flowExplore(): Flow<List<BookSource>>
 
 
+//    @Query("select * from book_sources where enabledReview = 1 order by customOrder asc")
+//    fun flowReview(): Flow<List<BookSource>>
+
     @Query("select * from book_sources where loginUrl is not null and loginUrl != ''")
     @Query("select * from book_sources where loginUrl is not null and loginUrl != ''")
     fun flowLogin(): Flow<List<BookSource>>
     fun flowLogin(): Flow<List<BookSource>>
 
 

+ 20 - 1
app/src/main/java/io/legado/app/data/entities/BookSource.kt

@@ -49,6 +49,8 @@ data class BookSource(
     override var loginUrl: String? = null,
     override var loginUrl: String? = null,
     // 登录UI
     // 登录UI
     override var loginUi: String? = null,
     override var loginUi: String? = null,
+    // 启用段评
+    var enabledReview: Boolean? = false,
     // 登录检测js
     // 登录检测js
     var loginCheckJs: String? = null,
     var loginCheckJs: String? = null,
     // 注释
     // 注释
@@ -74,7 +76,9 @@ data class BookSource(
     // 目录页规则
     // 目录页规则
     var ruleToc: TocRule? = null,
     var ruleToc: TocRule? = null,
     // 正文页规则
     // 正文页规则
-    var ruleContent: ContentRule? = null
+    var ruleContent: ContentRule? = null,
+    // 段评规则
+    var ruleReview: ReviewRule? = null
 ) : Parcelable, BaseSource {
 ) : Parcelable, BaseSource {
 
 
     override fun getTag(): String {
     override fun getTag(): String {
@@ -170,6 +174,13 @@ data class BookSource(
         return rule
         return rule
     }
     }
 
 
+    fun getReviewRule(): ReviewRule {
+        ruleReview?.let { return it }
+        val rule = ReviewRule()
+        ruleReview = rule
+        return rule
+    }
+
     fun getDisPlayNameGroup(): String {
     fun getDisPlayNameGroup(): String {
         return if (bookSourceGroup.isNullOrBlank()) {
         return if (bookSourceGroup.isNullOrBlank()) {
             bookSourceName
             bookSourceName
@@ -303,5 +314,13 @@ data class BookSource(
         fun stringToContentRule(json: String?) =
         fun stringToContentRule(json: String?) =
             GSON.fromJsonObject<ContentRule>(json).getOrNull()
             GSON.fromJsonObject<ContentRule>(json).getOrNull()
 
 
+        @TypeConverter
+        fun stringToReviewRule(json: String?) =
+            GSON.fromJsonObject<ReviewRule>(json).getOrNull()
+
+        @TypeConverter
+        fun reviewRuleToString(reviewRule: ReviewRule?): String =
+            GSON.toJson(reviewRule)
+
     }
     }
 }
 }

+ 18 - 0
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

+ 18 - 3
app/src/main/res/layout/activity_book_source_edit.xml

@@ -40,18 +40,33 @@
             android:checked="true"
             android:checked="true"
             android:text="@string/auto_save_cookie" />
             android:text="@string/auto_save_cookie" />
 
 
-        <TextView
+        <io.legado.app.lib.theme.view.ThemeCheckBox
+            android:id="@+id/cb_is_enable_review"
             android:layout_width="wrap_content"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_height="wrap_content"
+            android:checked="true"
+            android:text="@string/review" />
+
+    </LinearLayout>
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+
+        <TextView
+            android:height="30dp"
+            android:gravity="center"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
             android:text="@string/book_type"
             android:text="@string/book_type"
-            android:layout_marginLeft="12dp"
+            android:layout_marginLeft="8dp"
             android:layout_marginRight="3dp"
             android:layout_marginRight="3dp"
             tools:ignore="RtlHardcoded" />
             tools:ignore="RtlHardcoded" />
 
 
         <androidx.appcompat.widget.AppCompatSpinner
         <androidx.appcompat.widget.AppCompatSpinner
             android:id="@+id/sp_type"
             android:id="@+id/sp_type"
             android:layout_width="wrap_content"
             android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_height="match_parent"
             android:entries="@array/book_type"
             android:entries="@array/book_type"
             app:theme="@style/Spinner" />
             app:theme="@style/Spinner" />
 
 

+ 1 - 0
app/src/main/res/values-es-rES/strings.xml

@@ -1010,4 +1010,5 @@
     <string name="check_selected_interval">选中所选区间</string>
     <string name="check_selected_interval">选中所选区间</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
+    <string name="review">Review</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-ja-rJP/strings.xml

@@ -1013,4 +1013,5 @@
     <string name="check_selected_interval">选中所选区间</string>
     <string name="check_selected_interval">选中所选区间</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
+    <string name="review">Review</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-pt-rBR/strings.xml

@@ -1013,4 +1013,5 @@
     <string name="check_selected_interval">选中所选区间</string>
     <string name="check_selected_interval">选中所选区间</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
+    <string name="review">Review</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-zh-rHK/strings.xml

@@ -1010,4 +1010,5 @@
     <string name="check_selected_interval">选中所选区间</string>
     <string name="check_selected_interval">选中所选区间</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
+    <string name="review">段评</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-zh-rTW/strings.xml

@@ -1012,4 +1012,5 @@
     <string name="check_selected_interval">选中所选区间</string>
     <string name="check_selected_interval">选中所选区间</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
+    <string name="review">段评</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values-zh/strings.xml

@@ -1012,4 +1012,5 @@
     <string name="check_selected_interval">选中所选区间</string>
     <string name="check_selected_interval">选中所选区间</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
+    <string name="review">段评</string>
 </resources>
 </resources>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1013,4 +1013,5 @@
     <string name="check_selected_interval">选中所选区间</string>
     <string name="check_selected_interval">选中所选区间</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
     <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
+    <string name="review">Review</string>
 </resources>
 </resources>