PageViewModel: clearer message if no connection
This commit is contained in:
parent
bf28d30e4c
commit
afd0b42c83
|
@ -2,6 +2,7 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="dev.lowrespalmtree.comet">
|
package="dev.lowrespalmtree.comet">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
|
|
@ -140,7 +140,9 @@ class MainActivity : AppCompatActivity(), ContentAdapter.ContentAdapterListen {
|
||||||
is PageViewModel.FailureEvent -> {
|
is PageViewModel.FailureEvent -> {
|
||||||
var message = event.details
|
var message = event.details
|
||||||
if (!event.serverDetails.isNullOrEmpty())
|
if (!event.serverDetails.isNullOrEmpty())
|
||||||
message += "\n\n" + "Server details: ${event.serverDetails}"
|
message += "\n\nServer details: ${event.serverDetails}"
|
||||||
|
if (!isConnectedToNetwork(this))
|
||||||
|
message += "\n\nInternet may be inaccessible…"
|
||||||
alert(message, title = event.short)
|
alert(message, title = event.short)
|
||||||
updateState(PageViewModel.State.IDLE)
|
updateState(PageViewModel.State.IDLE)
|
||||||
}
|
}
|
||||||
|
|
11
app/src/main/java/dev/lowrespalmtree/comet/NetUtils.kt
Normal file
11
app/src/main/java/dev/lowrespalmtree/comet/NetUtils.kt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package dev.lowrespalmtree.comet
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
|
||||||
|
fun isConnectedToNetwork(context: Context): Boolean {
|
||||||
|
val connManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
val caps = connManager.getNetworkCapabilities(connManager.activeNetwork) ?: return false
|
||||||
|
return caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
|
||||||
|
}
|
Reference in a new issue