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 27061810..13bba449 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 @@ -24,94 +24,6 @@ import java.net.URI object AngConfigManager { - /** - * Parses the configuration from a QR code or string. - * - * @param str The configuration string. - * @param subid The subscription ID. - * @param subItem The subscription item. - * @param removedSelectedServer The removed selected server. - * @return The result code. - */ - private fun parseConfig( - str: String?, - subid: String, - subItem: SubscriptionItem?, - removedSelectedServer: ProfileItem? - ): Int { - try { - if (str == null || TextUtils.isEmpty(str)) { - return R.string.toast_none_data - } - - val config = if (str.startsWith(EConfigType.VMESS.protocolScheme)) { - VmessFmt.parse(str) - } else if (str.startsWith(EConfigType.SHADOWSOCKS.protocolScheme)) { - ShadowsocksFmt.parse(str) - } else if (str.startsWith(EConfigType.SOCKS.protocolScheme)) { - SocksFmt.parse(str) - } else if (str.startsWith(EConfigType.TROJAN.protocolScheme)) { - TrojanFmt.parse(str) - } else if (str.startsWith(EConfigType.VLESS.protocolScheme)) { - VlessFmt.parse(str) - } else if (str.startsWith(EConfigType.WIREGUARD.protocolScheme)) { - WireguardFmt.parse(str) - } else if (str.startsWith(EConfigType.HYSTERIA2.protocolScheme) || str.startsWith(HY2)) { - Hysteria2Fmt.parse(str) - } else { - null - } - - if (config == null) { - return R.string.toast_incorrect_protocol - } - //filter - if (subItem?.filter != null && subItem.filter?.isNotEmpty() == true && config.remarks.isNotEmpty()) { - val matched = Regex(pattern = subItem.filter ?: "") - .containsMatchIn(input = config.remarks) - if (!matched) return -1 - } - - config.subscriptionId = subid - val guid = MmkvManager.encodeServerConfig("", config) - if (removedSelectedServer != null && - config.server == removedSelectedServer.server && config.serverPort == removedSelectedServer.serverPort - ) { - MmkvManager.setSelectServer(guid) - } - } catch (e: Exception) { - e.printStackTrace() - return -1 - } - return 0 - } - - /** - * Shares the configuration. - * - * @param guid The GUID of the configuration. - * @return The configuration string. - */ - private fun shareConfig(guid: String): String { - try { - val config = MmkvManager.decodeServerConfig(guid) ?: return "" - - 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) - } - } catch (e: Exception) { - e.printStackTrace() - return "" - } - } /** * Shares the configuration to the clipboard. @@ -214,6 +126,33 @@ object AngConfigManager { return 0 } + /** + * Shares the configuration. + * + * @param guid The GUID of the configuration. + * @return The configuration string. + */ + private fun shareConfig(guid: String): String { + try { + val config = MmkvManager.decodeServerConfig(guid) ?: return "" + + 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) + } + } catch (e: Exception) { + e.printStackTrace() + return "" + } + } + /** * Imports a batch of configurations. * @@ -248,7 +187,7 @@ object AngConfigManager { * @param servers The servers string. * @return The number of subscriptions parsed. */ - fun parseBatchSubscription(servers: String?): Int { + private fun parseBatchSubscription(servers: String?): Int { try { if (servers == null) { return 0 @@ -277,7 +216,7 @@ object AngConfigManager { * @param append Whether to append the configurations. * @return The number of configurations parsed. */ - fun parseBatchConfig(servers: String?, subid: String, append: Boolean): Int { + private fun parseBatchConfig(servers: String?, subid: String, append: Boolean): Int { try { if (servers == null) { return 0 @@ -324,7 +263,7 @@ object AngConfigManager { * @param subid The subscription ID. * @return The number of configurations parsed. */ - fun parseCustomConfigServer(server: String?, subid: String): Int { + private fun parseCustomConfigServer(server: String?, subid: String): Int { if (server == null) { return 0 } @@ -377,6 +316,68 @@ object AngConfigManager { } } + /** + * Parses the configuration from a QR code or string. + * + * @param str The configuration string. + * @param subid The subscription ID. + * @param subItem The subscription item. + * @param removedSelectedServer The removed selected server. + * @return The result code. + */ + private fun parseConfig( + str: String?, + subid: String, + subItem: SubscriptionItem?, + removedSelectedServer: ProfileItem? + ): Int { + try { + if (str == null || TextUtils.isEmpty(str)) { + return R.string.toast_none_data + } + + val config = if (str.startsWith(EConfigType.VMESS.protocolScheme)) { + VmessFmt.parse(str) + } else if (str.startsWith(EConfigType.SHADOWSOCKS.protocolScheme)) { + ShadowsocksFmt.parse(str) + } else if (str.startsWith(EConfigType.SOCKS.protocolScheme)) { + SocksFmt.parse(str) + } else if (str.startsWith(EConfigType.TROJAN.protocolScheme)) { + TrojanFmt.parse(str) + } else if (str.startsWith(EConfigType.VLESS.protocolScheme)) { + VlessFmt.parse(str) + } else if (str.startsWith(EConfigType.WIREGUARD.protocolScheme)) { + WireguardFmt.parse(str) + } else if (str.startsWith(EConfigType.HYSTERIA2.protocolScheme) || str.startsWith(HY2)) { + Hysteria2Fmt.parse(str) + } else { + null + } + + if (config == null) { + return R.string.toast_incorrect_protocol + } + //filter + if (subItem?.filter != null && subItem.filter?.isNotEmpty() == true && config.remarks.isNotEmpty()) { + val matched = Regex(pattern = subItem.filter ?: "") + .containsMatchIn(input = config.remarks) + if (!matched) return -1 + } + + config.subscriptionId = subid + val guid = MmkvManager.encodeServerConfig("", config) + if (removedSelectedServer != null && + config.server == removedSelectedServer.server && config.serverPort == removedSelectedServer.serverPort + ) { + MmkvManager.setSelectServer(guid) + } + } catch (e: Exception) { + e.printStackTrace() + return -1 + } + return 0 + } + /** * Updates the configuration via all subscriptions. * diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/V2rayConfigManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/V2rayConfigManager.kt index e0af5755..edbf8811 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/V2rayConfigManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/V2rayConfigManager.kt @@ -97,7 +97,6 @@ object V2rayConfigManager { } } - //取得默认配置 val assets = Utils.readTextFromAssets(context, "v2ray_config.json") if (TextUtils.isEmpty(assets)) { return result @@ -284,7 +283,7 @@ object V2rayConfigManager { ) } - // DNS inbound对象 + // DNS inbound val remoteDns = SettingsManager.getRemoteDnsServers() if (v2rayConfig.inbounds.none { e -> e.protocol == "dokodemo-door" && e.tag == "dns-in" }) { val dnsInboundSettings = V2rayConfig.InboundBean.InSettingsBean( @@ -309,7 +308,7 @@ object V2rayConfigManager { ) } - // DNS outbound对象 + // DNS outbound if (v2rayConfig.outbounds.none { e -> e.protocol == "dns" && e.tag == "dns-out" }) { v2rayConfig.outbounds.add( V2rayConfig.OutboundBean( @@ -416,7 +415,7 @@ object V2rayConfigManager { hosts[DNS_YANDEX_DOMAIN] = DNS_YANDEX_ADDRESSES - // DNS dns对象 + // DNS dns v2rayConfig.dns = V2rayConfig.DnsBean( servers = servers, hosts = hosts diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayTestService.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayTestService.kt index 8bdbc6d1..193489ba 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayTestService.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayTestService.kt @@ -9,10 +9,10 @@ import com.v2ray.ang.AppConfig.MSG_MEASURE_CONFIG_SUCCESS import com.v2ray.ang.dto.EConfigType import com.v2ray.ang.extension.serializable import com.v2ray.ang.handler.MmkvManager +import com.v2ray.ang.handler.SpeedtestManager import com.v2ray.ang.handler.V2rayConfigManager import com.v2ray.ang.util.MessageUtil import com.v2ray.ang.util.PluginUtil -import com.v2ray.ang.handler.SpeedtestManager import com.v2ray.ang.util.Utils import go.Seq import kotlinx.coroutines.CoroutineScope diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainRecyclerAdapter.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainRecyclerAdapter.kt index f1b2cb82..05036b2d 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainRecyclerAdapter.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainRecyclerAdapter.kt @@ -83,7 +83,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter