mirror of
https://github.com/NeoApplications/Neo-Store.git
synced 2025-03-15 19:30:05 +00:00
Add: Video view beside the screen shots when available (closes #703)
This commit is contained in:
src/main/kotlin/com/machiav3lli/fdroid/ui
@ -1,16 +1,24 @@
|
||||
package com.machiav3lli.fdroid.ui.components
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.requiredHeight
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
@ -18,6 +26,8 @@ import androidx.compose.ui.unit.dp
|
||||
import com.machiav3lli.fdroid.data.database.entity.Repository
|
||||
import com.machiav3lli.fdroid.data.entity.Screenshot
|
||||
import com.machiav3lli.fdroid.manager.network.createScreenshotUri
|
||||
import com.machiav3lli.fdroid.ui.compose.icons.Phosphor
|
||||
import com.machiav3lli.fdroid.ui.compose.icons.phosphor.PlayCircle
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@ -32,15 +42,39 @@ fun Screenshot.toScreenshotItem(packageName: String, repository: Repository) =
|
||||
|
||||
@Composable
|
||||
fun ScreenshotList(
|
||||
modifier: Modifier = Modifier,
|
||||
screenShots: List<ScreenshotItem>,
|
||||
video: String = "",
|
||||
modifier: Modifier = Modifier,
|
||||
onUriClick: (Uri) -> Unit,
|
||||
onScreenShotClick: (Int) -> Unit,
|
||||
) {
|
||||
LazyRow(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
itemsIndexed(screenShots) { index, it ->
|
||||
if (video.isNotEmpty()) item(key = "video") {
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.height(250.dp)
|
||||
.aspectRatio(9 / 20f),
|
||||
shape = MaterialTheme.shapes.large,
|
||||
color = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||
contentColor = MaterialTheme.colorScheme.onSurface,
|
||||
onClick = { onUriClick(Uri.parse(video)) },
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Icon(
|
||||
Phosphor.PlayCircle,
|
||||
contentDescription = "Play video",
|
||||
modifier = Modifier.size(72.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
itemsIndexed(screenShots, key = { _, it -> it.screenShot.toString() }) { index, it ->
|
||||
val image by produceState<String?>(initialValue = null, it) {
|
||||
launch(Dispatchers.IO) {
|
||||
value = createScreenshotUri(
|
||||
|
@ -560,7 +560,11 @@ fun AppPage(
|
||||
}
|
||||
if (enableScreenshots) { // TODO add optional screenshots button
|
||||
item {
|
||||
ScreenshotList(screenShots = screenshots) { index ->
|
||||
ScreenshotList(
|
||||
screenShots = screenshots,
|
||||
video = product.video,
|
||||
onUriClick = { onUriClick(it, true) },
|
||||
) { index ->
|
||||
screenshotPage = index
|
||||
showScreenshots.value = true
|
||||
}
|
||||
|
Reference in New Issue
Block a user