|
|
@ -5,29 +5,31 @@ package io.legado.app.ui.widget.code |
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.widget.ArrayAdapter |
|
|
|
import android.widget.ArrayAdapter |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
|
|
|
|
import io.legado.app.lib.theme.secondaryTextColor |
|
|
|
|
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.init.appCtx |
|
|
|
|
|
|
|
import splitties.resources.color |
|
|
|
import java.util.regex.Pattern |
|
|
|
import java.util.regex.Pattern |
|
|
|
|
|
|
|
|
|
|
|
val legadoPattern: Pattern = Pattern.compile("\\|\\||&&|%%|@js:|@Json:|@css:|@@|@XPath:") |
|
|
|
val legadoPattern: Pattern = Pattern.compile("\\|\\||&&|%%|@js:|@Json:|@css:|@@|@XPath:") |
|
|
|
val jsonPattern: Pattern = Pattern.compile("\"[A-Za-z0-9]*?\"\\:|\"|\\{|\\}|\\[|\\]") |
|
|
|
val jsonPattern: Pattern = Pattern.compile("\"[A-Za-z0-9]*?\"\\:|\"|\\{|\\}|\\[|\\]") |
|
|
|
val wrapPattern: Pattern = Pattern.compile("\\\\n") |
|
|
|
val wrapPattern: Pattern = Pattern.compile("\\\\n") |
|
|
|
val jsPattern: Pattern = Pattern.compile("var|=") |
|
|
|
val operationPattern: Pattern = |
|
|
|
|
|
|
|
Pattern.compile(":|==|>|<|!=|>=|<=|->|=|>|<|%|-|-=|%=|\\+|\\-|\\-=|\\+=|\\^|\\&|\\|::|\\?|\\*") |
|
|
|
|
|
|
|
val jsPattern: Pattern = Pattern.compile("var") |
|
|
|
|
|
|
|
|
|
|
|
fun CodeView.addLegadoPattern() { |
|
|
|
fun CodeView.addLegadoPattern() { |
|
|
|
addSyntaxPattern(legadoPattern, appCtx.accentColor) |
|
|
|
addSyntaxPattern(legadoPattern, appCtx.color(R.color.md_orange_900)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun CodeView.addJsonPattern() { |
|
|
|
fun CodeView.addJsonPattern() { |
|
|
|
addSyntaxPattern(jsonPattern, appCtx.accentColor) |
|
|
|
addSyntaxPattern(jsonPattern, appCtx.color(R.color.md_blue_800)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun CodeView.addJsPattern() { |
|
|
|
fun CodeView.addJsPattern() { |
|
|
|
addSyntaxPattern(wrapPattern, appCtx.secondaryTextColor) |
|
|
|
addSyntaxPattern(wrapPattern, appCtx.color(R.color.md_blue_grey_500)) |
|
|
|
addSyntaxPattern(jsPattern, appCtx.accentColor) |
|
|
|
addSyntaxPattern(operationPattern, appCtx.color(R.color.md_orange_900)) |
|
|
|
|
|
|
|
addSyntaxPattern(jsPattern, appCtx.color(R.color.md_light_blue_600)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun Context.arrayAdapter(keywords: Array<String>): ArrayAdapter<String> { |
|
|
|
fun Context.arrayAdapter(keywords: Array<String>): ArrayAdapter<String> { |
|
|
|
return ArrayAdapter(this, R.layout.item_text, R.id.text_view, keywords) |
|
|
|
return ArrayAdapter(this, R.layout.item_1line_text_and_del, R.id.text_view, keywords) |
|
|
|
} |
|
|
|
} |