Compare commits

...

3 Commits

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

@ -13,6 +13,7 @@ import okhttp3.Interceptor
import okhttp3.Response import okhttp3.Response
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@Suppress("PrivatePropertyName")
class NoContentInterceptor(private val logId: Long) : Interceptor { class NoContentInterceptor(private val logId: Long) : Interceptor {
private val TAG: String = NoContentInterceptor::class.java.simpleName private val TAG: String = NoContentInterceptor::class.java.simpleName
@ -20,8 +21,9 @@ class NoContentInterceptor(private val logId: Long) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
val originalResponse = chain.proceed(chain.request()) val originalResponse = chain.proceed(chain.request())
if (originalResponse.code() == 204) { //HTTP Status 201-299 都算成功
val response = "HTTP 204 No Content" if (originalResponse.code() in 201..299) {
val response = "HTTP Status " + originalResponse.code() + " " + originalResponse.message()
Log.d(TAG, response) Log.d(TAG, response)
/* /*
// 创建一个空的响应体 // 创建一个空的响应体

@ -239,18 +239,17 @@ class WebhookUtils {
.timeStamp(true) //url自动追加时间戳避免缓存 .timeStamp(true) //url自动追加时间戳避免缓存
.addInterceptor(LoggingInterceptor(logId)) //增加一个log拦截器, 记录请求日志 .addInterceptor(LoggingInterceptor(logId)) //增加一个log拦截器, 记录请求日志
.addInterceptor(NoContentInterceptor(logId)) //拦截 HTTP 204 响应 .addInterceptor(NoContentInterceptor(logId)) //拦截 HTTP 204 响应
.execute(object : SimpleCallBack<Any>() { .execute(object : SimpleCallBack<String>() {
override fun onError(e: ApiException) { override fun onError(e: ApiException) {
e.printStackTrace() //e.printStackTrace()
Log.e(TAG, e.detailMessage) Log.e(TAG, e.detailMessage)
val status = 0 val status = if (setting.response.isNotEmpty() && e.detailMessage.contains(setting.response)) 2 else 0
SendUtils.updateLogs(logId, status, e.displayMessage) SendUtils.updateLogs(logId, status, e.displayMessage)
SendUtils.senderLogic(status, msgInfo, rule, senderIndex, msgId) SendUtils.senderLogic(status, msgInfo, rule, senderIndex, msgId)
} }
override fun onSuccess(resp: Any) { override fun onSuccess(response: String) {
val response = resp.toString()
Log.i(TAG, response) Log.i(TAG, response)
val status = if (setting.response.isNotEmpty() && !response.contains(setting.response)) 0 else 2 val status = if (setting.response.isNotEmpty() && !response.contains(setting.response)) 0 else 2
SendUtils.updateLogs(logId, status, response) SendUtils.updateLogs(logId, status, response)

@ -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…
Cancel
Save