forked from mozilla-mobile/fenix
-
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.
For mozilla-mobile#21894: Move Tabs Tray to compose: Individual tab v…
…iewholders: ListViewHolder.
- Loading branch information
Showing
20 changed files
with
748 additions
and
89 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
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
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
84 changes: 84 additions & 0 deletions
84
app/src/main/java/org/mozilla/fenix/compose/tabstray/MediaImage.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,84 @@ | ||
/* 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 org.mozilla.fenix.compose.tabstray | ||
|
||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material.Card | ||
import androidx.compose.material.Icon | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
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.concept.engine.mediasession.MediaSession.PlaybackState | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.theme.FirefoxTheme | ||
|
||
/** | ||
* A composable that lays out and draws the image from a given [tab] while showing a default placeholder | ||
* while that image is downloaded or a default fallback image when downloading failed. | ||
* | ||
* @param tab the tab which the image should be shown. | ||
* @param onMediaIconClicked handles the click event when tab has media session like play/pause. | ||
* @param modifier [Modifier] to be applied to the layout. | ||
*/ | ||
@Composable | ||
fun MediaImage( | ||
tab: TabSessionState, | ||
onMediaIconClicked: ((TabSessionState) -> Unit), | ||
modifier: Modifier, | ||
) { | ||
val (icon, contentDescription) = when (tab.mediaSessionState?.playbackState) { | ||
PlaybackState.PAUSED -> { | ||
R.drawable.media_state_play_vector to R.string.mozac_feature_media_notification_action_play | ||
} | ||
PlaybackState.PLAYING -> { | ||
R.drawable.media_state_pause_vector to R.string.mozac_feature_media_notification_action_pause | ||
} | ||
else -> return | ||
} | ||
|
||
Card( | ||
modifier = modifier | ||
.size(size = 24.dp) | ||
.clip(shape = CircleShape) | ||
.border( | ||
width = 2.dp, | ||
color = FirefoxTheme.colors.layer2, | ||
shape = CircleShape | ||
), | ||
backgroundColor = FirefoxTheme.colors.layerAccent | ||
) { | ||
Icon( | ||
painter = painterResource(id = icon), | ||
modifier = Modifier | ||
.size(size = 24.dp) | ||
.clickable { onMediaIconClicked.invoke(tab) }, | ||
contentDescription = stringResource(id = contentDescription), | ||
tint = FirefoxTheme.colors.borderPrimary | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview | ||
private fun ImagePreview() { | ||
MediaImage( | ||
tab = createTab(url = "https://mozilla.com"), | ||
onMediaIconClicked = {}, | ||
modifier = Modifier | ||
.height(100.dp) | ||
.width(200.dp) | ||
) | ||
} |
Oops, something went wrong.