Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MeasuredMapper -> Interceptor
class HttpUriInterceptor : Interceptor {
override suspend fun intercept(chain: Interceptor.Chain): ImageResult {
val data = chain.request.data
val request = if (data is Uri && handles(data)) {
chain.request.newBuilder().data(map(data, chain.size)).build()
} else {
chain.request
}
return chain.proceed(request)
}
private fun handles(data: Uri) = data.scheme == "http" || data.scheme == "https"
private fun map(data: Uri, size: Size): HttpUrl {
return data.toString()
.toHttpUrl()
.newBuilder()
.addQueryParameter("size", size.toString())
.build()
}
}
class HttpUriMeasuredMapper : MeasuredMapper<Uri, HttpUrl> {
override fun handles(data: Uri) = data.scheme == "http" || data.scheme == "https"
override fun map(data: Uri, size: Size): HttpUrl {
return data.toString()
.toHttpUrl()
.newBuilder()
.addQueryParameter("size", size.toString())
.build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment