Handle also UnknownHostException in GenericListModel

This commit is contained in:
tzugen 2021-05-21 23:26:13 +02:00
parent 005c1cb8f7
commit 0500bd5e88
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
2 changed files with 11 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import java.net.ConnectException
import java.net.UnknownHostException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -91,12 +92,18 @@ open class GenericListModel(application: Application) :
try {
load(isOffline, useId3Tags, musicService, refresh, bundle)
} catch (exception: ConnectException) {
Handler(Looper.getMainLooper()).post {
CommunicationErrorHandler.handleError(exception, swipe.context)
}
handleException(exception, swipe.context)
} catch (exception: UnknownHostException) {
handleException(exception, swipe.context)
}
}
private fun handleException(exception: Exception, context: Context) {
Handler(Looper.getMainLooper()).post {
CommunicationErrorHandler.handleError(exception, context)
}
}
/**
* This is the central function you need to implement if you want to extend this class
*/

View File

@ -20,12 +20,12 @@ import android.os.Looper
import android.os.PowerManager
import android.os.PowerManager.PARTIAL_WAKE_LOCK
import android.os.PowerManager.WakeLock
import org.koin.core.component.KoinApiExtension
import java.io.File
import java.net.URLEncoder
import java.util.Locale
import kotlin.math.abs
import kotlin.math.max
import org.koin.core.component.KoinApiExtension
import org.moire.ultrasonic.audiofx.EqualizerController
import org.moire.ultrasonic.audiofx.VisualizerController
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline