From b0e9b788af06a092758876c1f1d38e15f930e376 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 4 Oct 2021 21:02:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/widget/dialog/CodeDialog.kt | 9 ++++--- .../io/legado/app/utils/CodeViewExtensions.kt | 24 +++++++++++++++++++ .../io/legado/app/utils/ViewExtensions.kt | 11 +++++---- 3 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/io/legado/app/utils/CodeViewExtensions.kt diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/CodeDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/CodeDialog.kt index 4e7297da9..ae52ad358 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/CodeDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/CodeDialog.kt @@ -7,10 +7,11 @@ import android.view.ViewGroup import io.legado.app.R import io.legado.app.base.BaseDialogFragment 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.viewbindingdelegate.viewBinding -import java.util.regex.Pattern class CodeDialog() : BaseDialogFragment() { @@ -36,7 +37,9 @@ class CodeDialog() : BaseDialogFragment() { } 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 { binding.codeView.setText(it) } diff --git a/app/src/main/java/io/legado/app/utils/CodeViewExtensions.kt b/app/src/main/java/io/legado/app/utils/CodeViewExtensions.kt new file mode 100644 index 000000000..7078eaab9 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/CodeViewExtensions.kt @@ -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) +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index cccd7a31f..700dda057 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -1,3 +1,5 @@ +@file:Suppress("unused") + package io.legado.app.utils import android.annotation.SuppressLint @@ -9,10 +11,7 @@ import android.text.Html import android.view.View import android.view.View.* import android.view.inputmethod.InputMethodManager -import android.widget.EdgeEffect -import android.widget.RadioGroup -import android.widget.SeekBar -import android.widget.TextView +import android.widget.* import androidx.annotation.ColorInt import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.menu.MenuPopupHelper @@ -90,6 +89,10 @@ fun ViewPager.setEdgeEffectColor(@ColorInt color: Int) { } } +fun EditText.disableEdit() { + keyListener = null +} + fun View.gone() { if (visibility != GONE) { visibility = GONE