-
-
Save colinrtwhite/90267704091467451e46b21b95154299 to your computer and use it in GitHub Desktop.
MeasuredMapper -> Interceptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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