Deal with SY for the coroutine function changes
This commit is contained in:
@@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.network.await
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.MetadataMangasPage
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import exh.md.handlers.serializers.FollowPage
|
||||
import exh.md.handlers.serializers.FollowsIndividualSerializer
|
||||
import exh.md.handlers.serializers.FollowsPageSerializer
|
||||
@@ -17,8 +18,6 @@ import exh.md.utils.FollowStatus
|
||||
import exh.md.utils.MdUtil
|
||||
import exh.metadata.metadata.MangaDexSearchMetadata
|
||||
import exh.util.floor
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import okhttp3.CacheControl
|
||||
import okhttp3.FormBody
|
||||
@@ -122,7 +121,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
||||
title = manga.title
|
||||
mdUrl = manga.url
|
||||
thumbnail_url = manga.thumbnail_url
|
||||
follow_status = FollowStatus.fromInt(result.followType)?.int
|
||||
follow_status = FollowStatus.fromInt(result.followType).int
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +129,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
||||
* Change the status of a manga
|
||||
*/
|
||||
suspend fun updateFollowStatus(mangaID: String, followStatus: FollowStatus): Boolean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
return withIOContext {
|
||||
val response: Response =
|
||||
if (followStatus == FollowStatus.UNFOLLOWED) {
|
||||
client.newCall(
|
||||
@@ -153,12 +152,12 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
||||
.await()
|
||||
}
|
||||
|
||||
withContext(Dispatchers.IO) { response.body?.string().isNullOrEmpty() }
|
||||
withIOContext { response.body?.string().isNullOrEmpty() }
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateReadingProgress(track: Track): Boolean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
return withIOContext {
|
||||
val mangaID = MdUtil.getMangaId(track.tracking_url)
|
||||
val formBody = FormBody.Builder()
|
||||
.add("chapter", track.last_chapter_read.toString())
|
||||
@@ -178,12 +177,12 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
||||
)
|
||||
).await().body?.close()
|
||||
|
||||
withContext(Dispatchers.IO) { response.body?.string().isNullOrEmpty() }
|
||||
withIOContext { response.body?.string().isNullOrEmpty() }
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateRating(track: Track): Boolean {
|
||||
return withContext(Dispatchers.IO) {
|
||||
return withIOContext {
|
||||
val mangaID = MdUtil.getMangaId(track.tracking_url)
|
||||
val response = client.newCall(
|
||||
GET(
|
||||
@@ -193,7 +192,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
||||
)
|
||||
.await()
|
||||
|
||||
withContext(Dispatchers.IO) { response.body?.string().isNullOrEmpty() }
|
||||
withIOContext { response.body?.string().isNullOrEmpty() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +200,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
||||
* fetch all manga from all possible pages
|
||||
*/
|
||||
suspend fun fetchAllFollows(forceHd: Boolean): List<Pair<SManga, MangaDexSearchMetadata>> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
return withIOContext {
|
||||
val listManga = mutableListOf<Pair<SManga, MangaDexSearchMetadata>>()
|
||||
val response = client.newCall(followsListRequest()).await()
|
||||
val mangasPage = followsParseMangaPage(response, forceHd)
|
||||
@@ -215,7 +214,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
|
||||
}
|
||||
|
||||
suspend fun fetchTrackingInfo(url: String): Track {
|
||||
return withContext(Dispatchers.IO) {
|
||||
return withIOContext {
|
||||
val request = GET(
|
||||
"${MdUtil.apiUrl}${MdUtil.followsMangaApi}" + MdUtil.getMangaId(url),
|
||||
headers,
|
||||
|
||||
@@ -10,10 +10,9 @@ import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.toMangaInfo
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.util.lang.runAsObservable
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import exh.md.handlers.serializers.ApiCovers
|
||||
import exh.md.utils.MdUtil
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.CacheControl
|
||||
import okhttp3.Headers
|
||||
import okhttp3.OkHttpClient
|
||||
@@ -25,12 +24,12 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, val lang: Str
|
||||
|
||||
// TODO make use of this
|
||||
suspend fun fetchMangaAndChapterDetails(manga: MangaInfo, sourceId: Long): Pair<MangaInfo, List<SChapter>> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
return withIOContext {
|
||||
val response = client.newCall(apiRequest(manga.toSManga())).await()
|
||||
val covers = getCovers(manga, forceLatestCovers)
|
||||
val parser = ApiMangaParser(lang)
|
||||
|
||||
val jsonData = withContext(Dispatchers.IO) { response.body!!.string() }
|
||||
val jsonData = withIOContext { response.body!!.string() }
|
||||
if (response.code != 200) {
|
||||
XLog.tag("MangaHandler").enableStackTrace(2).e("error from MangaDex with response code ${response.code} \n body: \n$jsonData")
|
||||
throw Exception("Error from MangaDex Response code ${response.code} ")
|
||||
@@ -55,7 +54,7 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, val lang: Str
|
||||
}
|
||||
|
||||
suspend fun getMangaIdFromChapterId(urlChapterId: String): Int {
|
||||
return withContext(Dispatchers.IO) {
|
||||
return withIOContext {
|
||||
val request = GET(MdUtil.apiUrl + MdUtil.newApiChapter + urlChapterId + MdUtil.apiChapterSuffix, headers, CacheControl.FORCE_NETWORK)
|
||||
val response = client.newCall(request).await()
|
||||
ApiMangaParser(lang).chapterParseForMangaId(response)
|
||||
@@ -63,7 +62,7 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, val lang: Str
|
||||
}
|
||||
|
||||
suspend fun getMangaDetails(manga: MangaInfo, sourceId: Long): MangaInfo {
|
||||
return withContext(Dispatchers.IO) {
|
||||
return withIOContext {
|
||||
val response = client.newCall(apiRequest(manga.toSManga())).await()
|
||||
val covers = getCovers(manga, forceLatestCovers)
|
||||
ApiMangaParser(lang).parseToManga(manga, response, covers, sourceId)
|
||||
@@ -100,7 +99,7 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, val lang: Str
|
||||
}
|
||||
|
||||
suspend fun fetchChapterList(manga: SManga): List<SChapter> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
return withIOContext {
|
||||
val response = client.newCall(apiRequest(manga)).await()
|
||||
ApiMangaParser(lang).chapterListParse(response)
|
||||
}
|
||||
@@ -115,7 +114,7 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, val lang: Str
|
||||
}
|
||||
|
||||
suspend fun fetchRandomMangaId(): String {
|
||||
return withContext(Dispatchers.IO) {
|
||||
return withIOContext {
|
||||
val response = client.newCall(randomMangaRequest()).await()
|
||||
ApiMangaParser(lang).randomMangaIdParse(response)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.network.await
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import eu.kanade.tachiyomi.util.system.isServiceRunning
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import exh.md.similar.sql.models.MangaSimilarImpl
|
||||
@@ -28,7 +29,6 @@ import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import okio.buffer
|
||||
import okio.sink
|
||||
import okio.source
|
||||
@@ -149,7 +149,7 @@ class SimilarUpdateService(
|
||||
/**
|
||||
* Method that updates the similar database for manga
|
||||
*/
|
||||
private suspend fun updateSimilar() = withContext(Dispatchers.IO) {
|
||||
private suspend fun updateSimilar() = withIOContext {
|
||||
val response = client
|
||||
.newCall(GET(similarUrl))
|
||||
.await()
|
||||
@@ -157,7 +157,7 @@ class SimilarUpdateService(
|
||||
throw Exception("Error trying to download similar file")
|
||||
}
|
||||
val destinationFile = File(filesDir, "neko-similar.json")
|
||||
val buffer = withContext(Dispatchers.IO) { destinationFile.sink().buffer() }
|
||||
val buffer = withIOContext { destinationFile.sink().buffer() }
|
||||
|
||||
// write json to file
|
||||
response.body?.byteStream()?.source()?.use { input ->
|
||||
|
||||
Reference in New Issue
Block a user