Migrate to ktor 2.0

This commit is contained in:
tom5079
2022-04-24 21:06:29 +09:00
parent aa99c18a1b
commit b6ff956637
4 changed files with 13 additions and 26 deletions

View File

@@ -29,12 +29,7 @@ import com.google.android.gms.common.GooglePlayServicesRepairableException
import com.google.android.gms.security.ProviderInstaller
import io.ktor.client.*
import io.ktor.client.engine.okhttp.*
import io.ktor.client.features.*
import io.ktor.client.features.cache.*
import io.ktor.client.features.json.*
import io.ktor.client.features.json.serializer.*
import io.ktor.http.*
import okhttp3.Protocol
import io.ktor.client.plugins.contentnegotiation.*
import org.kodein.di.*
import org.kodein.di.android.x.androidXModule
import xyz.quaver.pupil.sources.core.NetworkCache
@@ -53,10 +48,7 @@ class Pupil : Application(), DIAware {
bind { singleton {
HttpClient(OkHttp) {
install(JsonFeature) {
serializer = KotlinxSerializer()
accept(ContentType("text", "plain"))
}
install(ContentNegotiation)
}
} }
}

View File

@@ -56,6 +56,7 @@ import com.google.accompanist.insets.ui.BottomNavigation
import com.google.accompanist.insets.ui.Scaffold
import com.google.accompanist.insets.ui.TopAppBar
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
@@ -181,7 +182,7 @@ fun Explore() {
while (true) {
delay(1000)
value = withContext(Dispatchers.IO) {
client.get<Map<String, RemoteSourceInfo>>("https://raw.githubusercontent.com/tom5079/PupilSources/master/versions.json")
client.get("https://raw.githubusercontent.com/tom5079/PupilSources/master/versions.json").body()
}
}
}

View File

@@ -20,23 +20,16 @@ package xyz.quaver.pupil.util
import android.content.Context
import android.content.Intent
import android.util.Log
import android.webkit.MimeTypeMap
import androidx.core.content.FileProvider
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.features.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.util.cio.*
import io.ktor.utils.io.*
import io.ktor.utils.io.core.*
import io.ktor.utils.io.jvm.javaio.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.withContext
import java.io.File
import kotlin.io.use
@@ -49,8 +42,8 @@ class ApkDownloadManager(private val context: Context, private val client: HttpC
it.delete()
}
client.get<HttpStatement>(url).execute { response ->
val channel: ByteReadChannel = response.receive()
client.prepareGet(url).execute { response ->
val channel = response.bodyAsChannel()
val contentLength = response.contentLength() ?: -1
var readBytes = 0f