Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix items not getting checked in bitrate selection popup #941

Merged
merged 1 commit into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class JellyfinMediaSource(
val item: BaseItemDto?,
val sourceInfo: MediaSourceInfo,
val playSessionId: String,
val maxStreamingBitrate: Int?,
private var startTimeTicks: Long? = null,
audioStreamIndex: Int? = null,
subtitleStreamIndex: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class MediaSourceResolver(private val apiClient: ApiClient) {
item = item,
sourceInfo = mediaSourceInfo,
playSessionId = playSessionId,
maxStreamingBitrate = maxStreamingBitrate,
startTimeTicks = startTimeTicks,
audioStreamIndex = audioStreamIndex,
subtitleStreamIndex = subtitleStreamIndex,
Expand Down
25 changes: 15 additions & 10 deletions app/src/main/java/org/jellyfin/mobile/player/ui/PlayerMenus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import android.widget.PopupMenu
import android.widget.TextView
import androidx.annotation.StringRes
import androidx.core.view.forEach
import androidx.core.view.get
import androidx.core.view.isVisible
import androidx.core.view.size
import org.jellyfin.mobile.R
import org.jellyfin.mobile.databinding.ExoPlayerControlViewBinding
import org.jellyfin.mobile.databinding.FragmentPlayerBinding
Expand Down Expand Up @@ -125,7 +127,7 @@ class PlayerMenus(
val height = mediaSource.selectedVideoStream?.height
val width = mediaSource.selectedVideoStream?.width
if (height != null && width != null) {
buildQualityMenu(qualityMenu.menu, width, height)
buildQualityMenu(qualityMenu.menu, mediaSource.maxStreamingBitrate, width, height)
} else {
qualityButton.isVisible = false
}
Expand Down Expand Up @@ -222,13 +224,10 @@ class PlayerMenus(
}

private fun createQualityMenu() = PopupMenu(context, qualityButton).apply {
setOnMenuItemClickListener { clickedItem: MenuItem ->
val newBitrate = clickedItem.itemId.takeUnless { bitrate -> bitrate == 0 }
setOnMenuItemClickListener { item: MenuItem ->
val newBitrate = item.itemId.takeUnless { bitrate -> bitrate == 0 }
fragment.onBitrateChanged(newBitrate) {
menu.forEach { item ->
item.isChecked = false
}
clickedItem.isChecked = true
// Ignore callback - menu will be recreated if bitrate changes
}
true
}
Expand Down Expand Up @@ -274,7 +273,10 @@ class PlayerMenus(
showNone: Boolean = false,
) {
menu.clear()
val itemNone = if (showNone) menu.add(groupId, -1, Menu.NONE, fragment.getString(R.string.menu_item_none)) else null
val itemNone = when {
showNone -> menu.add(groupId, -1, Menu.NONE, fragment.getString(R.string.menu_item_none))
else -> null
}
val menuItems = mediaStreams.map { mediaStream ->
menu.add(groupId, mediaStream.index, Menu.NONE, mediaStream.displayTitle)
}
Expand All @@ -297,17 +299,20 @@ class PlayerMenus(
subtitlesButton.setImageState(stateSet, true)
}

private fun buildQualityMenu(menu: Menu, videoWidth: Int, videoHeight: Int) {
private fun buildQualityMenu(menu: Menu, maxStreamingBitrate: Int?, videoWidth: Int, videoHeight: Int) {
menu.clear()
val options = qualityOptionsProvider.getApplicableQualityOptions(videoWidth, videoHeight)
options.map { option ->
options.forEach { option ->
val title = when (val bitrate = option.bitrate) {
0 -> context.getString(R.string.menu_item_auto)
else -> "${option.maxHeight}p - ${formatBitrate(bitrate.toDouble())}"
}
menu.add(QUALITY_MENU_GROUP, option.bitrate, Menu.NONE, title)
}
menu.setGroupCheckable(QUALITY_MENU_GROUP, true, true)

val selection = maxStreamingBitrate?.let(menu::findItem) ?: menu[menu.size - 1] // Last element is "auto"
selection.isChecked = true
}

fun dismissPlaybackInfo() {
Expand Down