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 new file mode 100644 index 00000000000..98e99f3d5af --- /dev/null +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketRecommendedStory.kt @@ -0,0 +1,26 @@ +/* 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 new file mode 100644 index 00000000000..6c5b382420f --- /dev/null +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketSponsoredStory.kt @@ -0,0 +1,35 @@ +/* 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 50d0377a988..621655bd56f 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,8 +6,6 @@ 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 deleted file mode 100644 index d8b03353a77..00000000000 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStory.kt +++ /dev/null @@ -1,71 +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 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 b660f658353..7b318e010e3 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.PocketStory.PocketRecommendedStory -import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory -import mozilla.components.service.pocket.PocketStory.PocketSponsoredStoryShim +import mozilla.components.service.pocket.PocketRecommendedStory +import mozilla.components.service.pocket.PocketSponsoredStory +import mozilla.components.service.pocket.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 8f6a6d3ff71..bd45f548169 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.PocketStory.PocketSponsoredStory +import mozilla.components.service.pocket.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 bd870aa146a..459553326ca 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.PocketStory.PocketSponsoredStory +import mozilla.components.service.pocket.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 1589415702a..a74d3f42470 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.PocketStory.PocketRecommendedStory +import mozilla.components.service.pocket.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 77207b8741f..52cadd9ffbc 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.PocketStory.PocketRecommendedStory +import mozilla.components.service.pocket.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 new file mode 100644 index 00000000000..559ae61085d --- /dev/null +++ b/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketRecommendedStoryTest.kt @@ -0,0 +1,21 @@ +/* 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 55339bc0dc4..66a384a68d6 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,8 +8,6 @@ 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 deleted file mode 100644 index 4641d1fa358..00000000000 --- a/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoryTest.kt +++ /dev/null @@ -1,69 +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 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 7bf53af776a..625f6c6656c 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.PocketStory.PocketRecommendedStory +import mozilla.components.service.pocket.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 64cfd6276ec..fafb150193d 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.PocketStory.PocketRecommendedStory +import mozilla.components.service.pocket.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 00621d91945..7c863745b5a 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.PocketStory.PocketRecommendedStory +import mozilla.components.service.pocket.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 4a18e3030a2..7979dc9b771 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -11,9 +11,6 @@ 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.