Migrate some old calls
This commit is contained in:
parent
e153565086
commit
f6f9683a9c
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue