Skip to content

Commit 2dd8750

Browse files
authored
Merge pull request #201 from Sparsh1212/refactor_null_checks_network
refactor #198: convert null checks in Network.kt to kotlin style
2 parents 1766684 + 35198f4 commit 2dd8750

File tree

1 file changed

+7
-7
lines changed
  • app/src/main/kotlin/org/mifos/mobile/cn/ui/utils

1 file changed

+7
-7
lines changed

app/src/main/kotlin/org/mifos/mobile/cn/ui/utils/Network.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object Network {
2525
*/
2626
fun isConnected(context: Context): Boolean {
2727
val info = Network.getNetworkInfo(context)
28-
return info != null && info.isConnected
28+
return info ?. isConnected ?: false
2929
}
3030

3131
/**
@@ -37,8 +37,8 @@ object Network {
3737
*/
3838
fun isConnectedWifi(context: Context): Boolean {
3939
val info = Network.getNetworkInfo(context)
40-
return info != null && info.isConnected &&
41-
info.type == ConnectivityManager.TYPE_WIFI
40+
return info ?. isConnected ?: false &&
41+
info ?. type == ConnectivityManager.TYPE_WIFI
4242
}
4343

4444
/**
@@ -50,8 +50,8 @@ object Network {
5050
*/
5151
fun isConnectedMobile(context: Context): Boolean {
5252
val info = Network.getNetworkInfo(context)
53-
return info != null && info.isConnected &&
54-
info.type == ConnectivityManager.TYPE_MOBILE
53+
return info ?. isConnected ?: false &&
54+
info ?. type == ConnectivityManager.TYPE_MOBILE
5555
}
5656

5757
/**
@@ -62,8 +62,8 @@ object Network {
6262
*/
6363
fun isConnectedFast(context: Context): Boolean {
6464
val info = Network.getNetworkInfo(context)
65-
return info != null && info.isConnected &&
66-
Network.isConnectionFast(info.type, info.subtype)
65+
return info ?. isConnected ?: false &&
66+
Network.isConnectionFast(info !!. type, info.subtype)
6767
}
6868

6969
/**

0 commit comments

Comments
 (0)