Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Bug 1876594 - Refactor ThumbnailStorage to be an implicit dependency #5577

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.thumbnails.storage.ThumbnailStorage
import mozilla.components.concept.base.images.ImageLoadRequest
import org.mozilla.fenix.theme.FirefoxTheme

Expand All @@ -32,7 +30,6 @@ private const val FALLBACK_ICON_SIZE = 36
* will be displayed until the thumbnail is loaded.
*
* @param tab The given [TabSessionState] to render a thumbnail for.
* @param storage [ThumbnailStorage] to obtain tab thumbnail bitmaps from.
* @param size Size of the thumbnail.
* @param modifier [Modifier] used to draw the image content.
* @param backgroundColor [Color] used for the background of the favicon.
Expand All @@ -44,7 +41,6 @@ private const val FALLBACK_ICON_SIZE = 36
@Composable
fun TabThumbnail(
tab: TabSessionState,
storage: ThumbnailStorage,
size: Int,
modifier: Modifier = Modifier,
backgroundColor: Color = FirefoxTheme.colors.layer2,
Expand All @@ -62,8 +58,6 @@ fun TabThumbnail(
size = size,
isPrivate = tab.content.private,
),
storage = storage,
modifier = modifier,
contentScale = contentScale,
alignment = alignment,
) {
Expand Down Expand Up @@ -100,7 +94,6 @@ private fun ThumbnailCardPreview() {
TabThumbnail(
tab = createTab(url = "www.mozilla.com", title = "Mozilla"),
size = 108,
storage = ThumbnailStorage(LocalContext.current),
modifier = Modifier
.size(108.dp, 80.dp)
.clip(RoundedCornerShape(8.dp)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import mozilla.components.browser.icons.compose.Loader
import mozilla.components.browser.icons.compose.Placeholder
import mozilla.components.browser.icons.compose.WithIcon
import mozilla.components.browser.thumbnails.storage.ThumbnailStorage
import mozilla.components.concept.base.images.ImageLoadRequest
import org.mozilla.fenix.components.components
import org.mozilla.fenix.theme.FirefoxTheme
Expand All @@ -36,7 +34,6 @@ private const val FALLBACK_ICON_SIZE = 36
*
* @param url Url to display thumbnail for.
* @param request [ImageLoadRequest] used to fetch the thumbnail bitmap.
* @param storage [ThumbnailStorage] to obtain tab thumbnail bitmaps from.
* @param modifier [Modifier] used to draw the image content.
* @param backgroundColor [Color] used for the background of the favicon.
* @param contentDescription Text used by accessibility services
Expand All @@ -48,7 +45,6 @@ private const val FALLBACK_ICON_SIZE = 36
fun ThumbnailCard(
url: String,
request: ImageLoadRequest,
storage: ThumbnailStorage,
modifier: Modifier = Modifier,
backgroundColor: Color = FirefoxTheme.colors.layer2,
contentDescription: String? = null,
Expand All @@ -61,8 +57,6 @@ fun ThumbnailCard(
) {
ThumbnailImage(
request = request,
storage = storage,
modifier = modifier,
contentScale = contentScale,
alignment = alignment,
) {
Expand Down Expand Up @@ -98,7 +92,6 @@ private fun ThumbnailCardPreview() {
ThumbnailCard(
url = "https://mozilla.com",
request = ImageLoadRequest("123", THUMBNAIL_SIZE, false),
storage = ThumbnailStorage(LocalContext.current),
modifier = Modifier
.size(THUMBNAIL_SIZE.dp)
.clip(RoundedCornerShape(8.dp)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.graphics.Bitmap
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
Expand All @@ -20,37 +21,36 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import mozilla.components.browser.thumbnails.storage.ThumbnailStorage
import mozilla.components.concept.base.images.ImageLoadRequest
import org.mozilla.fenix.components.components
import org.mozilla.fenix.theme.FirefoxTheme

/**
* Thumbnail belonging to a [ImageLoadRequest]. Asynchronously fetches the bitmap from storage.
*
* @param request [ImageLoadRequest] used to fetch the thumbnail bitmap.
* @param storage [ThumbnailStorage] to obtain tab thumbnail bitmaps from.
* @param modifier [Modifier] used to draw the image content.
* @param contentScale [ContentScale] used to draw image content.
* @param alignment [Alignment] used to draw the image content.
* @param modifier [Modifier] used to draw the image content.
* @param fallbackContent The content to display with a thumbnail is unable to be loaded.
*/
@Composable
fun ThumbnailImage(
request: ImageLoadRequest,
storage: ThumbnailStorage,
modifier: Modifier,
contentScale: ContentScale,
alignment: Alignment,
modifier: Modifier = Modifier,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just some unrelated bookkeeping? Fine with me if so, just checking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Modifiers are supposed to be optional, so I opted to include that minor change now

fallbackContent: @Composable () -> Unit,
) {
if (inComposePreview) {
Box(modifier = Modifier.background(color = FirefoxTheme.colors.layer3))
Box(modifier = modifier.background(color = FirefoxTheme.colors.layer3))
} else {
var state by remember { mutableStateOf(ThumbnailImageState(null, false)) }
val scope = rememberCoroutineScope()
val storage = components.core.thumbnailStorage

DisposableEffect(Unit) {
if (!state.hasLoaded) {
Expand Down Expand Up @@ -102,15 +102,14 @@ private data class ThumbnailImageState(

/**
* This preview does not demo anything. This is to ensure that [ThumbnailImage] does not break other previews.
*/
*/
@Preview
@Composable
private fun ThumbnailImagePreview() {
FirefoxTheme {
ThumbnailImage(
request = ImageLoadRequest("1", 1, false),
storage = ThumbnailStorage(LocalContext.current),
modifier = Modifier,
modifier = Modifier.size(50.dp),
contentScale = ContentScale.Crop,
alignment = Alignment.Center,
fallbackContent = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.dimensionResource
Expand All @@ -58,7 +57,6 @@ import androidx.compose.ui.zIndex
import androidx.core.text.BidiFormatter
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.thumbnails.storage.ThumbnailStorage
import mozilla.components.support.ktx.kotlin.MAX_URI_LENGTH
import mozilla.components.ui.colors.PhotonColors
import org.mozilla.fenix.R
Expand All @@ -76,7 +74,6 @@ import org.mozilla.fenix.theme.FirefoxTheme
* long clicks, multiple selection, and media controls.
*
* @param tab The given tab to be render as view a grid item.
* @param storage [ThumbnailStorage] to obtain tab thumbnail bitmaps from.
* @param thumbnailSize Size of tab's thumbnail.
* @param isSelected Indicates if the item should be render as selected.
* @param multiSelectionEnabled Indicates if the item should be render with multi selection options,
Expand All @@ -94,7 +91,6 @@ import org.mozilla.fenix.theme.FirefoxTheme
@Suppress("MagicNumber", "LongMethod")
fun TabGridItem(
tab: TabSessionState,
storage: ThumbnailStorage,
thumbnailSize: Int,
isSelected: Boolean = false,
multiSelectionEnabled: Boolean = false,
Expand Down Expand Up @@ -243,7 +239,6 @@ fun TabGridItem(
Thumbnail(
tab = tab,
size = thumbnailSize,
storage = storage,
multiSelectionSelected = multiSelectionSelected,
)
}
Expand Down Expand Up @@ -273,14 +268,12 @@ private fun clickableColor() = when (isSystemInDarkTheme()) {
*
* @param tab Tab, containing the thumbnail to be displayed.
* @param size Size of the thumbnail.
* @param storage [ThumbnailStorage] to obtain tab thumbnail bitmaps from.
* @param multiSelectionSelected Whether or not the multiple selection is enabled.
*/
@Composable
private fun Thumbnail(
tab: TabSessionState,
size: Int,
storage: ThumbnailStorage,
multiSelectionSelected: Boolean,
) {
Box(
Expand All @@ -294,7 +287,6 @@ private fun Thumbnail(
TabThumbnail(
tab = tab,
size = size,
storage = storage,
modifier = Modifier.fillMaxSize(),
)

Expand Down Expand Up @@ -335,7 +327,6 @@ private fun TabGridItemPreview() {
title = "Mozilla Domain",
),
thumbnailSize = 108,
storage = ThumbnailStorage(LocalContext.current),
onCloseClick = {},
onMediaClick = {},
onClick = {},
Expand All @@ -350,7 +341,6 @@ private fun TabGridItemSelectedPreview() {
TabGridItem(
tab = createTab(url = "www.mozilla.com", title = "Mozilla"),
thumbnailSize = 108,
storage = ThumbnailStorage(LocalContext.current),
isSelected = true,
onCloseClick = {},
onMediaClick = {},
Expand All @@ -367,7 +357,6 @@ private fun TabGridItemMultiSelectedPreview() {
TabGridItem(
tab = createTab(url = "www.mozilla.com", title = "Mozilla"),
thumbnailSize = 108,
storage = ThumbnailStorage(LocalContext.current),
multiSelectionEnabled = true,
multiSelectionSelected = true,
onCloseClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
Expand All @@ -43,7 +42,6 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.thumbnails.storage.ThumbnailStorage
import mozilla.components.support.ktx.kotlin.MAX_URI_LENGTH
import mozilla.components.ui.colors.PhotonColors
import org.mozilla.fenix.R
Expand All @@ -60,7 +58,6 @@ import org.mozilla.fenix.theme.FirefoxTheme
* long clicks, multiselection, and media controls.
*
* @param tab The given tab to be render as view a grid item.
* @param storage [ThumbnailStorage] to obtain tab thumbnail bitmaps from.
* @param thumbnailSize Size of tab's thumbnail.
* @param isSelected Indicates if the item should be render as selected.
* @param multiSelectionEnabled Indicates if the item should be render with multi selection options,
Expand All @@ -78,7 +75,6 @@ import org.mozilla.fenix.theme.FirefoxTheme
@Suppress("MagicNumber", "LongMethod")
fun TabListItem(
tab: TabSessionState,
storage: ThumbnailStorage,
thumbnailSize: Int,
isSelected: Boolean = false,
multiSelectionEnabled: Boolean = false,
Expand Down Expand Up @@ -150,7 +146,6 @@ fun TabListItem(
Thumbnail(
tab = tab,
size = thumbnailSize,
storage = storage,
multiSelectionEnabled = multiSelectionEnabled,
isSelected = multiSelectionSelected,
onMediaIconClicked = { onMediaClick(it) },
Expand Down Expand Up @@ -212,7 +207,6 @@ private fun clickableColor() = when (isSystemInDarkTheme()) {
private fun Thumbnail(
tab: TabSessionState,
size: Int,
storage: ThumbnailStorage,
multiSelectionEnabled: Boolean,
isSelected: Boolean,
onMediaIconClicked: ((TabSessionState) -> Unit),
Expand All @@ -222,7 +216,6 @@ private fun Thumbnail(
TabThumbnail(
tab = tab,
size = size,
storage = storage,
modifier = Modifier
.size(width = 92.dp, height = 72.dp)
.semantics(mergeDescendants = true) {
Expand Down Expand Up @@ -275,7 +268,6 @@ private fun TabListItemPreview() {
TabListItem(
tab = createTab(url = "www.mozilla.com", title = "Mozilla"),
thumbnailSize = 108,
storage = ThumbnailStorage(LocalContext.current),
onCloseClick = {},
onMediaClick = {},
onClick = {},
Expand All @@ -290,7 +282,6 @@ private fun SelectedTabListItemPreview() {
TabListItem(
tab = createTab(url = "www.mozilla.com", title = "Mozilla"),
thumbnailSize = 108,
storage = ThumbnailStorage(LocalContext.current),
onCloseClick = {},
onMediaClick = {},
onClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import mozilla.components.browser.thumbnails.storage.ThumbnailStorage
import mozilla.components.concept.base.images.ImageLoadRequest
import mozilla.components.concept.sync.DeviceType
import mozilla.components.support.ktx.kotlin.trimmed
Expand All @@ -60,7 +58,6 @@ private const val THUMBNAIL_SIZE = 108
* A recent synced tab card.
*
* @param tab The [RecentSyncedTab] to display.
* @param storage [ThumbnailStorage] to obtain tab thumbnail bitmaps from.
* @param backgroundColor The background [Color] of the item.
* @param buttonBackgroundColor The background [Color] of the item's button.
* @param buttonTextColor The [Color] of the button's text.
Expand All @@ -73,7 +70,6 @@ private const val THUMBNAIL_SIZE = 108
@Composable
fun RecentSyncedTab(
tab: RecentSyncedTab?,
storage: ThumbnailStorage,
backgroundColor: Color = FirefoxTheme.colors.layer2,
buttonBackgroundColor: Color = FirefoxTheme.colors.actionSecondary,
buttonTextColor: Color = FirefoxTheme.colors.textActionSecondary,
Expand Down Expand Up @@ -122,7 +118,6 @@ fun RecentSyncedTab(
size = LocalDensity.current.run { THUMBNAIL_SIZE.dp.toPx().toInt() },
isPrivate = false,
),
storage = storage,
modifier = imageModifier,
)
}
Expand Down Expand Up @@ -259,7 +254,6 @@ private fun LoadedRecentSyncedTab() {
FirefoxTheme {
RecentSyncedTab(
tab = tab,
storage = ThumbnailStorage(LocalContext.current),
onRecentSyncedTabClick = {},
onSeeAllSyncedTabsButtonClick = {},
onRemoveSyncedTab = {},
Expand All @@ -273,7 +267,6 @@ private fun LoadingRecentSyncedTab() {
FirefoxTheme {
RecentSyncedTab(
tab = null,
storage = ThumbnailStorage(LocalContext.current),
buttonBackgroundColor = FirefoxTheme.colors.layer3,
onRecentSyncedTabClick = {},
onSeeAllSyncedTabsButtonClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class RecentSyncedTabViewHolder(

RecentSyncedTab(
tab = syncedTab,
storage = components.core.thumbnailStorage,
backgroundColor = wallpaperState.wallpaperCardColor,
buttonBackgroundColor = buttonBackgroundColor,
buttonTextColor = buttonTextColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class RecentTabViewHolder(

RecentTabs(
recentTabs = recentTabs.value ?: emptyList(),
storage = components.core.thumbnailStorage,
backgroundColor = wallpaperState.wallpaperCardColor,
onRecentTabClick = { recentTabInteractor.onRecentTabClicked(it) },
menuItems = listOf(
Expand Down
Loading
Loading