Fix wrong "no network" banner

This commit is contained in:
Benoit Marty 2019-09-20 18:18:55 +02:00
parent 5651ea515b
commit e04bf31faa
2 changed files with 14 additions and 3 deletions

View File

@ -20,6 +20,7 @@ import android.content.Context
import com.novoda.merlin.Merlin
import com.novoda.merlin.MerlinsBeard
import im.vector.matrix.android.internal.di.MatrixScope
import im.vector.matrix.android.internal.util.BackgroundDetectionObserver
import timber.log.Timber
import java.util.*
import javax.inject.Inject
@ -27,7 +28,9 @@ import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
@MatrixScope
internal class NetworkConnectivityChecker @Inject constructor(context: Context) {
internal class NetworkConnectivityChecker @Inject constructor(context: Context,
backgroundDetectionObserver: BackgroundDetectionObserver)
: BackgroundDetectionObserver.Listener {
private val merlin = Merlin.Builder()
.withConnectableCallbacks()
@ -41,7 +44,12 @@ internal class NetworkConnectivityChecker @Inject constructor(context: Context)
private set
init {
backgroundDetectionObserver.register(this)
}
override fun onMoveToForeground() {
merlin.bind()
merlin.registerDisconnectable {
if (hasInternetAccess) {
Timber.v("On Disconnect")
@ -64,6 +72,10 @@ internal class NetworkConnectivityChecker @Inject constructor(context: Context)
}
}
override fun onMoveToBackground() {
merlin.unbind()
}
suspend fun waitUntilConnected() {
if (hasInternetAccess) {
return

View File

@ -30,7 +30,6 @@ import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.TaskThread
import im.vector.matrix.android.internal.task.configureWith
import im.vector.matrix.android.internal.util.BackgroundDetectionObserver
import kotlinx.coroutines.CancellationException
import timber.log.Timber
import java.net.SocketTimeoutException
import java.util.concurrent.CountDownLatch
@ -140,7 +139,7 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
if (failure is Failure.NetworkConnection && failure.cause is SocketTimeoutException) {
// Timeout are not critical
Timber.v("Timeout")
} else if (failure is Failure.Unknown && failure.throwable is CancellationException) {
} else if (failure is Failure.Cancelled) {
Timber.v("Cancelled")
} else if (failure is Failure.ServerError
&& (failure.error.code == MatrixError.UNKNOWN_TOKEN || failure.error.code == MatrixError.MISSING_TOKEN)) {