1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-09 08:50:34 +00:00

Improved stream components

This commit is contained in:
Isira Seneviratne 2024-07-28 09:46:21 +05:30
parent b443abbd8b
commit 06a5828bbe
6 changed files with 53 additions and 16 deletions

View File

@ -69,7 +69,7 @@ fun StreamCardItem(
}
if (isSelected) {
StreamMenu(onDismissPopup)
StreamMenu(stream, onDismissPopup)
}
}
}

View File

@ -15,6 +15,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.ui.theme.AppTheme
@ -24,6 +25,7 @@ import org.schabi.newpipe.ui.theme.AppTheme
fun StreamGridItem(
stream: StreamInfoItem,
isSelected: Boolean = false,
isMini: Boolean = false,
onClick: (StreamInfoItem) -> Unit = {},
onLongClick: (StreamInfoItem) -> Unit = {},
onDismissPopup: () -> Unit = {}
@ -37,10 +39,9 @@ fun StreamGridItem(
)
.padding(12.dp)
) {
StreamThumbnail(
modifier = Modifier.size(width = 246.dp, height = 138.dp),
stream = stream
)
val size = if (isMini) DpSize(150.dp, 85.dp) else DpSize(246.dp, 138.dp)
StreamThumbnail(modifier = Modifier.size(size), stream = stream)
Text(
text = stream.name,
@ -58,7 +59,7 @@ fun StreamGridItem(
}
if (isSelected) {
StreamMenu(onDismissPopup)
StreamMenu(stream, onDismissPopup)
}
}
}

View File

@ -7,6 +7,7 @@ import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@ -16,6 +17,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.fragment.app.FragmentActivity
import androidx.paging.compose.LazyPagingItems
import androidx.window.core.layout.WindowWidthSizeClass
import my.nanihadesuka.compose.LazyColumnScrollbar
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
import org.schabi.newpipe.extractor.stream.StreamInfoItem
@ -58,13 +60,17 @@ fun StreamList(
val gridState = rememberLazyGridState()
LazyVerticalGridScrollbar(state = gridState) {
LazyVerticalGrid(state = gridState, columns = GridCells.Adaptive(250.dp)) {
val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass
val isCompact = windowSizeClass.windowWidthSizeClass == WindowWidthSizeClass.COMPACT
val minSize = if (isCompact) 150.dp else 250.dp
LazyVerticalGrid(state = gridState, columns = GridCells.Adaptive(minSize)) {
gridHeader()
items(streams.itemCount) {
val stream = streams[it]!!
StreamGridItem(
stream, selectedStream == stream, onClick, onLongClick,
stream, selectedStream == stream, isCompact, onClick, onLongClick,
onDismissPopup
)
}

View File

@ -67,7 +67,7 @@ fun StreamListItem(
}
if (isSelected) {
StreamMenu(onDismissPopup)
StreamMenu(stream, onDismissPopup)
}
}
}

View File

@ -4,11 +4,24 @@ import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.fragment.app.FragmentActivity
import org.schabi.newpipe.R
import org.schabi.newpipe.download.DownloadDialog
import org.schabi.newpipe.extractor.stream.StreamInfo
import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.util.SparseItemUtil
import org.schabi.newpipe.util.external_communication.ShareUtils
@Composable
fun StreamMenu(onDismissRequest: () -> Unit) {
fun StreamMenu(
stream: StreamInfoItem,
onDismissRequest: () -> Unit
) {
val context = LocalContext.current
// TODO: Implement remaining click actions
DropdownMenu(expanded = true, onDismissRequest = onDismissRequest) {
DropdownMenuItem(
text = { Text(text = stringResource(R.string.start_here_on_background)) },
@ -20,7 +33,15 @@ fun StreamMenu(onDismissRequest: () -> Unit) {
)
DropdownMenuItem(
text = { Text(text = stringResource(R.string.download)) },
onClick = onDismissRequest
onClick = {
SparseItemUtil.fetchStreamInfoAndSaveToDatabase(
context, stream.serviceId, stream.url
) { info: StreamInfo ->
val downloadDialog = DownloadDialog(context, info)
val fragmentManager = (context as FragmentActivity).supportFragmentManager
downloadDialog.show(fragmentManager, "downloadDialog")
}
}
)
DropdownMenuItem(
text = { Text(text = stringResource(R.string.add_to_playlist)) },
@ -28,11 +49,11 @@ fun StreamMenu(onDismissRequest: () -> Unit) {
)
DropdownMenuItem(
text = { Text(text = stringResource(R.string.share)) },
onClick = onDismissRequest
onClick = { ShareUtils.shareText(context, stream.name, stream.url, stream.thumbnails) }
)
DropdownMenuItem(
text = { Text(text = stringResource(R.string.open_in_browser)) },
onClick = onDismissRequest
onClick = { ShareUtils.openUrlInBrowser(context, stream.url) }
)
DropdownMenuItem(
text = { Text(text = stringResource(R.string.mark_as_watched)) },

View File

@ -11,11 +11,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.util.Localization
import org.schabi.newpipe.util.StreamTypeUtil
import org.schabi.newpipe.util.image.ImageStrategy
@Composable
@ -34,12 +36,19 @@ fun StreamThumbnail(
modifier = modifier
)
val isLive = StreamTypeUtil.isLiveStream(stream.streamType)
val background = if (isLive) Color.Red else Color.Black
Text(
text = Localization.getDurationString(stream.duration),
text = if (isLive) {
stringResource(R.string.duration_live)
} else {
Localization.getDurationString(stream.duration)
},
color = Color.White,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(2.dp)
.background(Color.Black.copy(alpha = 0.5f))
modifier = Modifier
.padding(2.dp)
.background(background.copy(alpha = 0.5f))
)
}
}