Skip to content
Snippets Groups Projects
Commit f85182ec authored by Taras's avatar Taras
Browse files

Check for network access on application resume

parent 685c433a
No related branches found
No related tags found
No related merge requests found
...@@ -90,6 +90,7 @@ class App : Application() { ...@@ -90,6 +90,7 @@ class App : Application() {
override fun onResume(owner: LifecycleOwner) { override fun onResume(owner: LifecycleOwner) {
fcmHelper.onEnterForeground() fcmHelper.onEnterForeground()
MatrixSessionProvider.currentSession?.syncService()?.stopAnyBackgroundSync() MatrixSessionProvider.currentSession?.syncService()?.stopAnyBackgroundSync()
NetworkObserver.updateConnectionState(applicationContext)
} }
override fun onPause(owner: LifecycleOwner) { override fun onPause(owner: LifecycleOwner) {
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
</manifest> </manifest>
\ No newline at end of file
...@@ -21,10 +21,14 @@ object NetworkObserver { ...@@ -21,10 +21,14 @@ object NetworkObserver {
fun isConnected() = internetConnectionFlow.value fun isConnected() = internetConnectionFlow.value
fun register(context: Context) { fun register(context: Context) {
internetConnectionFlow.value = isConnectedToInternet(context) updateConnectionState(context)
setInternetConnectionObserver(context) { internetConnectionFlow.value = it } setInternetConnectionObserver(context) { internetConnectionFlow.value = it }
} }
fun updateConnectionState(context: Context) {
internetConnectionFlow.value = isConnectedToInternet(context)
}
fun observe(lifecycleOwner: LifecycleOwner, onConnectionChanged: (Boolean) -> Unit) { fun observe(lifecycleOwner: LifecycleOwner, onConnectionChanged: (Boolean) -> Unit) {
lifecycleOwner.lifecycleScope.launch { lifecycleOwner.lifecycleScope.launch {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment