refactor: Don't use context receiver

Deprecated on Kotlin 2.x, scheduled for removal in v2.1.x, will be replaced with context parameters

REF: https://github.com/Kotlin/KEEP/issues/259#issuecomment-2278319746
REF: https://youtrack.jetbrains.com/issue/KT-67119/Migration-warning-from-context-receivers-to-context-parameters
REF: https://github.com/Kotlin/KEEP/issues/367
This commit is contained in:
Ahmad Ansori Palembani 2025-01-01 07:10:30 +07:00
parent 1b92ae2e5f
commit d02f1bdd11
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
17 changed files with 265 additions and 347 deletions

View file

@ -66,7 +66,6 @@ android {
tasks {
withType<KotlinCompile> {
compilerOptions.freeCompilerArgs.addAll(
"-Xcontext-receivers",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
)

View file

@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.network
import java.io.IOException
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.coroutines.resumeWithException
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.json.Json
@ -18,6 +17,8 @@ import okhttp3.Response
import rx.Observable
import rx.Producer
import rx.Subscription
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
val jsonMime = "application/json; charset=utf-8".toMediaType()
@ -68,7 +69,6 @@ fun Call.asObservableSuccess(): Observable<Response> {
}
// Based on https://github.com/gildor/kotlin-coroutines-okhttp
@OptIn(ExperimentalCoroutinesApi::class)
private suspend fun Call.await(callStack: Array<StackTraceElement>): Response {
return suspendCancellableCoroutine { continuation ->
val callback =
@ -131,13 +131,11 @@ fun OkHttpClient.newCachelessCallWithProgress(request: Request, listener: Progre
return progressClient.newCall(request)
}
context(Json)
inline fun <reified T> Response.parseAs(): T {
return decodeFromJsonResponse(serializer(), this)
return Injekt.get<Json>().decodeFromJsonResponse(serializer(), this)
}
context(Json)
fun <T> decodeFromJsonResponse(
fun <T> Json.decodeFromJsonResponse(
deserializer: DeserializationStrategy<T>,
response: Response,
): T {