File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
omegatypes/src/main/java/com/omega_r/libs/omegatypes/image Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -6,21 +6,33 @@ import com.omega_r.libs.omegatypes.decoders.toBitmap
66import java.io.IOException
77import java.net.HttpURLConnection
88import java.net.URL
9+ import java.util.regex.Pattern
910
1011
1112/* *
1213 * Created by Anton Knyazev on 2019-10-03.
1314 */
14- data class UrlImage (val url : String ) : BaseBitmapImage() {
15+ data class UrlImage (val baseUrl : String? = null , val relativeUrl : String ) : BaseBitmapImage() {
1516
1617 companion object {
18+ private val PATTERN_ABSOLUTE_URL = Pattern .compile(" \\ A[a-z0-9.+-]+://.*" , Pattern .CASE_INSENSITIVE )
19+
20+ var defaultBaseUrl : String? = null
1721
1822 init {
1923 ImageProcessors .default.addImageProcessor(UrlImage ::class , Processor ())
2024 }
2125
26+ private fun String.isAbsoluteUrl (): Boolean = PATTERN_ABSOLUTE_URL .matcher(this ).matches()
27+
2228 }
2329
30+
31+ val url: String
32+ get() = if (relativeUrl.isAbsoluteUrl()) relativeUrl else (baseUrl ? : defaultBaseUrl ? : " " ) + relativeUrl
33+
34+ constructor (url: String ): this (null , url)
35+
2436 class Processor : BaseBitmapImage .Processor <UrlImage >(true ) {
2537
2638
You can’t perform that action at this time.
0 commit comments