diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketRecommendedStory.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketRecommendedStory.kt deleted file mode 100644 index 98e99f3d5af..00000000000 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketRecommendedStory.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package mozilla.components.service.pocket - -/** - * A Pocket recommended story. - * - * @property title the title of the story. - * @property url a "pocket.co" shortlink for the original story's page. - * @property imageUrl a url to a still image representing the story. - * @property publisher optional publisher name/domain, e.g. "The New Yorker" / "nationalgeographic.co.uk"". - * **May be empty**. - * @property category topic of interest under which similar stories are grouped. - * @property timeToRead inferred time needed to read the entire story. **May be -1**. - */ -data class PocketRecommendedStory( - val title: String, - val url: String, - val imageUrl: String, - val publisher: String, - val category: String, - val timeToRead: Int, - val timesShown: Long -) diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketSponsoredStory.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketSponsoredStory.kt deleted file mode 100644 index 6c5b382420f..00000000000 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketSponsoredStory.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package mozilla.components.service.pocket - -/** - * A Pocket sponsored story. - * - * @property title the title of the story. - * @property url 3rd party url containing the original story. - * @property imageUrl a url to a still image representing the story. - * Contains a "resize" parameter in the form of "resize=w618-h310" allowing to get the image - * with a specific resolution and the CENTER_CROP ScaleType. - * @property sponsor 3rd party sponsor of this story, e.g. "NextAdvisor". - * @property shim Unique identifiers for when the user interacts with this story. - */ -data class PocketSponsoredStory( - val title: String, - val url: String, - val imageUrl: String, - val sponsor: String, - val shim: PocketSponsoredStoryShim, -) - -/** - * Sponsored story unique identifiers intended to be used in telemetry. - * - * @property click Unique identifier for when the sponsored story is clicked. - * @property impression Unique identifier for when the user sees this sponsored story. - */ -data class PocketSponsoredStoryShim( - val click: String, - val impression: String, -) diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStoriesService.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStoriesService.kt index 621655bd56f..50d0377a988 100644 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStoriesService.kt +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStoriesService.kt @@ -6,6 +6,8 @@ package mozilla.components.service.pocket import android.content.Context import androidx.annotation.VisibleForTesting +import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory +import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory import mozilla.components.service.pocket.spocs.SpocsUseCases import mozilla.components.service.pocket.stories.PocketStoriesUseCases import mozilla.components.service.pocket.update.PocketStoriesRefreshScheduler diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStory.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStory.kt new file mode 100644 index 00000000000..d8b03353a77 --- /dev/null +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStory.kt @@ -0,0 +1,71 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package mozilla.components.service.pocket + +/** + * A Pocket story downloaded from the Internet and intended to be displayed in the application. + */ +sealed class PocketStory { + /** + * Title of the story. + */ + abstract val title: String + + /** + * Url where the story can be full read. + */ + abstract val url: String + + /** + * A Pocket recommended story. + * + * @property title The title of the story. + * @property url A "pocket.co" shortlink for the original story's page. + * @property imageUrl A url to a still image representing the story. + * @property publisher Optional publisher name/domain, e.g. "The New Yorker" / "nationalgeographic.co.uk"". + * **May be empty**. + * @property category Topic of interest under which similar stories are grouped. + * @property timeToRead Inferred time needed to read the entire story. **May be -1**. + */ + data class PocketRecommendedStory( + override val title: String, + override val url: String, + val imageUrl: String, + val publisher: String, + val category: String, + val timeToRead: Int, + val timesShown: Long + ) : PocketStory() + + /** + * A Pocket sponsored story. + * + * @property title The title of the story. + * @property url 3rd party url containing the original story. + * @property imageUrl A url to a still image representing the story. + * Contains a "resize" parameter in the form of "resize=w618-h310" allowing to get the image + * with a specific resolution and the CENTER_CROP ScaleType. + * @property sponsor 3rd party sponsor of this story, e.g. "NextAdvisor". + * @property shim Unique identifiers for when the user interacts with this story. + */ + data class PocketSponsoredStory( + override val title: String, + override val url: String, + val imageUrl: String, + val sponsor: String, + val shim: PocketSponsoredStoryShim, + ) : PocketStory() + + /** + * Sponsored story unique identifiers intended to be used in telemetry. + * + * @property click Unique identifier for when the sponsored story is clicked. + * @property impression Unique identifier for when the user sees this sponsored story. + */ + data class PocketSponsoredStoryShim( + val click: String, + val impression: String, + ) +} diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/ext/Mappers.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/ext/Mappers.kt index 7b318e010e3..b660f658353 100644 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/ext/Mappers.kt +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/ext/Mappers.kt @@ -5,9 +5,9 @@ package mozilla.components.service.pocket.ext import androidx.annotation.VisibleForTesting -import mozilla.components.service.pocket.PocketRecommendedStory -import mozilla.components.service.pocket.PocketSponsoredStory -import mozilla.components.service.pocket.PocketSponsoredStoryShim +import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory +import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory +import mozilla.components.service.pocket.PocketStory.PocketSponsoredStoryShim import mozilla.components.service.pocket.spocs.api.ApiSpoc import mozilla.components.service.pocket.spocs.db.SpocEntity import mozilla.components.service.pocket.stories.api.PocketApiStory diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/spocs/SpocsRepository.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/spocs/SpocsRepository.kt index bd45f548169..8f6a6d3ff71 100644 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/spocs/SpocsRepository.kt +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/spocs/SpocsRepository.kt @@ -6,7 +6,7 @@ package mozilla.components.service.pocket.spocs import android.content.Context import androidx.annotation.VisibleForTesting -import mozilla.components.service.pocket.PocketSponsoredStory +import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory import mozilla.components.service.pocket.ext.toLocalSpoc import mozilla.components.service.pocket.ext.toPocketSponsoredStory import mozilla.components.service.pocket.spocs.api.ApiSpoc diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/spocs/SpocsUseCases.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/spocs/SpocsUseCases.kt index 459553326ca..bd870aa146a 100644 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/spocs/SpocsUseCases.kt +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/spocs/SpocsUseCases.kt @@ -7,7 +7,7 @@ package mozilla.components.service.pocket.spocs import android.content.Context import androidx.annotation.VisibleForTesting import mozilla.components.concept.fetch.Client -import mozilla.components.service.pocket.PocketSponsoredStory +import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory import mozilla.components.service.pocket.spocs.api.SpocsEndpoint import mozilla.components.service.pocket.stories.api.PocketResponse.Failure import mozilla.components.service.pocket.stories.api.PocketResponse.Success diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/PocketRecommendationsRepository.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/PocketRecommendationsRepository.kt index a74d3f42470..1589415702a 100644 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/PocketRecommendationsRepository.kt +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/PocketRecommendationsRepository.kt @@ -6,7 +6,7 @@ package mozilla.components.service.pocket.stories import android.content.Context import androidx.annotation.VisibleForTesting -import mozilla.components.service.pocket.PocketRecommendedStory +import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory import mozilla.components.service.pocket.ext.toPartialTimeShownUpdate import mozilla.components.service.pocket.ext.toPocketLocalStory import mozilla.components.service.pocket.ext.toPocketRecommendedStory diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/PocketStoriesUseCases.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/PocketStoriesUseCases.kt index 52cadd9ffbc..77207b8741f 100644 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/PocketStoriesUseCases.kt +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/PocketStoriesUseCases.kt @@ -7,7 +7,7 @@ package mozilla.components.service.pocket.stories import android.content.Context import androidx.annotation.VisibleForTesting import mozilla.components.concept.fetch.Client -import mozilla.components.service.pocket.PocketRecommendedStory +import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory import mozilla.components.service.pocket.stories.api.PocketEndpoint import mozilla.components.service.pocket.stories.api.PocketResponse diff --git a/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketRecommendedStoryTest.kt b/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketRecommendedStoryTest.kt deleted file mode 100644 index 559ae61085d..00000000000 --- a/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketRecommendedStoryTest.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package mozilla.components.service.pocket - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import mozilla.components.service.pocket.helpers.assertClassVisibility -import org.junit.Test -import org.junit.runner.RunWith -import kotlin.reflect.KVisibility - -@RunWith(AndroidJUnit4::class) -class PocketRecommendedStoryTest { - - // This is the domain data type we expose to clients. Needs to be public. - @Test - fun `GIVEN a PocketRecommendedStory THEN its visibility is public`() { - assertClassVisibility(PocketRecommendedStory::class, KVisibility.PUBLIC) - } -} diff --git a/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoriesServiceTest.kt b/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoriesServiceTest.kt index 66a384a68d6..55339bc0dc4 100644 --- a/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoriesServiceTest.kt +++ b/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoriesServiceTest.kt @@ -8,6 +8,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import mozilla.components.concept.fetch.Client +import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory +import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory import mozilla.components.service.pocket.helpers.assertConstructorsVisibility import mozilla.components.service.pocket.spocs.SpocsUseCases import mozilla.components.service.pocket.spocs.SpocsUseCases.DeleteProfile diff --git a/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoryTest.kt b/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoryTest.kt new file mode 100644 index 00000000000..4641d1fa358 --- /dev/null +++ b/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoryTest.kt @@ -0,0 +1,69 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package mozilla.components.service.pocket + +import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory +import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory +import mozilla.components.service.pocket.helpers.assertConstructorsVisibility +import mozilla.components.support.test.mock +import org.junit.Assert.assertEquals +import org.junit.Test +import kotlin.reflect.KVisibility + +class PocketStoryTest { + @Test + fun `GIVEN PocketSponsoredStory THEN it should be publicly available`() { + assertConstructorsVisibility(PocketSponsoredStory::class, KVisibility.PUBLIC) + } + + @Test + fun `GIVEN PocketRecommendedStory THEN it should be publicly available`() { + assertConstructorsVisibility(PocketRecommendedStory::class, KVisibility.PUBLIC) + } + + @Test + fun `GIVEN a PocketRecommendedStory WHEN it's title is accessed from parent THEN it returns the previously set value`() { + val pocketRecommendedStory = PocketRecommendedStory( + title = "testTitle", url = "", imageUrl = "", publisher = "", category = "", timeToRead = 0, timesShown = 0 + ) + + val result = (pocketRecommendedStory as PocketStory).title + + assertEquals("testTitle", result) + } + + @Test + fun `GIVEN a PocketRecommendedStory WHEN it's url is accessed from parent THEN it returns the previously set value`() { + val pocketRecommendedStory = PocketRecommendedStory( + title = "", url = "testUrl", imageUrl = "", publisher = "", category = "", timeToRead = 0, timesShown = 0 + ) + + val result = (pocketRecommendedStory as PocketStory).url + + assertEquals("testUrl", result) + } + + @Test + fun `GIVEN a PocketSponsoredStory WHEN it's title is accessed from parent THEN it returns the previously set value`() { + val pocketRecommendedStory = PocketSponsoredStory( + title = "testTitle", url = "", imageUrl = "", sponsor = "", shim = mock() + ) + + val result = (pocketRecommendedStory as PocketStory).title + + assertEquals("testTitle", result) + } + + @Test + fun `GIVEN a PocketSponsoredStory WHEN it's url is accessed from parent THEN it returns the previously set value`() { + val pocketRecommendedStory = PocketSponsoredStory( + title = "", url = "testUrl", imageUrl = "", sponsor = "", shim = mock() + ) + + val result = (pocketRecommendedStory as PocketStory).url + + assertEquals("testUrl", result) + } +} diff --git a/components/service/pocket/src/test/java/mozilla/components/service/pocket/helpers/PocketTestResources.kt b/components/service/pocket/src/test/java/mozilla/components/service/pocket/helpers/PocketTestResources.kt index 625f6c6656c..7bf53af776a 100644 --- a/components/service/pocket/src/test/java/mozilla/components/service/pocket/helpers/PocketTestResources.kt +++ b/components/service/pocket/src/test/java/mozilla/components/service/pocket/helpers/PocketTestResources.kt @@ -4,7 +4,7 @@ package mozilla.components.service.pocket.helpers -import mozilla.components.service.pocket.PocketRecommendedStory +import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory import mozilla.components.service.pocket.spocs.api.ApiSpoc import mozilla.components.service.pocket.spocs.api.ApiSpocShim import mozilla.components.service.pocket.spocs.db.SpocEntity diff --git a/components/service/pocket/src/test/java/mozilla/components/service/pocket/spocs/SpocsUseCasesTest.kt b/components/service/pocket/src/test/java/mozilla/components/service/pocket/spocs/SpocsUseCasesTest.kt index fafb150193d..64cfd6276ec 100644 --- a/components/service/pocket/src/test/java/mozilla/components/service/pocket/spocs/SpocsUseCasesTest.kt +++ b/components/service/pocket/src/test/java/mozilla/components/service/pocket/spocs/SpocsUseCasesTest.kt @@ -9,7 +9,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import mozilla.components.concept.fetch.Client -import mozilla.components.service.pocket.PocketRecommendedStory +import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory import mozilla.components.service.pocket.helpers.PocketTestResources import mozilla.components.service.pocket.helpers.assertClassVisibility import mozilla.components.service.pocket.spocs.SpocsUseCases.RefreshSponsoredStories diff --git a/components/service/pocket/src/test/java/mozilla/components/service/pocket/stories/PocketStoriesUseCasesTest.kt b/components/service/pocket/src/test/java/mozilla/components/service/pocket/stories/PocketStoriesUseCasesTest.kt index 7c863745b5a..00621d91945 100644 --- a/components/service/pocket/src/test/java/mozilla/components/service/pocket/stories/PocketStoriesUseCasesTest.kt +++ b/components/service/pocket/src/test/java/mozilla/components/service/pocket/stories/PocketStoriesUseCasesTest.kt @@ -9,7 +9,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import mozilla.components.concept.fetch.Client -import mozilla.components.service.pocket.PocketRecommendedStory +import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory import mozilla.components.service.pocket.helpers.PocketTestResources import mozilla.components.service.pocket.helpers.assertClassVisibility import mozilla.components.service.pocket.stories.api.PocketEndpoint diff --git a/docs/changelog.md b/docs/changelog.md index 7979dc9b771..4a18e3030a2 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -11,6 +11,9 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/android-components/blob/main/buildSrc/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/android-components/blob/main/.config.yml) +* **service-pocket** + * Add a new `PocketStory` supertype for all Pocket stories. [#12171](https://github.com/mozilla-mobile/android-components/issues/12171) + * **service-pocket** * 🌟️ Add support for Pocket sponsored stories. * See component's [README](https://github.com/mozilla-mobile/android-components/blob/main/components/service/pocket/README.md) to get more info.