Migrate some old calls

This commit is contained in:
tzugen 2022-03-19 17:20:39 +01:00
parent e153565086
commit f6f9683a9c
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
5 changed files with 16 additions and 16 deletions

View File

@ -9,6 +9,7 @@ import java.util.TimeZone
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okio.Okio
import okio.source
import org.amshove.kluent.`should be`
import org.amshove.kluent.`should contain`
import org.amshove.kluent.`should not be`
@ -40,12 +41,12 @@ fun MockWebServer.enqueueResponse(resourceName: String) {
}
fun Any.loadJsonResponse(name: String): String {
val source = Okio.buffer(Okio.source(javaClass.classLoader.getResourceAsStream(name)))
val source = Okio.buffer(javaClass.classLoader.getResourceAsStream(name).source())
return source.readString(Charset.forName("UTF-8"))
}
fun Any.loadResourceStream(name: String): InputStream {
val source = Okio.buffer(Okio.source(javaClass.classLoader.getResourceAsStream(name)))
val source = Okio.buffer(javaClass.classLoader.getResourceAsStream(name).source())
return source.inputStream()
}

View File

@ -4,7 +4,7 @@ import com.squareup.picasso.Picasso
import com.squareup.picasso.Request
import com.squareup.picasso.RequestHandler
import java.io.IOException
import okio.Okio
import okio.source
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
/**
@ -29,7 +29,7 @@ class AvatarRequestHandler(
if (response.hasError() || response.stream == null) {
throw IOException("${response.apiError}")
} else {
return Result(Okio.source(response.stream!!), Picasso.LoadedFrom.NETWORK)
return Result(response.stream!!.source(), Picasso.LoadedFrom.NETWORK)
}
}
}

View File

@ -5,7 +5,7 @@ import com.squareup.picasso.Picasso.LoadedFrom.NETWORK
import com.squareup.picasso.Request
import com.squareup.picasso.RequestHandler
import java.io.IOException
import okio.Okio
import okio.source
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
import org.moire.ultrasonic.api.subsonic.toStreamResponse
import org.moire.ultrasonic.util.FileUtil.SUFFIX_LARGE
@ -44,7 +44,7 @@ class CoverArtRequestHandler(private val client: SubsonicAPIClient) : RequestHan
// Handle the response
if (!response.hasError() && response.stream != null) {
return Result(Okio.source(response.stream!!), NETWORK)
return Result(response.stream!!.source(), NETWORK)
}
// Throw an error if still not successful

View File

@ -10,12 +10,11 @@ import java.io.IOException
import java.io.InputStream
import okhttp3.Protocol
import okhttp3.Response
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
import org.moire.ultrasonic.api.subsonic.models.AlbumListType.Companion.fromName
import org.moire.ultrasonic.api.subsonic.models.JukeboxAction
import org.moire.ultrasonic.api.subsonic.response.StreamResponse
import org.moire.ultrasonic.api.subsonic.throwOnFailure
import org.moire.ultrasonic.api.subsonic.toStreamResponse
import org.moire.ultrasonic.data.ActiveServerProvider
@ -425,14 +424,13 @@ open class RESTMusicService(
save: Boolean
): Pair<InputStream, Boolean> {
val songOffset = if (offset < 0) 0 else offset
lateinit var response: StreamResponse
// Use semantically correct call
if (save) {
response = API.download(song.id, maxBitrate, offset = songOffset)
val response = if (save) {
API.download(song.id, maxBitrate, offset = songOffset)
.execute().toStreamResponse()
} else {
response = API.stream(song.id, maxBitrate, offset = songOffset)
API.stream(song.id, maxBitrate, offset = songOffset)
.execute().toStreamResponse()
}
@ -463,7 +461,7 @@ open class RESTMusicService(
// Returns a dummy response
Response.Builder()
.code(100)
.body(ResponseBody.create(null, ""))
.body("".toResponseBody(null))
.protocol(Protocol.HTTP_2)
.message("Empty response")
.request(chain.request())
@ -480,7 +478,7 @@ open class RESTMusicService(
val response = client.newCall(request).execute()
// The complete url :)
val url = response.request().url()
val url = response.request.url
return url.toString()
}

View File

@ -1,9 +1,10 @@
package org.moire.ultrasonic.imageloader
import java.io.InputStream
import okio.Okio
import okio.buffer
import okio.source
fun Any.loadResourceStream(name: String): InputStream {
val source = Okio.buffer(Okio.source(javaClass.classLoader!!.getResourceAsStream(name)))
val source = javaClass.classLoader!!.getResourceAsStream(name).source().buffer()
return source.inputStream()
}