Skip to content

Commit

Permalink
make it partially possible to display the available languages
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Oct 17, 2024
1 parent 8d099d3 commit ccb429c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data class VideoStreamTrack(
) : StreamTrack {

override fun toShortIdentifierString() =
"${if (width < height) width else height}p${if (frameRate != 30) frameRate else ""}"
"${if (width < height) width else height}p${if (frameRate > 30) frameRate else ""}"

override fun toLongIdentifierString() = "$fileFormat ${toShortIdentifierString()}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.R
import net.newpipe.newplayer.logic.TrackUtils
import net.newpipe.newplayer.uiModel.EmbeddedUiConfig
import net.newpipe.newplayer.uiModel.NewPlayerUIState
import net.newpipe.newplayer.uiModel.InternalNewPlayerViewModel
Expand All @@ -62,11 +63,13 @@ import net.newpipe.newplayer.uiModel.UIModeState
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.ui.videoplayer.pip.supportsPip
import net.newpipe.newplayer.ui.common.getEmbeddedUiConfig
import java.util.Locale

@OptIn(UnstableApi::class)
@Composable
internal fun VideoPlayerMenu(viewModel: InternalNewPlayerViewModel, uiState: NewPlayerUIState) {
var showMainMenu: Boolean by remember { mutableStateOf(false) }
var showLanguageMenu: Boolean by remember { mutableStateOf(false) }

val pixel_density = LocalDensity.current

Expand All @@ -79,6 +82,8 @@ internal fun VideoPlayerMenu(viewModel: InternalNewPlayerViewModel, uiState: New
else
EmbeddedUiConfig.DUMMY

val availableLanguages = TrackUtils.getAvailableLanguages(uiState.currentlyAvailableTracks)

Box {
IconButton(onClick = {
showMainMenu = true
Expand All @@ -99,8 +104,10 @@ internal fun VideoPlayerMenu(viewModel: InternalNewPlayerViewModel, uiState: New
expanded = showMainMenu,
onDismissRequest = {
showMainMenu = false
viewModel.dialogVisible(false)
if (!showLanguageMenu)
viewModel.dialogVisible(false)
}) {

DropdownMenuItem(text = { Text(stringResource(R.string.menu_item_open_in_browser)) },
leadingIcon = {
Icon(
Expand Down Expand Up @@ -142,7 +149,7 @@ internal fun VideoPlayerMenu(viewModel: InternalNewPlayerViewModel, uiState: New
)
})
}
if(uiState.uiMode.fullscreen) {
if (uiState.uiMode.fullscreen) {
DropdownMenuItem(text = { Text(stringResource(R.string.menu_item_fit_screen)) },
leadingIcon = {
Icon(
Expand All @@ -160,15 +167,36 @@ internal fun VideoPlayerMenu(viewModel: InternalNewPlayerViewModel, uiState: New
)
},
onClick = { /*TODO*/ showMainMenu = false })
DropdownMenuItem(text = { Text(stringResource(R.string.menu_item_language)) },
leadingIcon = {
Icon(
imageVector = Icons.Filled.Translate,
contentDescription = stringResource(R.string.menu_item_language)
)
},
onClick = { /*TODO*/ showMainMenu = false })
if (2 <= availableLanguages.size) {
DropdownMenuItem(text = { Text(stringResource(R.string.menu_item_language)) },
leadingIcon = {
Icon(
imageVector = Icons.Filled.Translate,
contentDescription = stringResource(R.string.menu_item_language)
)
},
onClick = {
showLanguageMenu = true
showMainMenu = false
})
}
}

DropdownMenu(expanded = showLanguageMenu, onDismissRequest = {
showLanguageMenu = false
viewModel.dialogVisible(false)
}) {
for (language in availableLanguages) {
val locale = Locale(language)

DropdownMenuItem(
text = {
Text(locale.displayLanguage)
},
onClick = { /*TODO*/ showLanguageMenu = false
viewModel.dialogVisible(false)
})
}
}
}

Expand Down

0 comments on commit ccb429c

Please sign in to comment.