diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt index 3dfd15fc4..3c27f7bb1 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt @@ -37,6 +37,7 @@ import java.lang.ref.SoftReference import android.os.Build import android.annotation.TargetApi import android.util.Log +import go.Seq import org.jetbrains.anko.doAsync class V2RayVpnService : VpnService() { diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/Server2Activity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/Server2Activity.kt index 4fef0cf75..bdfba4c2b 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/Server2Activity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/Server2Activity.kt @@ -1,9 +1,11 @@ package com.v2ray.ang.ui import android.os.Bundle +import android.text.Editable import android.text.TextUtils import android.view.Menu import android.view.MenuItem +import com.google.gson.Gson import com.v2ray.ang.AppConfig import com.v2ray.ang.R import com.v2ray.ang.extension.defaultDPreference @@ -12,6 +14,7 @@ import com.v2ray.ang.util.AngConfigManager import com.v2ray.ang.util.Utils import kotlinx.android.synthetic.main.activity_server2.* import org.jetbrains.anko.* +import java.lang.Exception class Server2Activity : BaseActivity() { @@ -50,7 +53,7 @@ class Server2Activity : BaseActivity() { */ fun bindingServer(vmess: AngConfig.VmessBean): Boolean { et_remarks.text = Utils.getEditable(vmess.remarks) - tv_content.text = defaultDPreference.getPrefString(AppConfig.ANG_CONFIG + edit_guid, "") + tv_content.text = Editable.Factory.getInstance().newEditable(defaultDPreference.getPrefString(AppConfig.ANG_CONFIG + edit_guid, "")) return true } @@ -66,21 +69,40 @@ class Server2Activity : BaseActivity() { * save server config */ fun saveServer(): Boolean { + var saveSuccess: Boolean val vmess = configs.vmess[edit_index] vmess.remarks = et_remarks.text.toString() if (TextUtils.isEmpty(vmess.remarks)) { toast(R.string.server_lab_remarks) - return false + saveSuccess = false } + if (AngConfigManager.addCustomServer(vmess, edit_index) == 0) { toast(R.string.toast_success) + saveSuccess = true + } else { + toast(R.string.toast_failure) + saveSuccess = false + } + + + try { + Gson().fromJson(tv_content.text.toString(), Object::class.java) + } catch (e: Exception) { + e.printStackTrace() + toast(R.string.toast_malformed_josn) + saveSuccess = false + } + + if (saveSuccess) { + //update config + defaultDPreference.setPrefString(AppConfig.ANG_CONFIG + edit_guid, tv_content.text.toString()) finish() return true } else { - toast(R.string.toast_failure) return false } } diff --git a/V2rayNG/app/src/main/res/layout/activity_server2.xml b/V2rayNG/app/src/main/res/layout/activity_server2.xml index 038d8c12e..7924443ca 100644 --- a/V2rayNG/app/src/main/res/layout/activity_server2.xml +++ b/V2rayNG/app/src/main/res/layout/activity_server2.xml @@ -68,20 +68,15 @@ android:text="@string/server_lab_content" android:textAppearance="@style/TextAppearance.AppCompat.Subhead" /> - - + \ No newline at end of file diff --git a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml index 6fe69c1c4..36fc90aa1 100644 --- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml @@ -184,5 +184,6 @@ 绑定代理入口ip到0.0.0.0 其他设备可以使用socks/http协议通过您的IP地址连接到代理\nHttp 代理: http://您的ip:10809\nSocks 代理: socks(4/5)://您的ip:10808\n仅在受信任的网络中启用以避免未经授权的连接 代理共享已启用,请确保处于受信网络 + 配置格式错误 diff --git a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml index 8c5a3fd8f..09b6ba66c 100644 --- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml @@ -186,4 +186,5 @@ 綁定代理入口ip到0.0.0.0 其他設備可以使用socks/http協議通過您的IP地址連接到代理\nHttp 代理: http://您的ip:10809\nSocks 代理: socks(4/5)://您的ip:10808\n僅在受信任的網絡中啟用以避免未經授權的連接 代理共享已啟用,請確保處於受信網絡 + 配置格式錯誤 diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml index ac4c92541..29c03bf9e 100644 --- a/V2rayNG/app/src/main/res/values/strings.xml +++ b/V2rayNG/app/src/main/res/values/strings.xml @@ -185,5 +185,6 @@ Bind inbound to 0.0.0.0 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 Proxy sharing enabled\nMake sure you are in a trusted network + Config malformed