From a12909e33dc27fe23fb44b9bffe346d55121a8e8 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Sat, 2 May 2026 19:00:17 +0800
Subject: [PATCH] Add proxy-chain feature (UI & core support)
Introduce a new Proxy Chain server type and full support across UI and core logic. Added EConfigType.PROXYCHAIN and ProfileItem.proxyChainProfiles, new ServerProxyChainActivity, ServerProxyChainMemberAdapter, layouts and menu entries, and localized strings. CoreConfigContextBuilder now resolves proxy-chain members (from explicit list or subscription group) with robust filtering and error logging; CoreConfigManager validates chain length and logs warnings. CoreOutboundBuilder and CoreServiceManager were updated to treat PROXYCHAIN as a non-directly-runnable config type. Various UI flows (GroupServerFragment, MainActivity, ServerActivity) updated to handle the new type.
---
V2rayNG/app/src/main/AndroidManifest.xml | 4 +
.../ang/core/CoreConfigContextBuilder.kt | 114 ++++++---
.../com/v2ray/ang/core/CoreConfigManager.kt | 12 +-
.../com/v2ray/ang/core/CoreOutboundBuilder.kt | 5 +-
.../com/v2ray/ang/core/CoreServiceManager.kt | 1 +
.../java/com/v2ray/ang/dto/ProfileItem.kt | 2 +
.../java/com/v2ray/ang/enums/EConfigType.kt | 3 +-
.../com/v2ray/ang/handler/AngConfigManager.kt | 3 -
.../com/v2ray/ang/ui/GroupServerFragment.kt | 8 +-
.../java/com/v2ray/ang/ui/MainActivity.kt | 11 +
.../java/com/v2ray/ang/ui/ServerActivity.kt | 2 -
.../v2ray/ang/ui/ServerProxyChainActivity.kt | 228 ++++++++++++++++++
.../ang/ui/ServerProxyChainMemberAdapter.kt | 136 +++++++++++
.../layout/activity_server_proxy_chain.xml | 72 ++++++
.../item_recycler_proxy_chain_member.xml | 84 +++++++
V2rayNG/app/src/main/res/menu/menu_main.xml | 4 +
.../app/src/main/res/values-ar/strings.xml | 7 +
.../app/src/main/res/values-bn/strings.xml | 7 +
.../src/main/res/values-bqi-rIR/strings.xml | 7 +
.../app/src/main/res/values-fa/strings.xml | 7 +
.../app/src/main/res/values-ru/strings.xml | 7 +
.../app/src/main/res/values-vi/strings.xml | 7 +
.../src/main/res/values-zh-rCN/strings.xml | 7 +
.../src/main/res/values-zh-rTW/strings.xml | 7 +
V2rayNG/app/src/main/res/values/strings.xml | 8 +
25 files changed, 697 insertions(+), 56 deletions(-)
create mode 100644 V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerProxyChainActivity.kt
create mode 100644 V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerProxyChainMemberAdapter.kt
create mode 100644 V2rayNG/app/src/main/res/layout/activity_server_proxy_chain.xml
create mode 100644 V2rayNG/app/src/main/res/layout/item_recycler_proxy_chain_member.xml
diff --git a/V2rayNG/app/src/main/AndroidManifest.xml b/V2rayNG/app/src/main/AndroidManifest.xml
index e53a660d..07b2949b 100644
--- a/V2rayNG/app/src/main/AndroidManifest.xml
+++ b/V2rayNG/app/src/main/AndroidManifest.xml
@@ -82,6 +82,10 @@
android:name=".ui.ServerGroupActivity"
android:exported="false"
android:windowSoftInputMode="stateUnchanged" />
+
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreConfigContextBuilder.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreConfigContextBuilder.kt
index d0e87592..fd067f79 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreConfigContextBuilder.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreConfigContextBuilder.kt
@@ -41,8 +41,13 @@ object CoreConfigContextBuilder {
Pair(profiles, CoreResolvedType.POLICYGROUP)
}
+ EConfigType.PROXYCHAIN -> {
+ val profiles = resolveProxyChainProfiles(config)
+ Pair(profiles, CoreResolvedType.PROXYCHAIN)
+ }
+
else -> {
- val chainProfiles = resolveProxyChainProfiles(config)
+ val chainProfiles = resolveProxyChainProfilesFromGroup(config)
val type = if (chainProfiles.size <= 1) CoreResolvedType.NORMAL else CoreResolvedType.PROXYCHAIN
Pair(chainProfiles, type)
}
@@ -61,42 +66,72 @@ object CoreConfigContextBuilder {
/** Resolves policy-group members with the same filters as runtime build. */
private fun resolvePolicyGroupProfiles(config: ProfileItem): List {
- val serverList = MmkvManager.decodeAllServerList()
- return serverList
- .asSequence()
- .mapNotNull { id -> MmkvManager.decodeServerConfig(id) }
- .filter { profile ->
- val subscriptionId = config.policyGroupSubscriptionId
- if (subscriptionId.isNullOrBlank()) {
- true
- } else {
- profile.subscriptionId == subscriptionId
- }
- }
- .filter { profile ->
- val filter = config.policyGroupFilter
- if (filter.isNullOrBlank()) {
- true
- } else {
- try {
- Regex(filter).containsMatchIn(profile.remarks)
- } catch (_: Exception) {
- profile.remarks.contains(filter)
+ try {
+ val serverList = MmkvManager.decodeAllServerList()
+ return serverList
+ .asSequence()
+ .mapNotNull { id -> MmkvManager.decodeServerConfig(id) }
+ .filter { profile ->
+ val subscriptionId = config.policyGroupSubscriptionId
+ if (subscriptionId.isNullOrBlank()) {
+ true
+ } else {
+ profile.subscriptionId == subscriptionId
}
}
- }
- .filter { it.server.isNotNullEmpty() }
- .filter { !Utils.isPureIpAddress(it.server!!) || Utils.isValidUrl(it.server!!) }
- .filter { it.configType != EConfigType.CUSTOM }
- .filter { it.configType != EConfigType.POLICYGROUP }
- .toList()
+ .filter { profile ->
+ val filter = config.policyGroupFilter
+ if (filter.isNullOrBlank()) {
+ true
+ } else {
+ try {
+ Regex(filter).containsMatchIn(profile.remarks)
+ } catch (_: Exception) {
+ profile.remarks.contains(filter)
+ }
+ }
+ }
+ .filter { it.server.isNotNullEmpty() }
+ .filter { !Utils.isPureIpAddress(it.server!!) || Utils.isValidUrl(it.server!!) }
+ .filter { it.configType != EConfigType.CUSTOM }
+ .filter { it.configType != EConfigType.POLICYGROUP }
+ .filter { it.configType != EConfigType.PROXYCHAIN }
+ .toList()
+ }
+ catch (e: Exception) {
+ LogUtil.e(AppConfig.TAG, "Failed to resolve policy group profiles for config '${config.remarks}'", e)
+ return listOf(config)
+ }
+ }
+
+ /** Resolves proxy-chain members with the same filters as runtime build. */
+ private fun resolveProxyChainProfiles(config: ProfileItem): List {
+ if (config.proxyChainProfiles.isNullOrBlank()) {
+ return listOf(config)
+ }
+
+ try {
+ return config.proxyChainProfiles.orEmpty().split(",")
+ .asSequence()
+ .mapNotNull { remark -> SettingsManager.getServerViaRemarks(remark) }
+ .filter { it.server.isNotNullEmpty() }
+ .filter { !Utils.isPureIpAddress(it.server!!) || Utils.isValidUrl(it.server!!) }
+ .filter { it.configType != EConfigType.CUSTOM }
+ .filter { it.configType != EConfigType.POLICYGROUP }
+ .filter { it.configType != EConfigType.PROXYCHAIN }
+ .toList()
+ }
+ catch (e: Exception) {
+ LogUtil.e(AppConfig.TAG, "Failed to resolve proxy chain profiles for config '${config.remarks}'", e)
+ return listOf(config)
+ }
}
/**
* Resolves chain nodes in fixed order: next -> current -> prev.
* If chain cannot be built, caller treats result as normal mode.
*/
- private fun resolveProxyChainProfiles(config: ProfileItem): List {
+ private fun resolveProxyChainProfilesFromGroup(config: ProfileItem): List {
if (MmkvManager.decodeSettingsBool(AppConfig.PREF_FRAGMENT_ENABLED, false) == true) {
return listOf(config)
}
@@ -104,16 +139,21 @@ object CoreConfigContextBuilder {
return listOf(config)
}
- val subItem = MmkvManager.decodeSubscription(config.subscriptionId) ?: return listOf(config)
- val resolved = mutableListOf()
+ try {
+ val subItem = MmkvManager.decodeSubscription(config.subscriptionId) ?: return listOf(config)
+ val resolved = mutableListOf()
- // Keep the same practical chain order as current runtime assembly:
- // next -> current -> prev
- SettingsManager.getServerViaRemarks(subItem.nextProfile)?.let { resolved.add(it) }
- resolved.add(config)
- SettingsManager.getServerViaRemarks(subItem.prevProfile)?.let { resolved.add(it) }
+ // Keep the same practical chain order as current runtime assembly:
+ // next -> current -> prev
+ SettingsManager.getServerViaRemarks(subItem.nextProfile)?.let { resolved.add(it) }
+ resolved.add(config)
+ SettingsManager.getServerViaRemarks(subItem.prevProfile)?.let { resolved.add(it) }
- return resolved
+ return resolved
+ } catch (e: Exception) {
+ LogUtil.e(AppConfig.TAG, "Failed to resolve proxy chain profiles from group for config '${config.remarks}'", e)
+ return listOf(config)
+ }
}
/**
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreConfigManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreConfigManager.kt
index f15a9821..074c0fbe 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreConfigManager.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreConfigManager.kt
@@ -197,24 +197,20 @@ object CoreConfigManager {
val config = configContext.selectedProfile
val resolvedProfiles = configContext.resolvedProfiles
- val address = config.server ?: return null
- if (!Utils.isPureIpAddress(address) && !Utils.isValidUrl(address)) {
- LogUtil.w(AppConfig.TAG, "$address is an invalid ip or domain")
- return null
- }
-
val v2rayConfig = initV2rayConfig(configContext) ?: return null
v2rayConfig.log.loglevel = MmkvManager.decodeSettingsString(AppConfig.PREF_LOGLEVEL) ?: "warning"
v2rayConfig.remarks = config.remarks
getInbounds(v2rayConfig)
- // Chain nodes are ordered as: next... -> current -> ...prev.
// Build and link the whole chain directly from resolvedProfiles.
val chainOutbounds = resolvedProfiles.mapNotNull { profile ->
convertProfile2Outbound(profile)
}.toMutableList()
- if (chainOutbounds.size < 2) return null
+ if (chainOutbounds.size < 2) {
+ LogUtil.w(AppConfig.TAG, "Proxy chain requires at least 2 valid profiles, but only ${chainOutbounds.size} found")
+ return null
+ }
chainOutbounds.forEachIndexed { index, outbound ->
outbound.tag = if (index == 0) AppConfig.TAG_PROXY else AppConfig.TAG_PROXY + index
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreOutboundBuilder.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreOutboundBuilder.kt
index 6c18cab5..b4cfe385 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreOutboundBuilder.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreOutboundBuilder.kt
@@ -26,7 +26,6 @@ object CoreOutboundBuilder {
fun convert(profileItem: ProfileItem): OutboundBean? {
val outbound = when (profileItem.configType) {
EConfigType.VMESS -> toOutboundVmess(profileItem)
- EConfigType.CUSTOM -> null
EConfigType.SHADOWSOCKS -> toOutboundShadowsocks(profileItem)
EConfigType.SOCKS -> toOutboundSocks(profileItem)
EConfigType.VLESS -> toOutboundVless(profileItem)
@@ -34,7 +33,6 @@ object CoreOutboundBuilder {
EConfigType.WIREGUARD -> toOutboundWireguard(profileItem)
EConfigType.HYSTERIA2 -> toOutboundHysteria2(profileItem)
EConfigType.HTTP -> toOutboundHttp(profileItem)
- EConfigType.POLICYGROUP -> null
else -> null
}
@@ -165,8 +163,7 @@ object CoreOutboundBuilder {
streamSettings = OutboundBean.StreamSettingsBean()
)
- EConfigType.CUSTOM -> null
- EConfigType.POLICYGROUP -> null
+ else -> null
}
}
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreServiceManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreServiceManager.kt
index 3129dd1d..8cc09e78 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreServiceManager.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreServiceManager.kt
@@ -127,6 +127,7 @@ object CoreServiceManager {
if (config.configType != EConfigType.CUSTOM
&& config.configType != EConfigType.POLICYGROUP
+ && config.configType != EConfigType.PROXYCHAIN
&& !Utils.isValidUrl(config.server)
&& !Utils.isPureIpAddress(config.server.orEmpty())
) {
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/dto/ProfileItem.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/dto/ProfileItem.kt
index 2c4bb147..33834d47 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/dto/ProfileItem.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/dto/ProfileItem.kt
@@ -69,6 +69,7 @@ data class ProfileItem(
var policyGroupType: String? = null,
var policyGroupSubscriptionId: String? = null,
var policyGroupFilter: String? = null,
+ var proxyChainProfiles: String? = null,
) {
companion object {
@@ -129,6 +130,7 @@ data class ProfileItem(
&& this.portHopping == obj.portHopping
&& this.portHoppingInterval == obj.portHoppingInterval
&& this.pinnedCA256 == obj.pinnedCA256
+ && this.proxyChainProfiles == obj.proxyChainProfiles
)
}
}
\ No newline at end of file
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/enums/EConfigType.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/enums/EConfigType.kt
index f849e759..c390f8d2 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/enums/EConfigType.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/enums/EConfigType.kt
@@ -15,7 +15,8 @@ enum class EConfigType(val value: Int, val protocolScheme: String) {
HYSTERIA2(9, AppConfig.HYSTERIA2),
HYSTERIA(900, AppConfig.HYSTERIA),
HTTP(10, AppConfig.HTTP),
- POLICYGROUP(101, AppConfig.CUSTOM);
+ POLICYGROUP(101, AppConfig.CUSTOM),
+ PROXYCHAIN(102, AppConfig.CUSTOM);
companion object {
fun fromInt(value: Int) = entries.firstOrNull { it.value == value }
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/AngConfigManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/AngConfigManager.kt
index dc6ad9cb..14d86326 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/AngConfigManager.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/AngConfigManager.kt
@@ -137,15 +137,12 @@ object AngConfigManager {
return config.configType.protocolScheme + when (config.configType) {
EConfigType.VMESS -> VmessFmt.toUri(config)
- EConfigType.CUSTOM -> ""
EConfigType.SHADOWSOCKS -> ShadowsocksFmt.toUri(config)
EConfigType.SOCKS -> SocksFmt.toUri(config)
- EConfigType.HTTP -> ""
EConfigType.VLESS -> VlessFmt.toUri(config)
EConfigType.TROJAN -> TrojanFmt.toUri(config)
EConfigType.WIREGUARD -> WireguardFmt.toUri(config)
EConfigType.HYSTERIA2 -> Hysteria2Fmt.toUri(config)
- EConfigType.POLICYGROUP -> ""
else -> {}
}
} catch (e: Exception) {
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/GroupServerFragment.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/GroupServerFragment.kt
index 74b70431..eaf274ae 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/GroupServerFragment.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/GroupServerFragment.kt
@@ -181,6 +181,10 @@ class GroupServerFragment : BaseFragment(),
ownerActivity.startActivity(intent.setClass(ownerActivity, ServerGroupActivity::class.java))
}
+ EConfigType.PROXYCHAIN -> {
+ ownerActivity.startActivity(intent.setClass(ownerActivity, ServerProxyChainActivity::class.java))
+ }
+
else -> {
ownerActivity.startActivity(intent.setClass(ownerActivity, ServerActivity::class.java))
}
@@ -265,7 +269,9 @@ class GroupServerFragment : BaseFragment(),
}
override fun onShare(guid: String, profile: ProfileItem, position: Int, more: Boolean) {
- val isCustom = profile.configType == EConfigType.CUSTOM || profile.configType == EConfigType.POLICYGROUP
+ val isCustom = profile.configType == EConfigType.CUSTOM
+ || profile.configType == EConfigType.POLICYGROUP
+ || profile.configType == EConfigType.PROXYCHAIN
val (shareOptions, skip) = if (more) {
val options = if (isCustom) share_method_more.asList().takeLast(3) else share_method_more.asList()
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt
index d943c527..cfb9d01d 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt
@@ -254,6 +254,11 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
true
}
+ R.id.import_manually_proxy_chain -> {
+ importManually(EConfigType.PROXYCHAIN.value)
+ true
+ }
+
R.id.import_manually_vmess -> {
importManually(EConfigType.VMESS.value)
true
@@ -356,6 +361,12 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
.putExtra("subscriptionId", mainViewModel.subscriptionId)
.setClass(this, ServerGroupActivity::class.java)
)
+ } else if (createConfigType == EConfigType.PROXYCHAIN.value) {
+ startActivity(
+ Intent()
+ .putExtra("subscriptionId", mainViewModel.subscriptionId)
+ .setClass(this, ServerProxyChainActivity::class.java)
+ )
} else {
startActivity(
Intent()
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt
index 8fae6678..b0ffdfea 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt
@@ -148,14 +148,12 @@ class ServerActivity : BaseActivity() {
val layoutId = when (config?.configType ?: createConfigType) {
EConfigType.VMESS -> R.layout.activity_server_vmess
- EConfigType.CUSTOM -> null
EConfigType.SHADOWSOCKS -> R.layout.activity_server_shadowsocks
EConfigType.SOCKS, EConfigType.HTTP -> R.layout.activity_server_socks
EConfigType.VLESS -> R.layout.activity_server_vless
EConfigType.TROJAN -> R.layout.activity_server_trojan
EConfigType.WIREGUARD -> R.layout.activity_server_wireguard
EConfigType.HYSTERIA2 -> R.layout.activity_server_hysteria2
- EConfigType.POLICYGROUP -> null
else -> null
} ?: return
setContentViewWithToolbar(layoutId, showHomeAsUp = true, title = (config?.configType ?: createConfigType).toString())
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerProxyChainActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerProxyChainActivity.kt
new file mode 100644
index 00000000..c733940b
--- /dev/null
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerProxyChainActivity.kt
@@ -0,0 +1,228 @@
+package com.v2ray.ang.ui
+
+import android.os.Bundle
+import android.text.TextUtils
+import android.view.Menu
+import android.view.MenuItem
+import androidx.appcompat.app.AlertDialog
+import androidx.recyclerview.widget.ItemTouchHelper
+import androidx.recyclerview.widget.LinearLayoutManager
+import com.v2ray.ang.AppConfig
+import com.v2ray.ang.R
+import com.v2ray.ang.contracts.BaseAdapterListener
+import com.v2ray.ang.databinding.ActivityServerProxyChainBinding
+import com.v2ray.ang.dto.ProfileItem
+import com.v2ray.ang.enums.EConfigType
+import com.v2ray.ang.extension.toast
+import com.v2ray.ang.extension.toastSuccess
+import com.v2ray.ang.helper.SimpleItemTouchHelperCallback
+import com.v2ray.ang.handler.MmkvManager
+import com.v2ray.ang.handler.SettingsManager
+import com.v2ray.ang.util.Utils
+
+class ServerProxyChainActivity : BaseActivity() {
+ private val binding by lazy { ActivityServerProxyChainBinding.inflate(layoutInflater) }
+ private val editGuid by lazy { intent.getStringExtra("guid").orEmpty() }
+ private val isRunning by lazy {
+ intent.getBooleanExtra("isRunning", false)
+ && editGuid.isNotEmpty()
+ && editGuid == MmkvManager.getSelectServer()
+ }
+ private val subscriptionId by lazy {
+ intent.getStringExtra("subscriptionId")
+ }
+ private lateinit var memberAdapter: ServerProxyChainMemberAdapter
+
+ private var allRemarks: List = emptyList()
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentViewWithToolbar(binding.root, showHomeAsUp = true, title = EConfigType.PROXYCHAIN.toString())
+
+ loadAvailableRemarks()
+ setupRecycler()
+ binding.fabAddProxyChainMember.setOnClickListener {
+ addMemberRow()
+ }
+
+ val config = MmkvManager.decodeServerConfig(editGuid)
+ if (config != null) {
+ bindingServer(config)
+ } else {
+ clearServer()
+ }
+ }
+
+ private fun loadAvailableRemarks() {
+ allRemarks = MmkvManager.decodeAllServerList()
+ .asSequence()
+ .mapNotNull { guid -> MmkvManager.decodeServerConfig(guid) }
+ .filter { profile ->
+ profile.configType != EConfigType.CUSTOM
+ && profile.configType != EConfigType.POLICYGROUP
+ && profile.configType != EConfigType.PROXYCHAIN
+ }
+ .map { it.remarks.trim() }
+ .filter { it.isNotEmpty() }
+ .distinct()
+ .toList()
+ }
+
+ private fun setupRecycler() {
+ memberAdapter = ServerProxyChainMemberAdapter(
+ members = mutableListOf(),
+ suggestions = allRemarks,
+ adapterListener = ActivityAdapterListener()
+ )
+ binding.recyclerProxyChainMembers.layoutManager = LinearLayoutManager(this)
+ binding.recyclerProxyChainMembers.adapter = memberAdapter
+ ItemTouchHelper(SimpleItemTouchHelperCallback(memberAdapter)).attachToRecyclerView(binding.recyclerProxyChainMembers)
+ }
+
+ private fun bindingServer(config: ProfileItem): Boolean {
+ binding.etRemarks.text = Utils.getEditable(config.remarks)
+ val rows = parseChainMembers(config.proxyChainProfiles)
+ memberAdapter.replaceAll(rows)
+ if (rows.isEmpty()) {
+ memberAdapter.addRow()
+ }
+ return true
+ }
+
+ private fun clearServer(): Boolean {
+ binding.etRemarks.text = null
+ memberAdapter.replaceAll(listOf("", ""))
+ return true
+ }
+
+ private fun saveServer(): Boolean {
+ if (TextUtils.isEmpty(binding.etRemarks.text.toString())) {
+ toast(R.string.server_lab_remarks)
+ return false
+ }
+
+ val chainMembers = memberAdapter.getMembers().map { it.trim() }.filter { it.isNotEmpty() }
+ if (chainMembers.size != memberAdapter.getMembers().size) {
+ toast(R.string.server_proxy_chain_members_unselected)
+ return false
+ }
+ if (chainMembers.size < 2) {
+ toast(R.string.server_proxy_chain_members_insufficient)
+ return false
+ }
+
+ val invalidMembers = chainMembers.filter { member ->
+ val profile = SettingsManager.getServerViaRemarks(member)
+ profile == null
+ || profile.configType == EConfigType.CUSTOM
+ || profile.configType == EConfigType.POLICYGROUP
+ || profile.configType == EConfigType.PROXYCHAIN
+ }
+ if (invalidMembers.isNotEmpty()) {
+ toast(getString(R.string.server_proxy_chain_members_invalid, invalidMembers.joinToString(", ")))
+ return false
+ }
+
+ val config = MmkvManager.decodeServerConfig(editGuid) ?: ProfileItem.create(EConfigType.PROXYCHAIN)
+ config.remarks = binding.etRemarks.text.toString().trim()
+ config.proxyChainProfiles = chainMembers.joinToString(",")
+ config.description = chainMembers.joinToString(" -> ")
+
+ if (config.subscriptionId.isEmpty() && !subscriptionId.isNullOrEmpty()) {
+ config.subscriptionId = subscriptionId.orEmpty()
+ }
+
+ MmkvManager.encodeServerConfig(editGuid, config)
+ toastSuccess(R.string.toast_success)
+ finish()
+ return true
+ }
+
+ private fun deleteServer(): Boolean {
+ if (editGuid.isNotEmpty()) {
+ if (editGuid != MmkvManager.getSelectServer()) {
+ if (MmkvManager.decodeSettingsBool(AppConfig.PREF_CONFIRM_REMOVE)) {
+ AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
+ .setPositiveButton(android.R.string.ok) { _, _ ->
+ MmkvManager.removeServer(editGuid)
+ finish()
+ }
+ .setNegativeButton(android.R.string.cancel) { _, _ ->
+ // do nothing
+ }
+ .show()
+ } else {
+ MmkvManager.removeServer(editGuid)
+ finish()
+ }
+ } else {
+ toast(R.string.toast_action_not_allowed)
+ }
+ }
+ return true
+ }
+
+ private fun addMemberRow() {
+ if (allRemarks.isEmpty()) {
+ toast(R.string.toast_none_data)
+ return
+ }
+ memberAdapter.addRow()
+ }
+
+ private fun parseChainMembers(raw: String?): List {
+ return raw.orEmpty()
+ .split(",")
+ .map { it.trim() }
+ .filter { it.isNotEmpty() }
+ }
+
+ private inner class ActivityAdapterListener : BaseAdapterListener {
+ override fun onEdit(guid: String, position: Int) {
+ // Row selection is handled directly by AutoCompleteTextView in the adapter.
+ }
+
+ override fun onRemove(guid: String, position: Int) {
+ memberAdapter.removeRow(position)
+ }
+
+ override fun onShare(url: String) {
+ }
+
+ override fun onRefreshData() {
+ }
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu): Boolean {
+ menuInflater.inflate(R.menu.action_server, menu)
+ val delButton = menu.findItem(R.id.del_config)
+ val saveButton = menu.findItem(R.id.save_config)
+
+ if (editGuid.isNotEmpty()) {
+ if (isRunning) {
+ delButton?.isVisible = false
+ saveButton?.isVisible = false
+ }
+ } else {
+ delButton?.isVisible = false
+ }
+
+ return super.onCreateOptionsMenu(menu)
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
+ R.id.del_config -> {
+ deleteServer()
+ true
+ }
+
+ R.id.save_config -> {
+ saveServer()
+ true
+ }
+
+ else -> super.onOptionsItemSelected(item)
+ }
+}
+
+
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerProxyChainMemberAdapter.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerProxyChainMemberAdapter.kt
new file mode 100644
index 00000000..deb2a39d
--- /dev/null
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerProxyChainMemberAdapter.kt
@@ -0,0 +1,136 @@
+package com.v2ray.ang.ui
+
+import android.graphics.Color
+import android.widget.ArrayAdapter
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.recyclerview.widget.RecyclerView
+import com.v2ray.ang.contracts.BaseAdapterListener
+import com.v2ray.ang.databinding.ItemRecyclerProxyChainMemberBinding
+import com.v2ray.ang.helper.ItemTouchHelperAdapter
+import com.v2ray.ang.helper.ItemTouchHelperViewHolder
+import java.util.Collections
+
+class ServerProxyChainMemberAdapter(
+ private val members: MutableList,
+ private val suggestions: List,
+ private val adapterListener: BaseAdapterListener?
+) : RecyclerView.Adapter(), ItemTouchHelperAdapter {
+
+ override fun getItemCount(): Int = members.size
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MemberViewHolder {
+ return MemberViewHolder(
+ ItemRecyclerProxyChainMemberBinding.inflate(
+ LayoutInflater.from(parent.context),
+ parent,
+ false
+ )
+ )
+ }
+
+ override fun onBindViewHolder(holder: MemberViewHolder, position: Int) {
+ val adapterPos = holder.bindingAdapterPosition.takeIf { it != RecyclerView.NO_POSITION } ?: position
+ val value = members[position]
+ holder.binding.tvMemberIndex.text = (position + 1).toString()
+
+ val dropdownAdapter = ArrayAdapter(
+ holder.itemView.context,
+ android.R.layout.simple_dropdown_item_1line,
+ suggestions
+ )
+ holder.binding.spMemberRemark.setAdapter(dropdownAdapter)
+ holder.binding.spMemberRemark.threshold = 0
+ holder.binding.spMemberRemark.setText(value, false)
+
+ holder.binding.spMemberRemark.setOnItemClickListener { _, _, selectedIndex, _ ->
+ if (adapterPos in members.indices) {
+ members[adapterPos] = suggestions[selectedIndex].trim()
+ adapterListener?.onRefreshData()
+ }
+ }
+ holder.binding.spMemberRemark.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
+ if (hasFocus) return@OnFocusChangeListener
+ val text = holder.binding.spMemberRemark.text?.toString().orEmpty().trim()
+ if (adapterPos in members.indices && members[adapterPos] != text) {
+ members[adapterPos] = text
+ adapterListener?.onRefreshData()
+ }
+ }
+ holder.binding.spMemberRemark.setOnClickListener { holder.binding.spMemberRemark.showDropDown() }
+ holder.binding.btnMemberDropdown.setOnClickListener {
+ holder.binding.spMemberRemark.requestFocus()
+ holder.binding.spMemberRemark.showDropDown()
+ }
+ holder.itemView.setOnClickListener { holder.binding.spMemberRemark.showDropDown() }
+
+ holder.binding.layoutRemove.setOnClickListener {
+ val removePos = holder.bindingAdapterPosition
+ if (removePos != RecyclerView.NO_POSITION) {
+ adapterListener?.onRemove("", removePos)
+ }
+ }
+ }
+
+ fun addRow() {
+ members.add("")
+ notifyItemInserted(members.lastIndex)
+ adapterListener?.onRefreshData()
+ }
+
+ fun removeRow(position: Int) {
+ if (position < 0 || position >= members.size) return
+ members.removeAt(position)
+ notifyItemRemoved(position)
+ notifyItemRangeChanged(position, members.size - position)
+ adapterListener?.onRefreshData()
+ }
+
+ fun setRemark(position: Int, remark: String) {
+ if (position < 0 || position >= members.size) return
+ members[position] = remark
+ notifyItemChanged(position)
+ adapterListener?.onRefreshData()
+ }
+
+ fun replaceAll(newMembers: List) {
+ members.clear()
+ members.addAll(newMembers)
+ notifyDataSetChanged()
+ adapterListener?.onRefreshData()
+ }
+
+ fun getMembers(): List = members.toList()
+
+ override fun onItemMove(fromPosition: Int, toPosition: Int): Boolean {
+ if (fromPosition == toPosition) return true
+ Collections.swap(members, fromPosition, toPosition)
+ notifyItemMoved(fromPosition, toPosition)
+ notifyItemChanged(fromPosition)
+ notifyItemChanged(toPosition)
+ return true
+ }
+
+ override fun onItemMoveCompleted() {
+ adapterListener?.onRefreshData()
+ }
+
+ override fun onItemDismiss(position: Int) {
+ // Swipe-to-dismiss disabled for this adapter.
+ }
+
+ class MemberViewHolder(val binding: ItemRecyclerProxyChainMemberBinding) :
+ BaseViewHolder(binding.root), ItemTouchHelperViewHolder
+
+ open class BaseViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+ fun onItemSelected() {
+ itemView.setBackgroundColor(Color.LTGRAY)
+ }
+
+ fun onItemClear() {
+ itemView.setBackgroundColor(Color.TRANSPARENT)
+ }
+ }
+}
+
diff --git a/V2rayNG/app/src/main/res/layout/activity_server_proxy_chain.xml b/V2rayNG/app/src/main/res/layout/activity_server_proxy_chain.xml
new file mode 100644
index 00000000..227d9965
--- /dev/null
+++ b/V2rayNG/app/src/main/res/layout/activity_server_proxy_chain.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/V2rayNG/app/src/main/res/layout/item_recycler_proxy_chain_member.xml b/V2rayNG/app/src/main/res/layout/item_recycler_proxy_chain_member.xml
new file mode 100644
index 00000000..9627de80
--- /dev/null
+++ b/V2rayNG/app/src/main/res/layout/item_recycler_proxy_chain_member.xml
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/V2rayNG/app/src/main/res/menu/menu_main.xml b/V2rayNG/app/src/main/res/menu/menu_main.xml
index 77ea890d..61bfb209 100644
--- a/V2rayNG/app/src/main/res/menu/menu_main.xml
+++ b/V2rayNG/app/src/main/res/menu/menu_main.xml
@@ -28,6 +28,10 @@
android:id="@+id/import_manually_policy_group"
android:title="@string/menu_item_import_config_policy_group"
app:showAsAction="never" />
+
- استيراد التكوين من الحافظة
Import config from locally
Add [Policy group]
+ Add [Proxy chain]
الكتابة يدويًا [VMess]
الكتابة يدويًا [VLESS]
الكتابة يدويًا [Shadowsocks]
@@ -376,6 +377,12 @@
Policy group type
From subscription group
Remarks regular filter
+ اعضاء سلسلة الوكيل
+ اضغط هنا لاختيار عضو
+ اختر عضوا
+ يرجى اختيار remark لكل صف في السلسلة
+ عدد الاعضاء غير كاف
+ اعضاء سلسلة غير صالحين: %1$s
Backup & Restore
diff --git a/V2rayNG/app/src/main/res/values-bn/strings.xml b/V2rayNG/app/src/main/res/values-bn/strings.xml
index 4b7103c9..c193d9d9 100644
--- a/V2rayNG/app/src/main/res/values-bn/strings.xml
+++ b/V2rayNG/app/src/main/res/values-bn/strings.xml
@@ -30,6 +30,7 @@
ক্লিপবোর্ড থেকে কনফিগারেশন আমদানি করুন
Import config from locally
Add [Policy group]
+ Add [Proxy chain]
ম্যানুয়ালি টাইপ করুন [VMess]
ম্যানুয়ালি টাইপ করুন [VLESS]
ম্যানুয়ালি টাইপ করুন [Shadowsocks]
@@ -375,6 +376,12 @@
Policy group type
From subscription group
Remarks regular filter
+ Proxy chain members
+ Tap here to pick member
+ Select a member
+ Please select member for each chain row
+ Insufficient members
+ Invalid chain members: %1$s
Backup & Restore
diff --git a/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml b/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml
index ba3cad76..0eae9cdf 100644
--- a/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml
+++ b/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml
@@ -30,6 +30,7 @@
و من ٱووردن کانفیگ ز کلیپ بورد
و من ٱووردن کانفیگ ز مهلی
ٱووردن [بونکۊ سیاست]
+ Add [Proxy chain]
هؽل دستی[VMess]
هؽل دستی[VLESS]
هؽل دستی[Shadowsocks]
@@ -375,6 +376,12 @@
نوع بونکۊ سیاست
ز بونکۊ اشتراک
توزیهات فیلتر معمۊلی
+ اعضای زنجیره پروکسی
+ اینجا بزنین تا عضو اِنتخاب اکه
+ یه عضو اِنتخاب کۊنین
+ لطفا سی هر ردیو زنجیره، remark اِنتخاب کۊنین
+ تعداد عضوها کافی نیس
+ اعضای نامعتبر زنجیره: %1$s
لادراری گرؽڌن & وورگندن
diff --git a/V2rayNG/app/src/main/res/values-fa/strings.xml b/V2rayNG/app/src/main/res/values-fa/strings.xml
index 2de37668..88170a8f 100644
--- a/V2rayNG/app/src/main/res/values-fa/strings.xml
+++ b/V2rayNG/app/src/main/res/values-fa/strings.xml
@@ -30,6 +30,7 @@
کانفیگ را از کلیپ بورد وارد کنید
کانفیگ را از محلی وارد کنید
اضافه کردن [گروه خط مشی]
+ Add [Proxy chain]
تایپ دستی[VMESS]
تایپ دستی[VLESS]
تایپ دستی[SHADOWSOCKS]
@@ -372,6 +373,12 @@
نوع گروه خط مشی
از گروه اشتراک
توضیحات فیلتر معمولی
+ اعضای زنجیره پروکسی
+ برای انتخاب عضو اینجا بزنید
+ یک عضو را انتخاب کنید
+ لطفا برای هر ردیف زنجیره remark انتخاب کنید
+ تعداد اعضا کافی نیست
+ اعضای نامعتبر زنجیره: %1$s
پشتیبانگیری و بازیابی
diff --git a/V2rayNG/app/src/main/res/values-ru/strings.xml b/V2rayNG/app/src/main/res/values-ru/strings.xml
index 9c0f106e..e8b2dc7b 100644
--- a/V2rayNG/app/src/main/res/values-ru/strings.xml
+++ b/V2rayNG/app/src/main/res/values-ru/strings.xml
@@ -30,6 +30,7 @@
Импорт из буфера обмена
Импорт из файла
Добавить группу политик
+ Add [Proxy chain]
Ручной ввод VMess
Ручной ввод VLESS
Ручной ввод Shadowsocks
@@ -378,6 +379,12 @@
Тип группы политик
Из группы подписки
Название фильтра
+ Участники цепочки прокси
+ Нажмите здесь, чтобы выбрать участника
+ Выберите участника
+ Пожалуйста, выберите участника для каждой строки цепочки
+ Недостаточно участников
+ Недопустимые участники цепочки: %1$s
Резервное копирование
diff --git a/V2rayNG/app/src/main/res/values-vi/strings.xml b/V2rayNG/app/src/main/res/values-vi/strings.xml
index 6098c3d3..5dc6caa5 100644
--- a/V2rayNG/app/src/main/res/values-vi/strings.xml
+++ b/V2rayNG/app/src/main/res/values-vi/strings.xml
@@ -30,6 +30,7 @@
Nhập cấu hình từ Clipboard
Import config from locally
Add [Policy group]
+ Add [Proxy chain]
Nhập thủ công [VMess]
Nhập thủ công [VLESS]
Nhập thủ công [ShadowSocks]
@@ -377,6 +378,12 @@
Policy group type
From subscription group
Remarks regular filter
+ Proxy chain members
+ Tap here to pick member
+ Select a member
+ Please select member for each chain row
+ Insufficient members
+ Invalid chain members: %1$s
Backup & Restore
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 3587e7e7..ce5ee7ac 100644
--- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml
+++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml
@@ -30,6 +30,7 @@
从剪贴板导入
从本地导入
添加 [策略组]
+ 添加 [链式代理]
添加 [VMess]
添加 [VLESS]
添加 [Shadowsocks]
@@ -376,6 +377,12 @@
策略组类型
来自订阅分组
别名正则过滤
+ 代理链成员
+ 点此选择成员
+ 请选择成员
+ 请为链路中的每一行选择成员
+ 成员数量不足
+ 无效的链路成员: %1$s
备份 & 还原
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 0205150c..f1227cf8 100644
--- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml
+++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml
@@ -30,6 +30,7 @@
從剪貼簿匯入設定
從本地匯入
新增 [策略組]
+ 新增 [鍊式代理]
新增 [VMess]
新增 [VLESS]
新增 [Shadowsocks]
@@ -376,6 +377,12 @@
策略群組類型
來自訂閱分組
別名正規過濾
+ 代理鏈成員
+ 點此選擇成員
+ 請選擇成員
+ 請為鏈路中的每一列選擇成員
+ 成員數量不足
+ 無效的鏈路成員: %1$s
Backup & Restore
diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml
index e70a7cae..f4b535bc 100644
--- a/V2rayNG/app/src/main/res/values/strings.xml
+++ b/V2rayNG/app/src/main/res/values/strings.xml
@@ -31,6 +31,7 @@
Import from Clipboard
Import from locally
Add [Policy group]
+ Add [Proxy chain]
Add [VMess]
Add [VLESS]
Add [Shadowsocks]
@@ -382,6 +383,13 @@
From subscription group
Remarks regular filter
+ Proxy chain members
+ Tap here to pick member
+ Select a member
+ Please select member for each chain row
+ Insufficient members
+ Invalid chain members: %1$s
+
Backup & Restore
Backup config