Update UI for gRPC
Separate transport header types for different networks Change UI dynamically based on user selection of network
This commit is contained in:
@@ -5,6 +5,9 @@ import android.support.v7.app.AlertDialog
|
||||
import android.text.TextUtils
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import com.tencent.mmkv.MMKV
|
||||
import com.v2ray.ang.R
|
||||
import com.v2ray.ang.dto.EConfigType
|
||||
@@ -28,6 +31,7 @@ import kotlinx.android.synthetic.main.activity_server_vmess.et_remarks
|
||||
import kotlinx.android.synthetic.main.activity_server_vmess.et_request_host
|
||||
import kotlinx.android.synthetic.main.activity_server_vmess.sp_allow_insecure
|
||||
import kotlinx.android.synthetic.main.activity_server_vmess.sp_header_type
|
||||
import kotlinx.android.synthetic.main.activity_server_vmess.sp_header_type_title
|
||||
import kotlinx.android.synthetic.main.activity_server_vmess.sp_network
|
||||
import kotlinx.android.synthetic.main.activity_server_vmess.sp_stream_security
|
||||
|
||||
@@ -56,8 +60,14 @@ class ServerActivity : BaseActivity() {
|
||||
private val networks: Array<out String> by lazy {
|
||||
resources.getStringArray(R.array.networks)
|
||||
}
|
||||
private val headertypes: Array<out String> by lazy {
|
||||
resources.getStringArray(R.array.headertypes)
|
||||
private val tcpTypes: Array<out String> by lazy {
|
||||
resources.getStringArray(R.array.header_type_tcp)
|
||||
}
|
||||
private val kcpAndQuicTypes: Array<out String> by lazy {
|
||||
resources.getStringArray(R.array.header_type_kcp_and_quic)
|
||||
}
|
||||
private val grpcModes: Array<out String> by lazy {
|
||||
resources.getStringArray(R.array.mode_type_grpc)
|
||||
}
|
||||
private val streamSecuritys: Array<out String> by lazy {
|
||||
resources.getStringArray(R.array.streamsecurityxs)
|
||||
@@ -79,6 +89,26 @@ class ServerActivity : BaseActivity() {
|
||||
// EConfigType.VLESS -> setContentView(R.layout.activity_server_vless)
|
||||
// EConfigType.TROJAN -> setContentView(R.layout.activity_server_trojan)
|
||||
}
|
||||
sp_network?.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
val types = transportTypes(networks[position])
|
||||
sp_header_type?.isEnabled = types.size > 1
|
||||
val adapter = ArrayAdapter(this@ServerActivity, android.R.layout.simple_spinner_item, types)
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
sp_header_type?.adapter = adapter
|
||||
sp_header_type_title?.text = if (networks[position] == "grpc")
|
||||
getString(R.string.server_lab_mode_type) else
|
||||
getString(R.string.server_lab_head_type)
|
||||
config?.getProxyOutbound()?.getTransportSettingDetails()?.let { transportDetails ->
|
||||
sp_header_type.setSelection(Utils.arrayFind(types, transportDetails[0]))
|
||||
et_request_host.text = Utils.getEditable(transportDetails[1])
|
||||
et_path.text = Utils.getEditable(transportDetails[2])
|
||||
}
|
||||
}
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
if (config != null) {
|
||||
bindingServer(config)
|
||||
} else {
|
||||
@@ -129,11 +159,6 @@ class ServerActivity : BaseActivity() {
|
||||
if (network >= 0) {
|
||||
sp_network?.setSelection(network)
|
||||
}
|
||||
outbound.getTransportSettingDetails()?.let { transportDetails ->
|
||||
sp_header_type.setSelection(Utils.arrayFind(headertypes, transportDetails[0]))
|
||||
et_request_host.text = Utils.getEditable(transportDetails[1])
|
||||
et_path.text = Utils.getEditable(transportDetails[2])
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -246,11 +271,12 @@ class ServerActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private fun saveStreamSettings(streamSetting: V2rayConfig.OutboundBean.StreamSettingsBean, config: ServerConfig) {
|
||||
val network = if (sp_network != null) networks[sp_network.selectedItemPosition] else DEFAULT_NETWORK
|
||||
val requestHost = if (et_request_host != null) et_request_host.text.toString().trim() else ""
|
||||
val path = if (et_path != null) et_path.text.toString().trim() else ""
|
||||
var sni = streamSetting.populateTransportSettings(
|
||||
if (sp_network != null) networks[sp_network.selectedItemPosition] else DEFAULT_NETWORK,
|
||||
if (sp_header_type != null) headertypes[sp_header_type.selectedItemPosition] else "",
|
||||
network,
|
||||
if (sp_header_type != null) transportTypes(network)[sp_header_type.selectedItemPosition] else "",
|
||||
requestHost,
|
||||
path,
|
||||
path,
|
||||
@@ -270,6 +296,18 @@ class ServerActivity : BaseActivity() {
|
||||
)
|
||||
}
|
||||
|
||||
private fun transportTypes(network: String?): Array<out String> {
|
||||
return if (network == "tcp") {
|
||||
tcpTypes
|
||||
} else if (network == "kcp" || network == "quic") {
|
||||
kcpAndQuicTypes
|
||||
} else if (network == "grpc") {
|
||||
grpcModes
|
||||
} else {
|
||||
arrayOf("---")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* save server config
|
||||
*/
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sp_header_type_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/server_lab_head_type" />
|
||||
@@ -181,8 +182,7 @@
|
||||
<Spinner
|
||||
android:id="@+id/sp_header_type"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/edit_height"
|
||||
android:entries="@array/headertypes" />
|
||||
android:layout_height="@dimen/edit_height" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -43,8 +43,9 @@
|
||||
<string name="server_lab_network">传输协议(network)</string>
|
||||
<string name="server_lab_more_function">功能设置(不清楚则保持默认值)</string>
|
||||
<string name="server_lab_head_type">伪装类型(type)</string>
|
||||
<string name="server_lab_mode_type">gRPC 传输模式 (mode)</string>
|
||||
<string name="server_lab_request_host">伪装域名(host)(host/ws host/h2 host)/QUIC 加密方式</string>
|
||||
<string name="server_lab_path">path(ws path/h2 path)/QUIC 加密密钥/kcp seed/grpc serviceName</string>
|
||||
<string name="server_lab_path">path(ws path/h2 path)/QUIC 加密密钥/kcp seed/gRPC serviceName</string>
|
||||
<string name="server_lab_stream_security">底层传输安全(tls)</string>
|
||||
<string name="server_lab_allow_insecure">跳过证书验证(allowInsecure)</string>
|
||||
<string name="server_lab_address3">服务器地址</string>
|
||||
|
||||
@@ -43,8 +43,9 @@
|
||||
<string name="server_lab_network">網路</string>
|
||||
<string name="server_lab_more_function">更多功能</string>
|
||||
<string name="server_lab_head_type">標頭類型</string>
|
||||
<string name="server_lab_mode_type">gRPC 傳輸模式 (mode)</string>
|
||||
<string name="server_lab_request_host">要求主機(host)(host/ws host/h2 host)/QUIC加密方式</string>
|
||||
<string name="server_lab_path">path(ws path/h2 path)/QUIC加密密鑰/kcp seed/grpc serviceName</string>
|
||||
<string name="server_lab_path">path(ws path/h2 path)/QUIC加密密鑰/kcp seed/gRPC serviceName</string>
|
||||
<string name="server_lab_stream_security">傳輸層安全性(tls)</string>
|
||||
<string name="server_lab_allow_insecure">跳過證書驗證(allowInsecure)</string>
|
||||
<string name="server_lab_address3">伺服器位址</string>
|
||||
|
||||
@@ -27,9 +27,13 @@
|
||||
<item>grpc</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="headertypes" translatable="false">
|
||||
<string-array name="header_type_tcp" translatable="false">
|
||||
<item>none</item>
|
||||
<item>http</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="header_type_kcp_and_quic" translatable="false">
|
||||
<item>none</item>
|
||||
<item>srtp</item>
|
||||
<item>utp</item>
|
||||
<item>wechat-video</item>
|
||||
@@ -37,18 +41,10 @@
|
||||
<item>wireguard</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="headertypetcps" translatable="false">
|
||||
<item>none</item>
|
||||
<item>http</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="headertypekcps" translatable="false">
|
||||
<item>none</item>
|
||||
<item>srtp</item>
|
||||
<item>utp</item>
|
||||
<item>wechat-video</item>
|
||||
<item>dtls</item>
|
||||
<item>wireguard</item>
|
||||
<string-array name="mode_type_grpc" translatable="false">
|
||||
<item>gun</item>
|
||||
<item>multi</item>
|
||||
<!--Hide this option until core support it <item>guna</item>-->
|
||||
</string-array>
|
||||
|
||||
<string-array name="streamsecuritys" translatable="false">
|
||||
|
||||
@@ -40,11 +40,12 @@
|
||||
<string name="server_lab_id">id</string>
|
||||
<string name="server_lab_alterid">alterId</string>
|
||||
<string name="server_lab_security">security</string>
|
||||
<string name="server_lab_network">network</string>
|
||||
<string name="server_lab_network">Network</string>
|
||||
<string name="server_lab_more_function">more function</string>
|
||||
<string name="server_lab_head_type">head type</string>
|
||||
<string name="server_lab_mode_type">gRPC mode</string>
|
||||
<string name="server_lab_request_host">request host(host/ws host/h2 host)/QUIC security</string>
|
||||
<string name="server_lab_path">path(ws path/h2 path)/QUIC key/kcp seed/grpc serviceName</string>
|
||||
<string name="server_lab_path">path(ws path/h2 path)/QUIC key/kcp seed/gRPC serviceName</string>
|
||||
<string name="server_lab_stream_security">tls</string>
|
||||
<string name="server_lab_allow_insecure">allowInsecure</string>
|
||||
<string name="server_lab_address3">address</string>
|
||||
|
||||
Reference in New Issue
Block a user