pull/1395/head
gedoor 3 years ago
parent 517db36272
commit b0e9b788af
  1. 9
      app/src/main/java/io/legado/app/ui/widget/dialog/CodeDialog.kt
  2. 24
      app/src/main/java/io/legado/app/utils/CodeViewExtensions.kt
  3. 11
      app/src/main/java/io/legado/app/utils/ViewExtensions.kt

@ -7,10 +7,11 @@ import android.view.ViewGroup
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogCodeViewBinding import io.legado.app.databinding.DialogCodeViewBinding
import io.legado.app.lib.theme.accentColor import io.legado.app.utils.addJsPattern
import io.legado.app.utils.addJsonPattern
import io.legado.app.utils.addLegadoPattern
import io.legado.app.utils.setLayout import io.legado.app.utils.setLayout
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.util.regex.Pattern
class CodeDialog() : BaseDialogFragment() { class CodeDialog() : BaseDialogFragment() {
@ -36,7 +37,9 @@ class CodeDialog() : BaseDialogFragment() {
} }
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.codeView.addSyntaxPattern(Pattern.compile("[\",:;[->]{}()]"), accentColor) binding.codeView.addLegadoPattern()
binding.codeView.addJsonPattern()
binding.codeView.addJsPattern()
arguments?.getString("code")?.let { arguments?.getString("code")?.let {
binding.codeView.setText(it) binding.codeView.setText(it)
} }

@ -0,0 +1,24 @@
@file:Suppress("unused")
package io.legado.app.utils
import com.amrdeveloper.codeview.CodeView
import io.legado.app.lib.theme.accentColor
import splitties.init.appCtx
import java.util.regex.Pattern
val legadoPattern: Pattern = Pattern.compile("\\|\\||&&|%%|@js:|@Json:|@css:|@@|@XPath:")
val jsonPattern: Pattern = Pattern.compile("\"\\:|\"|\\{|\\}|\\[|\\]")
val jsPattern: Pattern = Pattern.compile("var|\\\\n")
fun CodeView.addLegadoPattern() {
addSyntaxPattern(legadoPattern, appCtx.accentColor)
}
fun CodeView.addJsonPattern() {
addSyntaxPattern(jsonPattern, appCtx.accentColor)
}
fun CodeView.addJsPattern() {
addSyntaxPattern(jsPattern, appCtx.accentColor)
}

@ -1,3 +1,5 @@
@file:Suppress("unused")
package io.legado.app.utils package io.legado.app.utils
import android.annotation.SuppressLint import android.annotation.SuppressLint
@ -9,10 +11,7 @@ import android.text.Html
import android.view.View import android.view.View
import android.view.View.* import android.view.View.*
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.EdgeEffect import android.widget.*
import android.widget.RadioGroup
import android.widget.SeekBar
import android.widget.TextView
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.menu.MenuPopupHelper import androidx.appcompat.view.menu.MenuPopupHelper
@ -90,6 +89,10 @@ fun ViewPager.setEdgeEffectColor(@ColorInt color: Int) {
} }
} }
fun EditText.disableEdit() {
keyListener = null
}
fun View.gone() { fun View.gone() {
if (visibility != GONE) { if (visibility != GONE) {
visibility = GONE visibility = GONE

Loading…
Cancel
Save