Optimized code
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package com.v2ray.ang.dto
|
||||
|
||||
data class AngConfig(
|
||||
var index: Int,
|
||||
var vmess: ArrayList<VmessBean>,
|
||||
var subItem: ArrayList<SubItemBean>
|
||||
) {
|
||||
data class VmessBean(var guid: String = "123456",
|
||||
var address: String = "v2ray.cool",
|
||||
var port: Int = 10086,
|
||||
var id: String = "a3482e88-686a-4a58-8126-99c9df64b7bf",
|
||||
var alterId: Int = 64,
|
||||
var security: String = "aes-128-cfb",
|
||||
var network: String = "tcp",
|
||||
var remarks: String = "def",
|
||||
var headerType: String = "",
|
||||
var requestHost: String = "",
|
||||
var path: String = "",
|
||||
var streamSecurity: String = "",
|
||||
var allowInsecure: String = "",
|
||||
var configType: Int = 1,
|
||||
var configVersion: Int = 1,
|
||||
var testResult: String = "",
|
||||
var subid: String = "",
|
||||
var flow: String = "",
|
||||
var sni: String = "")
|
||||
|
||||
data class SubItemBean(var id: String = "",
|
||||
var remarks: String = "",
|
||||
var url: String = "",
|
||||
var enabled: Boolean = true)
|
||||
}
|
||||
@@ -157,7 +157,7 @@ data class V2rayConfig(
|
||||
var headers: HeadersBean = HeadersBean(),
|
||||
val version: String? = null,
|
||||
val method: String? = null) {
|
||||
data class HeadersBean(var Host: List<String> = ArrayList(),
|
||||
data class HeadersBean(var Host: List<String>? = ArrayList(),
|
||||
@SerializedName("User-Agent")
|
||||
val userAgent: List<String>? = null,
|
||||
@SerializedName("Accept-Encoding")
|
||||
@@ -247,7 +247,7 @@ data class V2rayConfig(
|
||||
requestObj.headers.Host = (host ?: "").split(",").map { it.trim() }.filter { it.isNotEmpty() }
|
||||
requestObj.path = (path ?: "").split(",").map { it.trim() }.filter { it.isNotEmpty() }
|
||||
tcpSetting.header.request = requestObj
|
||||
sni = requestObj.headers.Host.getOrNull(0) ?: sni
|
||||
sni = requestObj.headers.Host?.getOrNull(0) ?: sni
|
||||
}
|
||||
} else {
|
||||
tcpSetting.header.type = "none"
|
||||
|
||||
@@ -71,7 +71,7 @@ object SubscriptionUpdater {
|
||||
|
||||
val count = AngConfigManager.importBatchConfig(server, subid, append)
|
||||
if (count <= 0) {
|
||||
AngConfigManager.importBatchConfig(Utils.decode(server!!), subid, append)
|
||||
AngConfigManager.importBatchConfig(Utils.decode(server), subid, append)
|
||||
}
|
||||
if (count <= 0) {
|
||||
AngConfigManager.appendCustomConfigServer(server, subid)
|
||||
|
||||
@@ -162,7 +162,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter<Mai
|
||||
if (guid != selected) {
|
||||
mainStorage?.encode(MmkvManager.KEY_SELECTED_SERVER, guid)
|
||||
if (!TextUtils.isEmpty(selected)) {
|
||||
notifyItemChanged(mActivity.mainViewModel.getPosition(selected!!))
|
||||
notifyItemChanged(mActivity.mainViewModel.getPosition(selected?:""))
|
||||
}
|
||||
notifyItemChanged(mActivity.mainViewModel.getPosition(guid))
|
||||
if (isRunning) {
|
||||
|
||||
@@ -193,7 +193,7 @@ class PerAppProxyActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
filterProxyApp(newText!!)
|
||||
filterProxyApp(newText?:"")
|
||||
return false
|
||||
}
|
||||
})
|
||||
@@ -209,12 +209,12 @@ class PerAppProxyActivity : BaseActivity() {
|
||||
if (it.blacklist.containsAll(pkgNames)) {
|
||||
it.apps.forEach {
|
||||
val packageName = it.packageName
|
||||
adapter?.blacklist!!.remove(packageName)
|
||||
adapter?.blacklist?.remove(packageName)
|
||||
}
|
||||
} else {
|
||||
it.apps.forEach {
|
||||
val packageName = it.packageName
|
||||
adapter?.blacklist!!.add(packageName)
|
||||
adapter?.blacklist?.add(packageName)
|
||||
}
|
||||
}
|
||||
it.notifyDataSetChanged()
|
||||
@@ -278,7 +278,7 @@ class PerAppProxyActivity : BaseActivity() {
|
||||
return false
|
||||
}
|
||||
|
||||
adapter?.blacklist!!.clear()
|
||||
adapter?.blacklist?.clear()
|
||||
|
||||
if (binding.switchBypassApps.isChecked) {
|
||||
adapter?.let {
|
||||
@@ -286,7 +286,7 @@ class PerAppProxyActivity : BaseActivity() {
|
||||
val packageName = it.packageName
|
||||
Log.d(ANG_PACKAGE, packageName)
|
||||
if (!inProxyApps(proxyApps, packageName, force)) {
|
||||
adapter?.blacklist!!.add(packageName)
|
||||
adapter?.blacklist?.add(packageName)
|
||||
println(packageName)
|
||||
return@block
|
||||
}
|
||||
@@ -299,7 +299,7 @@ class PerAppProxyActivity : BaseActivity() {
|
||||
val packageName = it.packageName
|
||||
Log.d(ANG_PACKAGE, packageName)
|
||||
if (inProxyApps(proxyApps, packageName, force)) {
|
||||
adapter?.blacklist!!.add(packageName)
|
||||
adapter?.blacklist?.add(packageName)
|
||||
println(packageName)
|
||||
return@block
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class RoutingSettingsFragment : Fragment() {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val content = settingsStorage?.getString(requireArguments().getString(routing_arg), "")
|
||||
binding.etRoutingContent.text = Utils.getEditable(content!!)
|
||||
binding.etRoutingContent.text = Utils.getEditable(content)
|
||||
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ class RoutingSettingsFragment : Fragment() {
|
||||
private val scanQRCodeForReplace = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if (it.resultCode == RESULT_OK) {
|
||||
val content = it.data?.getStringExtra("SCAN_RESULT")
|
||||
binding.etRoutingContent.text = Utils.getEditable(content!!)
|
||||
binding.etRoutingContent.text = Utils.getEditable(content)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class RoutingSettingsFragment : Fragment() {
|
||||
val content = Utils.getUrlContext(url, 5000)
|
||||
launch(Dispatchers.Main) {
|
||||
val routingList = if (TextUtils.isEmpty(content)) {
|
||||
Utils.readTextFromAssets(activity?.v2RayApplication!!, "custom_routing_$tag")
|
||||
Utils.readTextFromAssets(activity?.v2RayApplication, "custom_routing_$tag")
|
||||
} else {
|
||||
content
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class ScannerActivity : BaseActivity(){
|
||||
|
||||
private fun handleResult(result: QRResult) {
|
||||
if (result is QRResult.QRSuccess ) {
|
||||
finished(result.content.rawValue!!)
|
||||
finished(result.content.rawValue?:"")
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
@@ -110,7 +110,7 @@ class ScannerActivity : BaseActivity(){
|
||||
try {
|
||||
val bitmap = BitmapFactory.decodeStream(contentResolver.openInputStream(uri))
|
||||
val text = QRCodeDecoder.syncDecodeQRCode(bitmap)
|
||||
finished(text!!)
|
||||
finished(text?:"")
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
toast(e.message.toString())
|
||||
|
||||
@@ -5,10 +5,14 @@ import android.text.TextUtils
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Spinner
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.tencent.mmkv.MMKV
|
||||
import com.v2ray.ang.AngApplication
|
||||
import com.v2ray.ang.AppConfig
|
||||
import com.v2ray.ang.AppConfig.PREF_ALLOW_INSECURE
|
||||
import com.v2ray.ang.AppConfig.WIREGUARD_LOCAL_ADDRESS_V4
|
||||
@@ -286,7 +290,7 @@ class ServerActivity : BaseActivity() {
|
||||
tlsSetting.alpn?.let {
|
||||
val alpnIndex = Utils.arrayFind(
|
||||
alpns,
|
||||
Utils.removeWhiteSpace(tlsSetting.alpn.joinToString())!!
|
||||
Utils.removeWhiteSpace(tlsSetting.alpn.joinToString())?:""
|
||||
)
|
||||
sp_stream_alpn?.setSelection(alpnIndex)
|
||||
}
|
||||
@@ -414,7 +418,7 @@ class ServerActivity : BaseActivity() {
|
||||
saveStreamSettings(it)
|
||||
}
|
||||
if (config.subscriptionId.isEmpty() && !subscriptionId.isNullOrEmpty()) {
|
||||
config.subscriptionId = subscriptionId!!
|
||||
config.subscriptionId = subscriptionId?:""
|
||||
}
|
||||
|
||||
MmkvManager.encodeServerConfig(editGuid, config)
|
||||
|
||||
@@ -44,7 +44,7 @@ class TaskerActivity : BaseActivity() {
|
||||
val adapter = ArrayAdapter(this,
|
||||
android.R.layout.simple_list_item_single_choice, lstData)
|
||||
listview = findViewById<View>(R.id.listview) as ListView
|
||||
listview!!.adapter = adapter
|
||||
listview?.adapter = adapter
|
||||
|
||||
init()
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ object Utils {
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
fun getEditable(text: String): Editable {
|
||||
return Editable.Factory.getInstance().newEditable(text)
|
||||
fun getEditable(text: String?): Editable {
|
||||
return Editable.Factory.getInstance().newEditable(text?:"")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,16 +101,16 @@ object Utils {
|
||||
/**
|
||||
* base64 decode
|
||||
*/
|
||||
fun decode(text: String): String {
|
||||
fun decode(text: String?): String {
|
||||
tryDecodeBase64(text)?.let { return it }
|
||||
if (text.endsWith('=')) {
|
||||
if (text?.endsWith('=')==true) {
|
||||
// try again for some loosely formatted base64
|
||||
tryDecodeBase64(text.trimEnd('='))?.let { return it }
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
fun tryDecodeBase64(text: String): String? {
|
||||
fun tryDecodeBase64(text: String?): String? {
|
||||
try {
|
||||
return Base64.decode(text, Base64.NO_WRAP).toString(charset("UTF-8"))
|
||||
} catch (e: Exception) {
|
||||
@@ -302,7 +302,11 @@ object Utils {
|
||||
/**
|
||||
* readTextFromAssets
|
||||
*/
|
||||
fun readTextFromAssets(context: Context, fileName: String): String {
|
||||
fun readTextFromAssets(context: Context?, fileName: String): String {
|
||||
if(context == null)
|
||||
{
|
||||
return ""
|
||||
}
|
||||
val content = context.assets.open(fileName).bufferedReader().use {
|
||||
it.readText()
|
||||
}
|
||||
@@ -389,7 +393,10 @@ object Utils {
|
||||
}
|
||||
}
|
||||
|
||||
fun getIpv6Address(address: String): String {
|
||||
fun getIpv6Address(address: String?): String {
|
||||
if(address == null){
|
||||
return ""
|
||||
}
|
||||
return if (isIpv6Address(address) && !address.contains('[') && !address.contains(']')) {
|
||||
String.format("[%s]", address)
|
||||
} else {
|
||||
|
||||
@@ -295,10 +295,10 @@ object V2rayConfigUtil {
|
||||
rulesDomain.domain?.add(it)
|
||||
}
|
||||
}
|
||||
if (rulesDomain.domain?.size!! > 0) {
|
||||
if ((rulesDomain.domain?.size ?: 0) > 0) {
|
||||
v2rayConfig.routing.rules.add(rulesDomain)
|
||||
}
|
||||
if (rulesIP.ip?.size!! > 0) {
|
||||
if ((rulesIP.ip?.size ?: 0) > 0) {
|
||||
v2rayConfig.routing.rules.add(rulesIP)
|
||||
}
|
||||
}
|
||||
@@ -560,7 +560,7 @@ object V2rayConfigUtil {
|
||||
} else {
|
||||
path
|
||||
}
|
||||
outbound.streamSettings?.tcpSettings?.header?.request?.headers?.Host = host!!
|
||||
outbound.streamSettings?.tcpSettings?.header?.request?.headers?.Host = host
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ object ShadowsocksFmt {
|
||||
val url = String.format(
|
||||
"%s@%s:%s",
|
||||
pw,
|
||||
Utils.getIpv6Address(outbound.getServerAddress()!!),
|
||||
Utils.getIpv6Address(outbound.getServerAddress()),
|
||||
outbound.getServerPort()
|
||||
)
|
||||
return url + remark
|
||||
|
||||
@@ -61,7 +61,7 @@ object SocksFmt {
|
||||
val url = String.format(
|
||||
"%s@%s:%s",
|
||||
Utils.encode(pw),
|
||||
Utils.getIpv6Address(outbound.getServerAddress()!!),
|
||||
Utils.getIpv6Address(outbound.getServerAddress()),
|
||||
outbound.getServerPort()
|
||||
)
|
||||
return url + remark
|
||||
|
||||
@@ -52,7 +52,7 @@ object TrojanFmt {
|
||||
fingerprint = queryParam["fp"] ?: ""
|
||||
config.outboundBean?.streamSettings?.populateTlsSettings(
|
||||
queryParam["security"] ?: V2rayConfig.TLS,
|
||||
allowInsecure, queryParam["sni"] ?: sni!!, fingerprint, queryParam["alpn"],
|
||||
allowInsecure, queryParam["sni"] ?: sni?:"", fingerprint, queryParam["alpn"],
|
||||
null, null, null
|
||||
)
|
||||
flow = queryParam["flow"] ?: ""
|
||||
@@ -92,16 +92,16 @@ object TrojanFmt {
|
||||
Utils.removeWhiteSpace(tlsSetting.alpn.joinToString()).orEmpty()
|
||||
}
|
||||
if (!TextUtils.isEmpty(tlsSetting.fingerprint)) {
|
||||
dicQuery["fp"] = tlsSetting.fingerprint!!
|
||||
dicQuery["fp"] = tlsSetting.fingerprint?:""
|
||||
}
|
||||
if (!TextUtils.isEmpty(tlsSetting.publicKey)) {
|
||||
dicQuery["pbk"] = tlsSetting.publicKey!!
|
||||
dicQuery["pbk"] = tlsSetting.publicKey?:""
|
||||
}
|
||||
if (!TextUtils.isEmpty(tlsSetting.shortId)) {
|
||||
dicQuery["sid"] = tlsSetting.shortId!!
|
||||
dicQuery["sid"] = tlsSetting.shortId?:""
|
||||
}
|
||||
if (!TextUtils.isEmpty(tlsSetting.spiderX)) {
|
||||
dicQuery["spx"] = Utils.urlEncode(tlsSetting.spiderX!!)
|
||||
dicQuery["spx"] = Utils.urlEncode(tlsSetting.spiderX?:"")
|
||||
}
|
||||
}
|
||||
dicQuery["type"] =
|
||||
@@ -162,7 +162,7 @@ object TrojanFmt {
|
||||
val url = String.format(
|
||||
"%s@%s:%s",
|
||||
outbound.getPassword(),
|
||||
Utils.getIpv6Address(outbound.getServerAddress()!!),
|
||||
Utils.getIpv6Address(outbound.getServerAddress()),
|
||||
outbound.getServerPort()
|
||||
)
|
||||
return url + query + remark
|
||||
|
||||
@@ -92,16 +92,16 @@ object VlessFmt {
|
||||
Utils.removeWhiteSpace(tlsSetting.alpn.joinToString()).orEmpty()
|
||||
}
|
||||
if (!TextUtils.isEmpty(tlsSetting.fingerprint)) {
|
||||
dicQuery["fp"] = tlsSetting.fingerprint!!
|
||||
dicQuery["fp"] = tlsSetting.fingerprint?:""
|
||||
}
|
||||
if (!TextUtils.isEmpty(tlsSetting.publicKey)) {
|
||||
dicQuery["pbk"] = tlsSetting.publicKey!!
|
||||
dicQuery["pbk"] = tlsSetting.publicKey?:""
|
||||
}
|
||||
if (!TextUtils.isEmpty(tlsSetting.shortId)) {
|
||||
dicQuery["sid"] = tlsSetting.shortId!!
|
||||
dicQuery["sid"] = tlsSetting.shortId?:""
|
||||
}
|
||||
if (!TextUtils.isEmpty(tlsSetting.spiderX)) {
|
||||
dicQuery["spx"] = Utils.urlEncode(tlsSetting.spiderX!!)
|
||||
dicQuery["spx"] = Utils.urlEncode(tlsSetting.spiderX?:"")
|
||||
}
|
||||
}
|
||||
dicQuery["type"] =
|
||||
@@ -162,7 +162,7 @@ object VlessFmt {
|
||||
val url = String.format(
|
||||
"%s@%s:%s",
|
||||
outbound.getPassword(),
|
||||
Utils.getIpv6Address(outbound.getServerAddress()!!),
|
||||
Utils.getIpv6Address(outbound.getServerAddress()),
|
||||
outbound.getServerPort()
|
||||
)
|
||||
return url + query + remark
|
||||
|
||||
@@ -63,7 +63,7 @@ object WireguardFmt {
|
||||
val url = String.format(
|
||||
"%s@%s:%s",
|
||||
Utils.urlEncode(outbound.getPassword().toString()),
|
||||
Utils.getIpv6Address(outbound.getServerAddress()!!),
|
||||
Utils.getIpv6Address(outbound.getServerAddress()),
|
||||
outbound.getServerPort()
|
||||
)
|
||||
return url + query + remark
|
||||
|
||||
@@ -60,8 +60,8 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
|
||||
var serverList = MmkvManager.decodeServerList()
|
||||
var subscriptionId: String = settingsStorage.decodeString(AppConfig.CACHE_SUBSCRIPTION_ID, "")!!
|
||||
var keywordFilter: String = settingsStorage.decodeString(AppConfig.CACHE_KEYWORD_FILTER, "")!!
|
||||
var subscriptionId: String = settingsStorage.decodeString(AppConfig.CACHE_SUBSCRIPTION_ID, "")?:""
|
||||
var keywordFilter: String = settingsStorage.decodeString(AppConfig.CACHE_KEYWORD_FILTER, "")?:""
|
||||
private set
|
||||
val serversCache = mutableListOf<ServersCache>()
|
||||
val isRunning by lazy { MutableLiveData<Boolean>() }
|
||||
|
||||
@@ -83,7 +83,7 @@ class SubViewModel(application: Application) : AndroidViewModel(application) {
|
||||
fun importBatchConfig(server: String?, subid: String = "", append: Boolean): Int {
|
||||
var count = AngConfigManager.importBatchConfig(server, subid, append)
|
||||
if (count <= 0) {
|
||||
count = AngConfigManager.importBatchConfig(Utils.decode(server!!), subid, append)
|
||||
count = AngConfigManager.importBatchConfig(Utils.decode(server), subid, append)
|
||||
}
|
||||
if (count <= 0) {
|
||||
count = AngConfigManager.appendCustomConfigServer(server, subid)
|
||||
|
||||
Reference in New Issue
Block a user