Skip to content

Commit

Permalink
Hide LanguageMenuButton automatically when empty (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens authored Oct 1, 2024
1 parent 4ec979e commit 9c3ee28
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* 🐛 Fix `CurrentTimeDisplay` to show the time offset to the live point when playing a live or DVR stream with `showRemaining = true`.
* 💅 Changed `DefaultUi` to hide the current time display when playing a live stream.
* 💅 Changed `DefaultUi` to show the time offset to the live point when playing a DVR stream.
* 💅 Changed `LanguageMenuButton` to automatically hide itself when there are no alternative audio or subtitle tracks to select.

## v1.9.0 (2024-09-10)

Expand Down
4 changes: 2 additions & 2 deletions ui/src/main/java/com/theoplayer/android/ui/LanguageMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ fun MenuScope.LanguageMenu() {
}
}

private fun showAudioTracks(player: Player?): Boolean {
internal fun showAudioTracks(player: Player?): Boolean {
return player != null && player.audioTracks.size >= 2
}

private fun showSubtitleTracks(player: Player?): Boolean {
internal fun showSubtitleTracks(player: Player?): Boolean {
return player != null && player.subtitleTracks.isNotEmpty()
}

Expand Down
12 changes: 11 additions & 1 deletion ui/src/main/java/com/theoplayer/android/ui/LanguageMenuButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ fun MenuScope.LanguageMenuButton(
)
}
) {
val player = Player.current
if (!showLanguageMenuButton(player)) {
// Hide when no alternative audio or subtitle tracks are available
return
}

IconButton(
modifier = modifier,
contentPadding = contentPadding,
onClick = { openMenu { LanguageMenu() } }) {
content()
}
}
}

internal fun showLanguageMenuButton(player: Player?): Boolean {
return showAudioTracks(player) || showSubtitleTracks(player)
}

0 comments on commit 9c3ee28

Please sign in to comment.