From 9c3ee28443cf69816205f415ac05b701bdb249e6 Mon Sep 17 00:00:00 2001 From: Mattias Buelens <649348+MattiasBuelens@users.noreply.github.com> Date: Tue, 1 Oct 2024 14:22:04 +0200 Subject: [PATCH] Hide LanguageMenuButton automatically when empty (#45) --- CHANGELOG.md | 1 + .../java/com/theoplayer/android/ui/LanguageMenu.kt | 4 ++-- .../com/theoplayer/android/ui/LanguageMenuButton.kt | 12 +++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 500b407..0c77440 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/ui/src/main/java/com/theoplayer/android/ui/LanguageMenu.kt b/ui/src/main/java/com/theoplayer/android/ui/LanguageMenu.kt index fc1635a..911aa18 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/LanguageMenu.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/LanguageMenu.kt @@ -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() } diff --git a/ui/src/main/java/com/theoplayer/android/ui/LanguageMenuButton.kt b/ui/src/main/java/com/theoplayer/android/ui/LanguageMenuButton.kt index 7cb6f85..99f5836 100644 --- a/ui/src/main/java/com/theoplayer/android/ui/LanguageMenuButton.kt +++ b/ui/src/main/java/com/theoplayer/android/ui/LanguageMenuButton.kt @@ -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() } -} \ No newline at end of file +} + +internal fun showLanguageMenuButton(player: Player?): Boolean { + return showAudioTracks(player) || showSubtitleTracks(player) +}