Updated rule

pull/32/head
atbest 6 years ago
parent 7082209416
commit 680520d6f9
  1. 1
      app/src/main/java/io/legado/app/data/entities/rule/ChapterRule.kt
  2. 39
      app/src/main/java/io/legado/app/data/entities/rule/Rule.kt
  3. 1
      app/src/main/java/io/legado/app/help/permission/OnRequestPermissionsResultCallback.kt
  4. 6
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  5. 1
      app/src/main/java/io/legado/app/ui/search/SearchActivity.kt
  6. 2
      app/src/main/res/values/strings.xml

@ -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,

@ -2,12 +2,47 @@ package io.legado.app.data.entities.rule
data class Rule (
var selectors: List<BaseRule>,
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<BaseRule> {
TODO()
}
private fun parseJSON(rawRule: String): List<BaseRule> {
TODO()
}
private fun parseXPATH(rawRule: String): List<BaseRule> {
TODO()
}
private fun parseREGEX(rawRule: String): List<BaseRule> {
TODO()
}
private fun parseCONST(rawRule: String): List<BaseRule> {
TODO()
}
private fun parseJS(rawRule: String): List<BaseRule> {
TODO()
}
}
}
enum class RuleType {
CSS, XPATH, JSON, REGEX, CONST, JS, HYBRID

@ -6,6 +6,5 @@ interface OnRequestPermissionsResultCallback {
fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray)
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
}

@ -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<MainDataBinding, MainViewModel>(), 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 条净化替换规则")
}
}

@ -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

@ -21,7 +21,7 @@
<string name="dialog_setting">去设置</string>
<string name="tip_cannot_jump_setting_page">无法跳转至设置界面</string>
<string name="tip_perm_request_storage">阅读需要访问存储卡权限,请前往“设置”—”应用权限“—打开所需权限</string>
<string name="tip_perm_request_storage">阅读需要访问存储卡权限,请前往“设置”—“应用权限”—打开所需权限</string>
<string name="dynamic_click_retry">点击重试</string>
<string name="dynamic_loading">正在加载</string>

Loading…
Cancel
Save