mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor Context.isOnline()
This commit is contained in:
parent
05d5e89c58
commit
a99dac2b23
1 changed files with 7 additions and 13 deletions
|
@ -487,10 +487,6 @@ fun Context.appDelegateNightMode(): Int {
|
|||
}
|
||||
|
||||
fun Context.isOnline(): Boolean {
|
||||
val connectivityManager = this
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
|
||||
var result = false
|
||||
connectivityManager?.let {
|
||||
val networkCapabilities = connectivityManager.activeNetwork ?: return false
|
||||
val actNw = connectivityManager.getNetworkCapabilities(networkCapabilities) ?: return false
|
||||
val maxTransport = when {
|
||||
|
@ -498,9 +494,7 @@ fun Context.isOnline(): Boolean {
|
|||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> NetworkCapabilities.TRANSPORT_WIFI_AWARE
|
||||
else -> NetworkCapabilities.TRANSPORT_VPN
|
||||
}
|
||||
result = (NetworkCapabilities.TRANSPORT_CELLULAR..maxTransport).any(actNw::hasTransport)
|
||||
}
|
||||
return result
|
||||
return (NetworkCapabilities.TRANSPORT_CELLULAR..maxTransport).any(actNw::hasTransport)
|
||||
}
|
||||
|
||||
fun Context.createFileInCacheDir(name: String): File {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue