Skip to content

Commit

Permalink
Merge pull request openMF#201 from Sparsh1212/refactor_null_checks_ne…
Browse files Browse the repository at this point in the history
…twork

refactor openMF#198: convert null checks in Network.kt to kotlin style
  • Loading branch information
Garvit Agarwal authored Dec 9, 2020
2 parents 1766684 + 35198f4 commit 2dd8750
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/src/main/kotlin/org/mifos/mobile/cn/ui/utils/Network.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Network {
*/
fun isConnected(context: Context): Boolean {
val info = Network.getNetworkInfo(context)
return info != null && info.isConnected
return info ?. isConnected ?: false
}

/**
Expand All @@ -37,8 +37,8 @@ object Network {
*/
fun isConnectedWifi(context: Context): Boolean {
val info = Network.getNetworkInfo(context)
return info != null && info.isConnected &&
info.type == ConnectivityManager.TYPE_WIFI
return info ?. isConnected ?: false &&
info ?. type == ConnectivityManager.TYPE_WIFI
}

/**
Expand All @@ -50,8 +50,8 @@ object Network {
*/
fun isConnectedMobile(context: Context): Boolean {
val info = Network.getNetworkInfo(context)
return info != null && info.isConnected &&
info.type == ConnectivityManager.TYPE_MOBILE
return info ?. isConnected ?: false &&
info ?. type == ConnectivityManager.TYPE_MOBILE
}

/**
Expand All @@ -62,8 +62,8 @@ object Network {
*/
fun isConnectedFast(context: Context): Boolean {
val info = Network.getNetworkInfo(context)
return info != null && info.isConnected &&
Network.isConnectionFast(info.type, info.subtype)
return info ?. isConnected ?: false &&
Network.isConnectionFast(info !!. type, info.subtype)
}

/**
Expand Down

0 comments on commit 2dd8750

Please sign in to comment.