From 680520d6f9de993bf634bf6ba7459aefba41c859 Mon Sep 17 00:00:00 2001 From: atbest Date: Fri, 24 May 2019 19:47:47 -0400 Subject: [PATCH] Updated rule --- .../app/data/entities/rule/ChapterRule.kt | 1 + .../io/legado/app/data/entities/rule/Rule.kt | 39 ++++++++++++++++++- .../OnRequestPermissionsResultCallback.kt | 1 - .../io/legado/app/ui/main/MainActivity.kt | 6 +-- .../io/legado/app/ui/search/SearchActivity.kt | 1 + app/src/main/res/values/strings.xml | 2 +- 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ChapterRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ChapterRule.kt index 72df9ac22..830d1295a 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ChapterRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ChapterRule.kt @@ -2,6 +2,7 @@ package io.legado.app.data.entities.rule data class ChapterRule ( var chapterList: Rule, + var isReversed: Boolean = false, var title: Rule, var contentUrl: Rule, var resourceUrl: Rule, 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 421fed660..ffef32688 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 @@ -2,12 +2,47 @@ package io.legado.app.data.entities.rule data class Rule ( var selectors: List, - var type: RuleType, var regex: String?, var replacement: String?, var javascript: String?, var extra: String? -) +) { + companion object { + fun parse(input: String) = when { + 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) + else -> parseCSS(input) + } + + private fun parseCSS(rawRule: String): List { + TODO() + } + + private fun parseJSON(rawRule: String): List { + TODO() + } + + private fun parseXPATH(rawRule: String): List { + TODO() + } + + private fun parseREGEX(rawRule: String): List { + TODO() + } + + private fun parseCONST(rawRule: String): List { + TODO() + } + + private fun parseJS(rawRule: String): List { + TODO() + } + + } +} enum class RuleType { CSS, XPATH, JSON, REGEX, CONST, JS, HYBRID diff --git a/app/src/main/java/io/legado/app/help/permission/OnRequestPermissionsResultCallback.kt b/app/src/main/java/io/legado/app/help/permission/OnRequestPermissionsResultCallback.kt index b86983fd9..3674461bc 100644 --- a/app/src/main/java/io/legado/app/help/permission/OnRequestPermissionsResultCallback.kt +++ b/app/src/main/java/io/legado/app/help/permission/OnRequestPermissionsResultCallback.kt @@ -6,6 +6,5 @@ interface OnRequestPermissionsResultCallback { fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) - fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 10bfe53c3..f6fb83294 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -26,6 +26,7 @@ import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.app_bar_main.* import org.jetbrains.anko.doAsync import org.jetbrains.anko.startActivity +import org.jetbrains.anko.toast import org.jetbrains.anko.uiThread import java.io.File @@ -122,15 +123,14 @@ class MainActivity : BaseActivity(), NavigationV rRule.isEnabled = jsonItem.readBool("$.enable") rRule.order = jsonItem.readInt("$.serialNumber") replaceRules.add(rRule) - // Log.e(APP_TAG, rRule.toString()) } doAsync { App.db.replaceRuleDao().insert(*replaceRules.toTypedArray()) - val count = App.db.replaceRuleDao().all.size + val count = items.size val maxId = App.db.replaceRuleDao().maxOrder uiThread { - Log.e(APP_TAG, "$count records were inserted to database, and max id is $maxId.") + toast("成功地导入 $count 条净化替换规则") } } diff --git a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt index 2adf07e62..c58c611a9 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.search import android.os.Bundle import io.legado.app.R import io.legado.app.base.BaseActivity +import io.legado.app.data.entities.rule.Rule import io.legado.app.utils.getViewModel import org.jetbrains.anko.startActivity diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fd1cb0f6a..0a227369c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -21,7 +21,7 @@ 去设置 无法跳转至设置界面 - 阅读需要访问存储卡权限,请前往“设置”—”应用权限“—打开所需权限 + 阅读需要访问存储卡权限,请前往“设置”—“应用权限”—打开所需权限 点击重试 正在加载