mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-09 19:10:51 +00:00
新增:Frp内网穿透·编辑配置时语法高亮
This commit is contained in:
parent
01aeb8d698
commit
ac45ff6245
@ -26,6 +26,7 @@ import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
|
|||||||
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
|
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
|
||||||
import com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
|
import com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
|
||||||
import com.xuexiang.xutil.resource.ResUtils.getColors
|
import com.xuexiang.xutil.resource.ResUtils.getColors
|
||||||
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@Page(name = "Frp内网穿透·编辑配置")
|
@Page(name = "Frp内网穿透·编辑配置")
|
||||||
@ -34,6 +35,7 @@ class FrpcEditFragment : BaseFragment<FragmentFrpcEditBinding?>() {
|
|||||||
private var titleBar: TitleBar? = null
|
private var titleBar: TitleBar? = null
|
||||||
private var frpc: Frpc? = null
|
private var frpc: Frpc? = null
|
||||||
private val viewModel by viewModels<FrpcViewModel> { BaseViewModelFactory(context) }
|
private val viewModel by viewModels<FrpcViewModel> { BaseViewModelFactory(context) }
|
||||||
|
private val codeview by lazy { binding!!.codeview }
|
||||||
|
|
||||||
override fun initViews() {
|
override fun initViews() {
|
||||||
val pairCompleteMap: MutableMap<Char, Char> = HashMap()
|
val pairCompleteMap: MutableMap<Char, Char> = HashMap()
|
||||||
@ -43,14 +45,25 @@ class FrpcEditFragment : BaseFragment<FragmentFrpcEditBinding?>() {
|
|||||||
pairCompleteMap['<'] = '>'
|
pairCompleteMap['<'] = '>'
|
||||||
pairCompleteMap['"'] = '"'
|
pairCompleteMap['"'] = '"'
|
||||||
|
|
||||||
binding!!.editText.enablePairComplete(true)
|
codeview.enablePairComplete(true)
|
||||||
binding!!.editText.enablePairCompleteCenterCursor(true)
|
codeview.enablePairCompleteCenterCursor(true)
|
||||||
binding!!.editText.setPairCompleteMap(pairCompleteMap)
|
codeview.setPairCompleteMap(pairCompleteMap)
|
||||||
|
|
||||||
binding!!.editText.setEnableLineNumber(true)
|
codeview.setEnableLineNumber(true)
|
||||||
binding!!.editText.setLineNumberTextColor(Color.LTGRAY)
|
codeview.setLineNumberTextColor(Color.LTGRAY)
|
||||||
binding!!.editText.setLineNumberTextSize(24f)
|
codeview.setLineNumberTextSize(24f)
|
||||||
binding!!.editText.textSize = 14f
|
codeview.textSize = 14f
|
||||||
|
|
||||||
|
//语法高亮
|
||||||
|
val syntaxPatterns: MutableMap<Pattern, Int> = HashMap()
|
||||||
|
syntaxPatterns[Pattern.compile("\\s*#.*")] = Color.GRAY
|
||||||
|
syntaxPatterns[Pattern.compile("\\[\\[?([^]]*?)]]?", Pattern.DOTALL)] = Color.MAGENTA
|
||||||
|
syntaxPatterns[Pattern.compile("\\[\\[?")] = Color.WHITE
|
||||||
|
syntaxPatterns[Pattern.compile("]]?")] = Color.WHITE
|
||||||
|
syntaxPatterns[Pattern.compile(".*(?=\\s=)")] = Color.YELLOW
|
||||||
|
syntaxPatterns[Pattern.compile("(?<=\\s=)\\s*\"[^\"]*\"\\s*\n", Pattern.DOTALL)] = Color.GREEN
|
||||||
|
syntaxPatterns[Pattern.compile("(?<=\\s=).*\n")] = Color.CYAN
|
||||||
|
codeview.setSyntaxPatternsMap(syntaxPatterns)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun viewBindingInflate(inflater: LayoutInflater, container: ViewGroup): FragmentFrpcEditBinding {
|
override fun viewBindingInflate(inflater: LayoutInflater, container: ViewGroup): FragmentFrpcEditBinding {
|
||||||
@ -74,7 +87,7 @@ class FrpcEditFragment : BaseFragment<FragmentFrpcEditBinding?>() {
|
|||||||
tvName.setText(frpc!!.name)
|
tvName.setText(frpc!!.name)
|
||||||
sbAutorun.setCheckedImmediately(frpc!!.autorun == 1)
|
sbAutorun.setCheckedImmediately(frpc!!.autorun == 1)
|
||||||
|
|
||||||
frpc!!.config = binding!!.editText.text.toString()
|
frpc!!.config = codeview.text.toString()
|
||||||
|
|
||||||
if (TextUtils.isEmpty(frpc!!.config)) {
|
if (TextUtils.isEmpty(frpc!!.config)) {
|
||||||
XToastUtils.error(R.string.tips_input_config_content)
|
XToastUtils.error(R.string.tips_input_config_content)
|
||||||
@ -128,7 +141,7 @@ class FrpcEditFragment : BaseFragment<FragmentFrpcEditBinding?>() {
|
|||||||
titleBar!!.addAction(object : TitleBar.ImageAction(R.drawable.ic_restore) {
|
titleBar!!.addAction(object : TitleBar.ImageAction(R.drawable.ic_restore) {
|
||||||
@SingleClick
|
@SingleClick
|
||||||
override fun performAction(view: View) {
|
override fun performAction(view: View) {
|
||||||
binding!!.editText.setText(frpc?.config!!)
|
codeview.setText(frpc?.config!!)
|
||||||
XToastUtils.success(R.string.tipRestoreSuccess)
|
XToastUtils.success(R.string.tipRestoreSuccess)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -138,7 +151,7 @@ class FrpcEditFragment : BaseFragment<FragmentFrpcEditBinding?>() {
|
|||||||
override fun initListeners() {
|
override fun initListeners() {
|
||||||
LiveEventBus.get(INTENT_FRPC_EDIT_FILE, Frpc::class.java).observeSticky(this) { value: Frpc ->
|
LiveEventBus.get(INTENT_FRPC_EDIT_FILE, Frpc::class.java).observeSticky(this) { value: Frpc ->
|
||||||
frpc = value
|
frpc = value
|
||||||
binding!!.editText.setText(value.config)
|
codeview.setText(value.config)
|
||||||
titleBar!!.setTitle(if (TextUtils.isEmpty(value.name)) getString(R.string.noName) else value.name)
|
titleBar!!.setTitle(if (TextUtils.isEmpty(value.name)) getString(R.string.noName) else value.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,17 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="?attr/xui_config_color_background"
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<com.amrdeveloper.codeview.CodeView
|
<com.amrdeveloper.codeview.CodeView
|
||||||
android:id="@+id/editText"
|
android:id="@+id/codeview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/black"
|
android:background="#1E1F22"
|
||||||
android:dropDownWidth="@dimen/block_high_height"
|
android:dropDownWidth="@dimen/block_high_height"
|
||||||
android:dropDownHorizontalOffset="0dp"
|
android:dropDownHorizontalOffset="0dp"
|
||||||
android:dropDownSelector="@color/black"
|
android:dropDownSelector="#1E1F22"
|
||||||
android:gravity="top|start"
|
android:gravity="top|start"
|
||||||
android:textColor="@color/darkGreen" />
|
android:textColor="#BCBEC4" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user