-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
36 remove rts image workaround (#37)
Remove RTS image scaling workaround. Now every image are decorated by the integration layer image service.
- Loading branch information
Showing
7 changed files
with
111 additions
and
253 deletions.
There are no files selected for viewing
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
57 changes: 40 additions & 17 deletions
57
.../main/java/ch/srg/dataProvider/integrationlayer/request/image/DefaultImageUrlDecorator.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,54 @@ | ||
package ch.srg.dataProvider.integrationlayer.request.image | ||
|
||
import android.net.Uri | ||
import ch.srg.dataProvider.integrationlayer.data.ImageUrlDecorator | ||
import ch.srg.dataProvider.integrationlayer.request.IlHost | ||
|
||
/** | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* Il host image url decorator | ||
* | ||
* If the image url isn't supported by [DefaultImageUrlDecorator] the same url is returned. | ||
* | ||
* License information is available from the LICENSE file. | ||
*/ | ||
|
||
/** | ||
* Default image url decorator | ||
* confluence doc : https://srgssr-ch.atlassian.net/wiki/spaces/SRGPLAY/pages/799082429/Project+-+Image+Service) | ||
* | ||
* For specific RTS image url, the old [ScaleWidthImageUrlDecorator] is used, but it should be fixed sooner or later. | ||
* | ||
* @param ilHost The [IlHost] to use with [ilHostImageUrlDecorator]. | ||
* @param ilHost The [IlHost] of the integration layer image service. | ||
*/ | ||
class DefaultImageUrlDecorator(ilHost: IlHost = IlHost.PROD) : ImageUrlDecorator { | ||
private val ilHostImageUrlDecorator = IlHostImageUrlDecorator(ilHost) | ||
class DefaultImageUrlDecorator(ilHost: IlHost) : ImageUrlDecorator { | ||
private val imageServiceUri: Uri | ||
|
||
init { | ||
imageServiceUri = ilHost.hostUri.buildUpon().appendEncodedPath(IMAGES_SEGMENT).build() | ||
} | ||
|
||
override fun decorate(sourceUrl: String, widthPixels: Int): String { | ||
// FIXME https://github.com/SRGSSR/srgdataprovider-apple/issues/47 once RTS image service is well connected to Il Play image service. | ||
return if (sourceUrl.contains("rts.ch") && sourceUrl.contains(".image")) { | ||
ScaleWidthImageUrlDecorator.decorate(sourceUrl, widthPixels) | ||
} else { | ||
ilHostImageUrlDecorator.decorate(sourceUrl, widthPixels) | ||
} | ||
// Il image service only support some image url hostnames! | ||
if (!isImageUrlHostCompatible(sourceUrl)) return sourceUrl | ||
// Il image service only support a limited image size! | ||
val imageWidth = ImageWidth.getFromPixels(widthPixels) | ||
return imageServiceUri.buildUpon() | ||
.appendQueryParameter(PARAM_IMAGE_URL, sourceUrl) | ||
.appendQueryParameter(PARAM_FORMAT, FORMAT_WEBP) | ||
.appendQueryParameter(PARAM_WIDTH, imageWidth.widthPixels.toString()) | ||
.build() | ||
.toString() | ||
} | ||
|
||
/** | ||
* Check that the host of the [imageUrl] is compatible with the il image service. | ||
* | ||
* @param imageUrl The image url to decorate. | ||
*/ | ||
fun isImageUrlHostCompatible(imageUrl: String): Boolean { | ||
return Uri.parse(imageUrl)?.host?.contains(SUPPORTED_HOST_NAME_REGEX) ?: false | ||
} | ||
|
||
companion object { | ||
private const val FORMAT_WEBP = "webp" // webp, jpg, png | ||
private const val IMAGES_SEGMENT = "images/" | ||
private const val PARAM_IMAGE_URL = "imageUrl" | ||
private const val PARAM_FORMAT = "format" | ||
private const val PARAM_WIDTH = "width" | ||
|
||
private val SUPPORTED_HOST_NAME_REGEX = "((rts|srf|rsi|rtr|swissinfo|srgssr)\\.ch)|swi-services-ch".toRegex(RegexOption.IGNORE_CASE) | ||
} | ||
} |
54 changes: 0 additions & 54 deletions
54
...c/main/java/ch/srg/dataProvider/integrationlayer/request/image/IlHostImageUrlDecorator.kt
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
...in/java/ch/srg/dataProvider/integrationlayer/request/image/ScaleWidthImageUrlDecorator.kt
This file was deleted.
Oops, something went wrong.
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
103 changes: 0 additions & 103 deletions
103
...etrofit/src/test/java/ch/srg/dataProvider/integrationlayer/TestIlHostImageUrlDecorator.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.