Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.onLayoutRectChanged
import androidx.compose.ui.layout.onVisibilityChanged
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -456,11 +457,19 @@ private fun DancingBot(
dancingBotLink: String?,
modifier: Modifier,
) {
AsyncImage(
model = dancingBotLink,
modifier = modifier,
contentDescription = null,
)
if (LocalInspectionMode.current) {
Image(
painter = painterResource(id = R.drawable.dancing_droid_gif_placeholder),
contentDescription = null,
modifier = modifier
)
Comment on lines +460 to +465
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider extracting the Image composable into a separate function for better readability and maintainability. This would encapsulate the placeholder logic and make the DancingBot function cleaner.

@Composable
private fun DancingBotPlaceholder(modifier: Modifier = Modifier) {
    Image(
        painter = painterResource(id = R.drawable.dancing_droid_gif_placeholder),
        contentDescription = null,
        modifier = modifier
    )
}

// Usage in DancingBot:
if (LocalInspectionMode.current) {
    DancingBotPlaceholder(modifier = modifier)
}

} else {
AsyncImage(
model = dancingBotLink,
modifier = modifier,
contentDescription = null,
)
}
}

@Composable
Expand Down Expand Up @@ -520,23 +529,31 @@ private fun VideoPlayer(
videoLink: String?,
modifier: Modifier = Modifier,
) {
if (LocalInspectionMode.current) return // Layoutlib does not support ExoPlayer

val context = LocalContext.current
var player by remember { mutableStateOf<Player?>(null) }
LifecycleStartEffect(videoLink) {
if (videoLink != null) {
player = ExoPlayer.Builder(context).build().apply {
setMediaItem(MediaItem.fromUri(videoLink))
repeatMode = Player.REPEAT_MODE_ONE
prepare()
if (LocalInspectionMode.current) {
Image(
painter = painterResource(id = R.drawable.promo_video_placeholder),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = modifier,
)
return
Comment on lines +532 to +539
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider extracting the Image composable into a separate function for better readability and maintainability. This would encapsulate the placeholder logic and make the VideoPlayer function cleaner.

@Composable
private fun VideoPlaceholder(modifier: Modifier = Modifier) {
    Image(
        painter = painterResource(id = R.drawable.promo_video_placeholder),
        contentDescription = null,
        contentScale = ContentScale.Crop,
        modifier = modifier,
    )
}

// Usage in VideoPlayer:
if (LocalInspectionMode.current) {
    VideoPlaceholder(modifier = modifier)
    return
}

} else {
val context = LocalContext.current
var player by remember { mutableStateOf<Player?>(null) }
LifecycleStartEffect(videoLink) {
if (videoLink != null) {
player = ExoPlayer.Builder(context).build().apply {
setMediaItem(MediaItem.fromUri(videoLink))
repeatMode = Player.REPEAT_MODE_ONE
prepare()
}
}
onStopOrDispose {
player?.release()
player = null
}
}
onStopOrDispose {
player?.release()
player = null
}
}


var videoFullyOnScreen by remember { mutableStateOf(false) }
val isWindowOccluded = LocalOcclusion.current
Expand Down Expand Up @@ -582,3 +599,4 @@ private fun VideoPlayer(
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.