More coroutine network call fixes

This commit is contained in:
arkon 2020-02-14 09:23:54 -05:00
parent 0a6f607e22
commit 34bf9b729e
3 changed files with 20 additions and 26 deletions

View File

@ -6,6 +6,8 @@ import eu.kanade.tachiyomi.data.updater.UpdateResult
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.network.await import eu.kanade.tachiyomi.network.await
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -23,7 +25,9 @@ class DevRepoUpdateChecker : UpdateChecker() {
} }
override suspend fun checkForUpdate(): UpdateResult { override suspend fun checkForUpdate(): UpdateResult {
val response = client.newCall(GET(DevRepoRelease.LATEST_URL)).await(assertSuccess = false) val response = withContext(Dispatchers.IO) {
client.newCall(GET(DevRepoRelease.LATEST_URL)).await(assertSuccess = false)
}
// Get latest repo version number from header in format "Location: tachiyomi-r1512.apk" // Get latest repo version number from header in format "Location: tachiyomi-r1512.apk"
val latestVersionNumber: String = versionRegex.find(response.header("Location")!!)!!.groupValues[1] val latestVersionNumber: String = versionRegex.find(response.header("Location")!!)!!.groupValues[1]

View File

@ -12,9 +12,7 @@ import eu.kanade.tachiyomi.extension.util.ExtensionInstallReceiver
import eu.kanade.tachiyomi.extension.util.ExtensionInstaller import eu.kanade.tachiyomi.extension.util.ExtensionInstaller
import eu.kanade.tachiyomi.extension.util.ExtensionLoader import eu.kanade.tachiyomi.extension.util.ExtensionLoader
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.launchNow import eu.kanade.tachiyomi.util.lang.launchNow
import eu.kanade.tachiyomi.util.lang.launchUI
import kotlinx.coroutines.async import kotlinx.coroutines.async
import rx.Observable import rx.Observable
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
@ -146,16 +144,14 @@ class ExtensionManager(
* Finds the available extensions in the [api] and updates [availableExtensions]. * Finds the available extensions in the [api] and updates [availableExtensions].
*/ */
fun findAvailableExtensions() { fun findAvailableExtensions() {
launchIO { launchNow {
val extensions: List<Extension.Available> = try { val extensions: List<Extension.Available> = try {
api.findExtensions() api.findExtensions()
} catch (e: Exception) { } catch (e: Exception) {
emptyList() emptyList()
} }
launchUI { availableExtensions = extensions
availableExtensions = extensions
}
} }
} }

View File

@ -16,8 +16,7 @@ import eu.kanade.tachiyomi.data.updater.UpdaterJob
import eu.kanade.tachiyomi.data.updater.UpdaterService import eu.kanade.tachiyomi.data.updater.UpdaterService
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.main.ChangelogDialogController import eu.kanade.tachiyomi.ui.main.ChangelogDialogController
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchNow
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.lang.toTimestampString import eu.kanade.tachiyomi.util.lang.toTimestampString
import eu.kanade.tachiyomi.util.preference.* import eu.kanade.tachiyomi.util.preference.*
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
@ -119,28 +118,23 @@ class SettingsAboutController : SettingsController() {
activity?.toast(R.string.update_check_look_for_updates) activity?.toast(R.string.update_check_look_for_updates)
launchIO { launchNow {
try { try {
val result = updateChecker.checkForUpdate() when (val result = updateChecker.checkForUpdate()) {
launchUI { is UpdateResult.NewUpdate<*> -> {
when (result) { val body = result.release.info
is UpdateResult.NewUpdate<*> -> { val url = result.release.downloadLink
val body = result.release.info
val url = result.release.downloadLink
// Create confirmation window // Create confirmation window
NewUpdateDialogController(body, url).showDialog(router) NewUpdateDialogController(body, url).showDialog(router)
} }
is UpdateResult.NoNewUpdate -> { is UpdateResult.NoNewUpdate -> {
activity?.toast(R.string.update_check_no_new_updates) activity?.toast(R.string.update_check_no_new_updates)
}
} }
} }
} catch (error: Exception) { } catch (error: Exception) {
launchUI { activity?.toast(error.message)
activity?.toast(error.message) Timber.e(error)
Timber.e(error)
}
} }
} }
} }