Use EditorKit for custom config

https://github.com/massivemadness/Squircle-IDE
This commit is contained in:
yuhan6665
2021-07-09 18:16:39 -04:00
parent 57476290d3
commit a23245435f
4 changed files with 24 additions and 18 deletions

View File

@@ -99,6 +99,8 @@ dependencies {
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
implementation 'com.github.jorgecastilloprz:fabprogresscircle:1.01@aar'
implementation 'me.drakeet.support:toastcompat:1.1.0'
implementation 'com.blacksquircle.ui:editorkit:2.0.0'
implementation 'com.blacksquircle.ui:language-json:2.0.0'
implementation(name: 'libv2ray', ext: 'aar')
//implementation(name: 'tun2socks', ext: 'aar')

View File

@@ -28,6 +28,8 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> -->
<uses-sdk tools:overrideLibrary="com.blacksquircle.ui.editorkit, com.blacksquircle.ui.language.json, com.blacksquircle.ui.language.base"/>
<application
android:name=".AngApplication"
android:allowBackup="true"

View File

@@ -1,11 +1,12 @@
package com.v2ray.ang.ui
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import android.text.TextUtils
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import com.blacksquircle.ui.language.json.JsonLanguage
import com.google.gson.Gson
import com.tencent.mmkv.MMKV
import com.v2ray.ang.R
@@ -34,6 +35,7 @@ class ServerCustomConfigActivity : BaseActivity() {
setContentView(R.layout.activity_server_custom_config)
title = getString(R.string.title_server)
editor.language = JsonLanguage()
val config = MmkvManager.decodeServerConfig(editGuid)
if (config != null) {
bindingServer(config)
@@ -50,9 +52,9 @@ class ServerCustomConfigActivity : BaseActivity() {
et_remarks.text = Utils.getEditable(config.remarks)
val raw = serverRawStorage?.decodeString(editGuid)
if (raw.isNullOrBlank()) {
tv_content.text = Utils.getEditable(config.fullConfig?.toPrettyPrinting().orEmpty())
editor.setTextContent(Utils.getEditable(config.fullConfig?.toPrettyPrinting().orEmpty()))
} else {
tv_content.text = Utils.getEditable(raw)
editor.setTextContent(Utils.getEditable(raw))
}
return true
}
@@ -75,7 +77,7 @@ class ServerCustomConfigActivity : BaseActivity() {
}
val v2rayConfig = try {
Gson().fromJson(tv_content.text.toString(), V2rayConfig::class.java)
Gson().fromJson(editor.text.toString(), V2rayConfig::class.java)
} catch (e: Exception) {
e.printStackTrace()
ToastCompat.makeText(this, "${getString(R.string.toast_malformed_josn)} ${e.cause?.message}", Toast.LENGTH_LONG).show()
@@ -87,7 +89,7 @@ class ServerCustomConfigActivity : BaseActivity() {
config.fullConfig = v2rayConfig
MmkvManager.encodeServerConfig(editGuid, config)
serverRawStorage?.encode(editGuid, tv_content.text.toString())
serverRawStorage?.encode(editGuid, editor.text.toString())
toast(R.string.toast_success)
finish()
return true

View File

@@ -8,14 +8,13 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/layout_margin_top_height">
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/layout_margin_top_height">
android:layout_margin="@dimen/layout_margin_spacing">
<TextView
android:layout_width="wrap_content"
@@ -28,7 +27,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:layout_margin="@dimen/layout_margin_spacing">
<TextView
android:layout_width="wrap_content"
@@ -40,7 +40,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:layout_margin="@dimen/layout_margin_spacing"
android:orientation="vertical">
<TextView
@@ -59,24 +59,24 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/layout_margin_spacing"
android:text="@string/server_lab_content"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
<EditText
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:text="" />
<com.blacksquircle.ui.editorkit.widget.TextProcessor
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top|start"
android:id="@+id/editor"
android:layout_marginTop="@dimen/layout_margin_top_height" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</ScrollView>