-
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.
# Description The goal of this PR is to enhance the integrator experience with image url handling. The new api allow to write with ease image url like the SRG SSR required. ### Examples ```kotlin val media: Media = ... media.imageUrl.url(ImageWidth.W1920) media.imageUrl.url(ImageWidth.W1920, IlHost.TEST) val chapter: Chapter = ... chapter.imageUrl.url(ImageSize.MEDIUM) val defaultDecorator = DefaultImageUrlDecorator(IlHost.PROD) // or custom decorator media.imageUrl.url(defaultDecorator, ImageSize.MEDIUM) ``` ## Changes - `ImageUrl.rawUrl` is private now - Add `ImageUrlDecorator` to decorate image url with a width - Remove `ImageProvider` replaced by `DefaultImageUrlDecorator` --------- Co-authored-by: Loïc Dumas <[email protected]> Co-authored-by: Gaëtan Muller <[email protected]>
- Loading branch information
1 parent
4c202f3
commit aca31b8
Showing
17 changed files
with
524 additions
and
153 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
37 changes: 0 additions & 37 deletions
37
data/src/main/java/ch/srg/dataProvider/integrationlayer/data/IlImage.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
15 changes: 15 additions & 0 deletions
15
data/src/main/java/ch/srg/dataProvider/integrationlayer/data/ImageUrlDecorator.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package ch.srg.dataProvider.integrationlayer.data | ||
|
||
/** | ||
* Image url decorator | ||
*/ | ||
interface ImageUrlDecorator { | ||
/** | ||
* Decorate [sourceUrl] with [widthPixels]. | ||
* | ||
* @param sourceUrl The source url. | ||
* @param widthPixels The width size in pixels. | ||
* @return decorated url. | ||
*/ | ||
fun decorate(sourceUrl: String, widthPixels: Int): String | ||
} |
46 changes: 46 additions & 0 deletions
46
...src/androidTest/java/ch/srg/dataProvider/integrationlayer/TestDefaultImageUrlDecorator.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ch.srg.dataProvider.integrationlayer | ||
|
||
import android.net.Uri | ||
import ch.srg.dataProvider.integrationlayer.data.ImageUrl | ||
import ch.srg.dataProvider.integrationlayer.request.IlHost | ||
import ch.srg.dataProvider.integrationlayer.request.image.DefaultImageUrlDecorator | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class TestDefaultImageUrlDecorator { | ||
private val decorator = DefaultImageUrlDecorator(ilHost = IlHost.PROD) | ||
|
||
@Test | ||
fun testNonRtsUrl() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
Assert.assertEquals(expected, input.decorated(decorator, 480)) | ||
} | ||
|
||
@Test | ||
fun testRtsUrlWithoutImage() { | ||
val input = ImageUrl("https://ws.rts.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.rts.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
Assert.assertEquals(expected, input.decorated(decorator, 480)) | ||
} | ||
|
||
@Test | ||
fun testUrlWithImageOnly() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123.image") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123.image") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
Assert.assertEquals(expected, input.decorated(decorator, 480)) | ||
} | ||
|
||
@Test | ||
fun testRtsUrlWithImage() { | ||
val input = ImageUrl("https://ws.rts.ch/asset/image/audio/123.image") | ||
val expected = "https://ws.rts.ch/asset/image/audio/123.image/scale/width/460" | ||
Assert.assertEquals(expected, input.decorated(decorator, 460)) | ||
} | ||
|
||
|
||
|
||
} |
73 changes: 73 additions & 0 deletions
73
.../src/androidTest/java/ch/srg/dataProvider/integrationlayer/TestIlHostImageUrlDecorator.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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package ch.srg.dataProvider.integrationlayer | ||
|
||
import android.net.Uri | ||
import ch.srg.dataProvider.integrationlayer.data.ImageUrl | ||
import ch.srg.dataProvider.integrationlayer.request.IlHost | ||
import ch.srg.dataProvider.integrationlayer.request.image.IlHostImageUrlDecorator | ||
import ch.srg.dataProvider.integrationlayer.request.image.ImageSize | ||
import ch.srg.dataProvider.integrationlayer.request.image.ImageWidth | ||
import ch.srg.dataProvider.integrationlayer.request.image.url | ||
import ch.srg.dataProvider.integrationlayer.request.image.decorated | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class TestIlHostImageUrlDecorator { | ||
|
||
private val decorator = IlHostImageUrlDecorator(ilHost = IlHost.PROD) | ||
|
||
@Test | ||
fun testPixelValid() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
assertEquals(expected, input.decorated(decorator, 480)) | ||
} | ||
|
||
@Test | ||
fun testPixelWidthInvalid() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
assertEquals(expected, input.decorated(decorator, 460)) | ||
} | ||
|
||
@Test | ||
fun testImageSize() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
assertEquals(expected, input.decorated(decorator, ImageSize.MEDIUM)) | ||
} | ||
|
||
@Test | ||
fun testImageWidth() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=1920" | ||
assertEquals(expected, input.url(decorator, ImageWidth.W1920)) | ||
} | ||
|
||
@Test | ||
fun testOtherIlHost() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il-stage.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=1920" | ||
assertEquals(expected, input.url(decorator = IlHostImageUrlDecorator(IlHost.STAGE), width = ImageWidth.W1920)) | ||
} | ||
|
||
@Test | ||
fun testExtensionImageWidthWithIlHost() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il-stage.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=1920" | ||
assertEquals(expected, input.decorated(ilHost = IlHost.STAGE, width = ImageWidth.W1920)) | ||
} | ||
|
||
@Test | ||
fun testExtensionImageSizeWithIlHost() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il-test.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
assertEquals(expected, input.decorated(ilHost = IlHost.TEST, imageSize = ImageSize.MEDIUM)) | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
.../androidTest/java/ch/srg/dataProvider/integrationlayer/TestScaleWidthImageUrlDecorator.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ch.srg.dataProvider.integrationlayer | ||
|
||
import ch.srg.dataProvider.integrationlayer.data.ImageUrl | ||
import ch.srg.dataProvider.integrationlayer.request.image.ImageSize | ||
import ch.srg.dataProvider.integrationlayer.request.image.ImageWidth | ||
import ch.srg.dataProvider.integrationlayer.request.image.ScaleWidthImageUrlDecorator | ||
import ch.srg.dataProvider.integrationlayer.request.image.url | ||
import ch.srg.dataProvider.integrationlayer.request.image.decorated | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class TestScaleWidthImageUrlDecorator { | ||
|
||
private val decorator = ScaleWidthImageUrlDecorator | ||
|
||
@Test | ||
fun testScaleWidth() { | ||
val input = ImageUrl("https://www.data.com/images/images.png") | ||
val width = 458 | ||
val expected = "https://www.data.com/images/images.png/scale/width/458" | ||
assertEquals(expected, input.decorated(decorator, width)) | ||
} | ||
|
||
@Test | ||
fun testScaleWidthImageSize() { | ||
val input = ImageUrl("https://www.data.com/images/images.png") | ||
val expected = "https://www.data.com/images/images.png/scale/width/480" | ||
assertEquals(expected, input.decorated(decorator, ImageSize.MEDIUM)) | ||
} | ||
|
||
@Test | ||
fun testScaleWidthImageWidth() { | ||
val input = ImageUrl("https://www.data.com/images/images.png") | ||
val expected = "https://www.data.com/images/images.png/scale/width/1920" | ||
assertEquals(expected, input.url(decorator, ImageWidth.W1920)) | ||
} | ||
} |
101 changes: 0 additions & 101 deletions
101
...ider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/ImageProvider.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.