https://github.com/2dust/v2rayNG/issues/3168
This commit is contained in:
2dust
2024-05-29 17:41:58 +08:00
parent 2ddbe38781
commit 2d803e009c
3 changed files with 27 additions and 14 deletions

View File

@@ -495,7 +495,7 @@ data class V2rayConfig(
var poolSize: Int = 10000) // roughly 10 times smaller than total ip pool var poolSize: Int = 10000) // roughly 10 times smaller than total ip pool
fun getProxyOutbound(): OutboundBean? { fun getProxyOutbound(): OutboundBean? {
outbounds.forEach { outbound -> outbounds?.forEach { outbound ->
EConfigType.entries.forEach { EConfigType.entries.forEach {
if (outbound.protocol.equals(it.name, true)) { if (outbound.protocol.equals(it.name, true)) {
return outbound return outbound

View File

@@ -629,16 +629,18 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
toast(R.string.toast_none_data) toast(R.string.toast_none_data)
return return
} }
mainViewModel.appendCustomConfigServer(server) if (mainViewModel.appendCustomConfigServer(server)) {
mainViewModel.reloadServerList() mainViewModel.reloadServerList()
toast(R.string.toast_success) toast(R.string.toast_success)
} else {
toast(R.string.toast_failure)
}
//adapter.notifyItemInserted(mainViewModel.serverList.lastIndex) //adapter.notifyItemInserted(mainViewModel.serverList.lastIndex)
} catch (e: Exception) { } catch (e: Exception) {
ToastCompat.makeText(this, "${getString(R.string.toast_malformed_josn)} ${e.cause?.message}", Toast.LENGTH_LONG).show() ToastCompat.makeText(this, "${getString(R.string.toast_malformed_josn)} ${e.cause?.message}", Toast.LENGTH_LONG).show()
e.printStackTrace() e.printStackTrace()
return return
} }
}
fun setTestState(content: String?) { fun setTestState(content: String?) {
binding.tvTestState.text = content binding.tvTestState.text = content

View File

@@ -110,15 +110,26 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
} }
} }
fun appendCustomConfigServer(server: String) { fun appendCustomConfigServer(server: String): Boolean {
val config = ServerConfig.create(EConfigType.CUSTOM) if (server.contains("inbounds")
config.subscriptionId = subscriptionId && server.contains("outbounds")
config.fullConfig = Gson().fromJson(server, V2rayConfig::class.java) && server.contains("routing")
config.remarks = config.fullConfig?.remarks ?: System.currentTimeMillis().toString() ) {
val key = MmkvManager.encodeServerConfig("", config) try {
serverRawStorage?.encode(key, server) val config = ServerConfig.create(EConfigType.CUSTOM)
serverList.add(0, key) config.subscriptionId = subscriptionId
serversCache.add(0, ServersCache(key, config)) config.fullConfig = Gson().fromJson(server, V2rayConfig::class.java)
config.remarks = config.fullConfig?.remarks ?: System.currentTimeMillis().toString()
val key = MmkvManager.encodeServerConfig("", config)
serverRawStorage?.encode(key, server)
serverList.add(0, key)
serversCache.add(0, ServersCache(key, config))
return true
} catch (e: Exception) {
e.printStackTrace()
}
}
return false
} }
fun swapServer(fromPosition: Int, toPosition: Int) { fun swapServer(fromPosition: Int, toPosition: Int) {