@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user