Skip to content

Commit

Permalink
Removed internet check (#3494)
Browse files Browse the repository at this point in the history
Removed the internet connection check before connecting as per the request in issue #3486
  • Loading branch information
CodeWithTamim committed Aug 17, 2024
1 parent fee0a01 commit f646eff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
18 changes: 1 addition & 17 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/extension/_Ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,4 @@ val URLConnection.responseLength: Long
val URI.idnHost: String
get() = host?.replace("[", "")?.replace("]", "").orEmpty()

fun String.removeWhiteSpace(): String = replace("\\s+".toRegex(), "")

val Context.isNetworkConnected: Boolean
get() {
val manager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
manager.getNetworkCapabilities(manager.activeNetwork)?.let {
it.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) ||
it.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) ||
it.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH) ||
it.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) ||
it.hasTransport(NetworkCapabilities.TRANSPORT_VPN)
} ?: false
else
@Suppress("DEPRECATION")
manager.activeNetworkInfo?.isConnectedOrConnecting == true
}
fun String.removeWhiteSpace(): String = replace("\\s+".toRegex(), "")
10 changes: 3 additions & 7 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,10 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
}

fun startV2Ray() {
if (isNetworkConnected) {
if (MmkvManager.mainStorage?.decodeString(MmkvManager.KEY_SELECTED_SERVER).isNullOrEmpty()) {
return
}
V2RayServiceManager.startV2Ray(this)
} else {
ToastCompat.makeText(this, getString(R.string.connection_test_fail), Toast.LENGTH_LONG).show()
if (MmkvManager.mainStorage?.decodeString(MmkvManager.KEY_SELECTED_SERVER).isNullOrEmpty()) {
return
}
V2RayServiceManager.startV2Ray(this)
}

fun restartV2Ray() {
Expand Down

0 comments on commit f646eff

Please sign in to comment.