Skip to content

Commit 746254b

Browse files
author
Annoymous contributor
committed
Give user the ability to edit/copy/paste custom config for convenience.
Fix import for go.Seq
1 parent 2227ea3 commit 746254b

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import java.lang.ref.SoftReference
3737
import android.os.Build
3838
import android.annotation.TargetApi
3939
import android.util.Log
40+
import go.Seq
4041
import org.jetbrains.anko.doAsync
4142

4243
class V2RayVpnService : VpnService() {

V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/Server2Activity.kt

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.v2ray.ang.ui
22

33
import android.os.Bundle
4+
import android.text.Editable
45
import android.text.TextUtils
56
import android.view.Menu
67
import android.view.MenuItem
8+
import com.google.gson.Gson
79
import com.v2ray.ang.AppConfig
810
import com.v2ray.ang.R
911
import com.v2ray.ang.extension.defaultDPreference
@@ -12,6 +14,7 @@ import com.v2ray.ang.util.AngConfigManager
1214
import com.v2ray.ang.util.Utils
1315
import kotlinx.android.synthetic.main.activity_server2.*
1416
import org.jetbrains.anko.*
17+
import java.lang.Exception
1518

1619

1720
class Server2Activity : BaseActivity() {
@@ -50,7 +53,7 @@ class Server2Activity : BaseActivity() {
5053
*/
5154
fun bindingServer(vmess: AngConfig.VmessBean): Boolean {
5255
et_remarks.text = Utils.getEditable(vmess.remarks)
53-
tv_content.text = defaultDPreference.getPrefString(AppConfig.ANG_CONFIG + edit_guid, "")
56+
tv_content.text = Editable.Factory.getInstance().newEditable(defaultDPreference.getPrefString(AppConfig.ANG_CONFIG + edit_guid, ""))
5457
return true
5558
}
5659

@@ -66,21 +69,40 @@ class Server2Activity : BaseActivity() {
6669
* save server config
6770
*/
6871
fun saveServer(): Boolean {
72+
var saveSuccess: Boolean
6973
val vmess = configs.vmess[edit_index]
7074

7175
vmess.remarks = et_remarks.text.toString()
7276

7377
if (TextUtils.isEmpty(vmess.remarks)) {
7478
toast(R.string.server_lab_remarks)
75-
return false
79+
saveSuccess = false
7680
}
7781

82+
7883
if (AngConfigManager.addCustomServer(vmess, edit_index) == 0) {
7984
toast(R.string.toast_success)
85+
saveSuccess = true
86+
} else {
87+
toast(R.string.toast_failure)
88+
saveSuccess = false
89+
}
90+
91+
92+
try {
93+
Gson().fromJson<Object>(tv_content.text.toString(), Object::class.java)
94+
} catch (e: Exception) {
95+
e.printStackTrace()
96+
toast(R.string.toast_malformed_josn)
97+
saveSuccess = false
98+
}
99+
100+
if (saveSuccess) {
101+
//update config
102+
defaultDPreference.setPrefString(AppConfig.ANG_CONFIG + edit_guid, tv_content.text.toString())
80103
finish()
81104
return true
82105
} else {
83-
toast(R.string.toast_failure)
84106
return false
85107
}
86108
}

V2rayNG/app/src/main/res/layout/activity_server2.xml

+4-9
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,15 @@
6868
android:text="@string/server_lab_content"
6969
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
7070

71-
<TextView
71+
<EditText
7272
android:id="@+id/tv_content"
73-
android:layout_width="wrap_content"
74-
android:layout_height="wrap_content"
73+
android:layout_width="match_parent"
74+
android:layout_height="match_parent"
7575
android:layout_marginTop="@dimen/layout_margin_top_height"
7676
android:text="" />
7777
</LinearLayout>
7878

79-
<LinearLayout
80-
android:layout_width="match_parent"
81-
android:layout_height="wrap_content"
82-
android:layout_marginTop="@dimen/layout_margin_top_height"
83-
android:layout_marginBottom="@dimen/layout_margin_top_height"
84-
android:orientation="vertical" />
79+
8580

8681
</LinearLayout>
8782
</ScrollView>

V2rayNG/app/src/main/res/values-zh-rCN/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,6 @@
184184
<string name="summary_pref_proxy_sharing_enabled">绑定代理入口ip到0.0.0.0</string>
185185
<string name="toast_warning_pref_proxysharing">其他设备可以使用socks/http协议通过您的IP地址连接到代理\nHttp 代理: http://您的ip:10809\nSocks 代理: socks(4/5)://您的ip:10808\n仅在受信任的网络中启用以避免未经授权的连接</string>
186186
<string name="toast_warning_pref_proxysharing_short">代理共享已启用,请确保处于受信网络</string>
187+
<string name="toast_malformed_josn">配置格式错误</string>
187188

188189
</resources>

V2rayNG/app/src/main/res/values-zh-rTW/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,5 @@
186186
<string name="summary_pref_proxy_sharing_enabled">綁定代理入口ip到0.0.0.0</string>
187187
<string name="toast_warning_pref_proxysharing">其他設備可以使用socks/http協議通過您的IP地址連接到代理\nHttp 代理: http://您的ip:10809\nSocks 代理: socks(4/5)://您的ip:10808\n僅在受信任的網絡中啟用以避免未經授權的連接</string>
188188
<string name="toast_warning_pref_proxysharing_short">代理共享已啟用,請確保處於受信網絡</string>
189+
<string name="toast_malformed_josn">配置格式錯誤</string>
189190
</resources>

V2rayNG/app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,6 @@
185185
<string name="summary_pref_proxy_sharing_enabled">Bind inbound to 0.0.0.0</string>
186186
<string name="toast_warning_pref_proxysharing">Other devices can connect to proxy by your ip address through socks/http protocol\nHttp Proxy: http://yourIP:10809\nSocks Proxy: socks(4/5)://yourIP:10808\nOnly enable in trusted network to avoid unauthorized connection</string>
187187
<string name="toast_warning_pref_proxysharing_short">Proxy sharing enabled\nMake sure you are in a trusted network</string>
188+
<string name="toast_malformed_josn">Config malformed</string>
188189

189190
</resources>

0 commit comments

Comments
 (0)