diff --git a/app/src/main/java/org/mozilla/fenix/compose/Image.kt b/app/src/main/java/org/mozilla/fenix/compose/Image.kt index 46d53ec78..d05b10a57 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/Image.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/Image.kt @@ -11,20 +11,14 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import mozilla.components.browser.engine.gecko.fetch.GeckoViewFetchClient -import mozilla.components.concept.fetch.Client -import mozilla.components.concept.fetch.MutableHeaders -import mozilla.components.concept.fetch.Request -import mozilla.components.concept.fetch.Response import mozilla.components.support.images.compose.loader.ImageLoader import mozilla.components.support.images.compose.loader.WithImage +import org.mozilla.fenix.components.components /** * A composable that lays out and draws the image from a given URL while showing a default placeholder * while that image is downloaded or a default fallback image when downloading failed. * - * @param client [Client] instance to be used for downloading the image. - * When using [GeckoViewFetchClient] the image will automatically be cached if it has the right headers. * @param url URL from where the to download the image to be shown. * @param modifier [Modifier] to be applied to the layout. * @param private Whether or not this is a private request. Like in private browsing mode, @@ -37,7 +31,6 @@ import mozilla.components.support.images.compose.loader.WithImage @Composable @Suppress("LongParameterList") fun Image( - client: Client, url: String, modifier: Modifier = Modifier, private: Boolean = false, @@ -46,7 +39,7 @@ fun Image( ) { ImageLoader( url = url, - client = client, + client = components.core.client, private = private, targetSize = targetSize ) { @@ -68,17 +61,7 @@ fun Image( @Preview private fun ImagePreview() { Image( - FakeClient(), "https://mozilla.com", Modifier.height(100.dp).width(200.dp) ) } - -internal class FakeClient : Client() { - override fun fetch(request: Request) = Response( - url = request.url, - status = 200, - body = Response.Body.empty(), - headers = MutableHeaders() - ) -} diff --git a/app/src/main/java/org/mozilla/fenix/compose/ListItemTabLarge.kt b/app/src/main/java/org/mozilla/fenix/compose/ListItemTabLarge.kt index c7836cde8..6d1eb8d77 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/ListItemTabLarge.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/ListItemTabLarge.kt @@ -20,8 +20,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import mozilla.components.browser.engine.gecko.fetch.GeckoViewFetchClient -import mozilla.components.concept.fetch.Client import org.mozilla.fenix.theme.FirefoxTheme /** @@ -37,8 +35,6 @@ import org.mozilla.fenix.theme.FirefoxTheme * --------------------------------------------- * ``` * - * @param client [Client] instance to be used for downloading the image. - * When using [GeckoViewFetchClient] the image will automatically be cached if it has the right headers. * @param imageUrl URL from where the to download a header image of the tab this composable renders. * @param title Title off the tab this composable renders. * @param caption Optional caption text. @@ -46,13 +42,12 @@ import org.mozilla.fenix.theme.FirefoxTheme */ @Composable fun ListItemTabLarge( - client: Client, imageUrl: String, title: String, caption: String? = null, onClick: (() -> Unit)? = null ) { - ListItemTabSurface(client, imageUrl, onClick) { + ListItemTabSurface(imageUrl, onClick) { TabTitle(text = title, maxLines = 3) if (caption != null) { @@ -77,8 +72,6 @@ fun ListItemTabLarge( * --------------------------------------------- * ``` * - * @param client [Client] instance to be used for downloading the image. - * When using [GeckoViewFetchClient] the image will automatically be cached if it has the right headers. * @param imageUrl URL from where the to download a header image of the tab this composable renders. * @param title Composable rendering the title of the tab this composable represents. * @param subtitle Optional tab caption composable. @@ -86,13 +79,12 @@ fun ListItemTabLarge( */ @Composable fun ListItemTabLarge( - client: Client, imageUrl: String, onClick: () -> Unit, title: @Composable () -> Unit, subtitle: @Composable (() -> Unit)? = null ) { - ListItemTabSurface(client, imageUrl, onClick) { + ListItemTabSurface(imageUrl, onClick) { title() subtitle?.invoke() @@ -102,15 +94,12 @@ fun ListItemTabLarge( /** * Shared default configuration of a ListItemTabLarge Composable. * - * @param client [Client] instance to be used for downloading the image. - * When using [GeckoViewFetchClient] the image will automatically be cached if it has the right headers. * @param imageUrl URL from where the to download a header image of the tab this composable renders. * @param onClick Optional callback to be invoked when this composable is clicked. * @param tabDetails [Composable] Displayed to the the end of the image. Allows for variation in the item text style. */ @Composable private fun ListItemTabSurface( - client: Client, imageUrl: String, onClick: (() -> Unit)? = null, tabDetails: @Composable () -> Unit @@ -132,7 +121,7 @@ private fun ListItemTabSurface( .size(imageWidth, imageHeight) .clip(RoundedCornerShape(8.dp)) - Image(client, imageUrl, imageModifier, false, imageWidth) + Image(imageUrl, imageModifier, false, imageWidth) Spacer(Modifier.width(16.dp)) @@ -151,7 +140,6 @@ private fun ListItemTabSurface( private fun ListItemTabLargePreview() { FirefoxTheme { ListItemTabLarge( - client = FakeClient(), imageUrl = "", title = "This is a very long title for a tab but needs to be so for this preview", caption = "And this is a caption" diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlAdapter.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlAdapter.kt index ddacd882d..6f9d299ca 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlAdapter.kt @@ -232,9 +232,8 @@ class SessionControlAdapter( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { when (viewType) { PocketStoriesViewHolder.LAYOUT_ID -> return PocketStoriesViewHolder( - ComposeView(parent.context), - store, - components.core.client, + composeView = ComposeView(parent.context), + store = store, interactor = interactor ) RecentTabViewHolder.LAYOUT_ID -> return RecentTabViewHolder( diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/pocket/PocketStoriesComposables.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/pocket/PocketStoriesComposables.kt index 20b056978..87b63920d 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/pocket/PocketStoriesComposables.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/pocket/PocketStoriesComposables.kt @@ -41,7 +41,6 @@ import mozilla.components.ui.colors.PhotonColors import org.mozilla.fenix.R import org.mozilla.fenix.compose.ClickableSubstringLink import org.mozilla.fenix.compose.EagerFlingBehavior -import org.mozilla.fenix.compose.FakeClient import org.mozilla.fenix.compose.ListItemTabLarge import org.mozilla.fenix.compose.ListItemTabLargePlaceholder import org.mozilla.fenix.compose.SelectableChip @@ -64,13 +63,11 @@ private val placeholderStory = PocketRecommendedStory("", "", "", "", "", 0, 0) * Displays a single [PocketRecommendedStory]. * * @param story The [PocketRecommendedStory] to be displayed. - * @param client [Client] instance to be used for downloading the story header image. * @param onStoryClick Callback for when the user taps on this story. */ @Composable fun PocketStory( @PreviewParameter(PocketStoryProvider::class) story: PocketRecommendedStory, - client: Client, onStoryClick: (PocketRecommendedStory) -> Unit, ) { val imageUrl = story.imageUrl.replace( @@ -80,7 +77,6 @@ fun PocketStory( val isValidPublisher = story.publisher.isNotBlank() val isValidTimeToRead = story.timeToRead >= 0 ListItemTabLarge( - client = client, imageUrl = imageUrl, onClick = { onStoryClick(story) }, title = { @@ -111,7 +107,6 @@ fun PocketStory( @Composable fun PocketStories( @PreviewParameter(PocketStoryProvider::class) stories: List, - client: Client, onExternalLinkClicked: (String) -> Unit ) { // Show stories in at most 3 rows but on any number of columns depending on the data received. @@ -135,7 +130,7 @@ fun PocketStories( onExternalLinkClicked("http://getpocket.com/explore") } } else { - PocketStory(story, client) { + PocketStory(story) { onExternalLinkClicked(story.url) } } @@ -235,7 +230,6 @@ private fun PocketStoriesComposablesPreview() { Column { PocketStories( stories = getFakePocketStories(8), - client = FakeClient(), onExternalLinkClicked = { } ) Spacer(Modifier.height(10.dp)) diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/pocket/PocketStoriesViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/pocket/PocketStoriesViewHolder.kt index 88a58abb7..5f6c7805a 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/pocket/PocketStoriesViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/pocket/PocketStoriesViewHolder.kt @@ -18,7 +18,6 @@ import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.recyclerview.widget.RecyclerView -import mozilla.components.concept.fetch.Client import mozilla.components.lib.state.ext.observeAsComposableState import mozilla.components.service.pocket.PocketRecommendedStory import org.mozilla.fenix.R @@ -35,13 +34,11 @@ internal const val POCKET_CATEGORIES_SELECTED_AT_A_TIME_COUNT = 8 * * @param composeView [ComposeView] which will be populated with Jetpack Compose UI content. * @param store [HomeFragmentStore] containing the list of Pocket stories to be displayed. - * @param client [Client] instance used for the stories header images. * @param interactor [PocketStoriesInteractor] callback for user interaction. */ class PocketStoriesViewHolder( val composeView: ComposeView, val store: HomeFragmentStore, - val client: Client, val interactor: PocketStoriesInteractor ) : RecyclerView.ViewHolder(composeView) { @@ -53,7 +50,6 @@ class PocketStoriesViewHolder( FirefoxTheme { PocketStories( store, - client, interactor::onStoriesShown, interactor::onCategoryClick, interactor::onExternalLinkClicked @@ -70,7 +66,6 @@ class PocketStoriesViewHolder( @Composable fun PocketStories( store: HomeFragmentStore, - client: Client, onStoriesShown: (List) -> Unit, onCategoryClick: (PocketRecommendedStoriesCategory) -> Unit, onExternalLinkClicked: (String) -> Unit @@ -101,7 +96,7 @@ fun PocketStories( Spacer(Modifier.height(17.dp)) - PocketStories(stories ?: emptyList(), client, onExternalLinkClicked) + PocketStories(stories ?: emptyList(), onExternalLinkClicked) Spacer(Modifier.height(24.dp))