Skip to content

Commit

Permalink
Merge branch 'master' into fixes_issue_2806
Browse files Browse the repository at this point in the history
  • Loading branch information
noahvogt committed Aug 11, 2024
2 parents 3e9fc6d + 6111cbe commit 98458c8
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import org.jellyfin.androidtv.util.sdk.getSeasonEpisodeName
import org.jellyfin.androidtv.util.sdk.isNew
import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.BaseItemKind
import org.jellyfin.sdk.model.api.MediaSourceInfo
import org.jellyfin.sdk.model.api.MediaStream
import org.jellyfin.sdk.model.api.MediaStreamType
import org.jellyfin.sdk.model.api.SeriesStatus
import org.jellyfin.sdk.model.api.VideoRangeType
Expand Down Expand Up @@ -135,13 +137,23 @@ fun InfoRowSeasonEpisode(item: BaseItemDto) {
}
}

private fun List<MediaStream>.getDefault(type: MediaStreamType, defaultIndex: Int? = null): MediaStream? {
if (defaultIndex != null) {
val byIndex = get(defaultIndex)
if (byIndex.type == type) return byIndex
}

return firstOrNull { it.type == type }
}

@Composable
fun InfoRowMediaDetails(item: BaseItemDto) {
val videoStream = item.mediaStreams?.firstOrNull { it.type == MediaStreamType.VIDEO }
val audioStream = item.mediaStreams?.firstOrNull { it.type == MediaStreamType.AUDIO }
fun InfoRowMediaDetails(mediaSource: MediaSourceInfo) {
val videoStream = mediaSource.mediaStreams?.getDefault(MediaStreamType.VIDEO)
val audioStream = mediaSource.mediaStreams?.getDefault(MediaStreamType.AUDIO, mediaSource.defaultAudioStreamIndex)
val subtitleStream = mediaSource.mediaStreams?.getDefault(MediaStreamType.SUBTITLE, mediaSource.defaultSubtitleStreamIndex)

// Subtitles
if (item.hasSubtitles == true) {
if (subtitleStream != null) {
InfoRowItem(
contentDescription = null,
colors = InfoRowColors.Default,
Expand Down Expand Up @@ -219,6 +231,7 @@ fun InfoRowMediaDetails(item: BaseItemDto) {
@Composable
fun BaseItemInfoRow(
item: BaseItemDto,
mediaSource: MediaSourceInfo?,
includeRuntime: Boolean,
) {
val userPreferences = koinInject<UserPreferences>()
Expand All @@ -239,7 +252,7 @@ fun BaseItemInfoRow(
InfoRowDate(item)
if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it) }
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
mediaSource?.let { InfoRowMediaDetails(it) }
}

BaseItemKind.BOX_SET -> {
Expand All @@ -257,15 +270,15 @@ fun BaseItemInfoRow(
val runtime = item.cumulativeRunTimeTicks ?: item.runTimeTicks
if (includeRuntime) runtime?.ticks?.let { BaseItemInfoRowRuntime(it) }
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
mediaSource?.let { InfoRowMediaDetails(it) }
}

BaseItemKind.SERIES -> {
InfoRowDate(item)
if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it) }
InfoRowSeriesStatus(item)
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
mediaSource?.let { InfoRowMediaDetails(it) }
}

BaseItemKind.PROGRAM -> {
Expand Down Expand Up @@ -303,7 +316,7 @@ fun BaseItemInfoRow(

if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it) }
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
mediaSource?.let { InfoRowMediaDetails(it) }
}

BaseItemKind.MUSIC_ARTIST -> {
Expand Down Expand Up @@ -343,14 +356,14 @@ fun BaseItemInfoRow(
val runtime = item.cumulativeRunTimeTicks ?: item.runTimeTicks
if (includeRuntime) runtime?.ticks?.let { BaseItemInfoRowRuntime(it) }
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
mediaSource?.let { InfoRowMediaDetails(it) }
}

else -> {
InfoRowDate(item)
if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it) }
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
mediaSource?.let { InfoRowMediaDetails(it) }
}
}
}
Expand All @@ -364,6 +377,7 @@ class BaseItemInfoRowView @JvmOverloads constructor(
attrs: AttributeSet? = null,
) : AbstractComposeView(context, attrs) {
private val _item = MutableStateFlow<BaseItemDto?>(null)
private val _mediaSource = MutableStateFlow<MediaSourceInfo?>(null)
private val _includeRuntime = MutableStateFlow(false)

var item: BaseItemDto?
Expand All @@ -372,6 +386,12 @@ class BaseItemInfoRowView @JvmOverloads constructor(
_item.value = value
}

var mediaSource: MediaSourceInfo?
get() = _mediaSource.value
set(value) {
_mediaSource.value = value
}

var includeRuntime: Boolean
get() = _includeRuntime.value
set(value) {
Expand All @@ -386,8 +406,9 @@ class BaseItemInfoRowView @JvmOverloads constructor(
@Composable
override fun Content() {
val item by _item.collectAsState()
val mediaSource by _mediaSource.collectAsState()
val includeRuntime by _includeRuntime.collectAsState()

item?.let { BaseItemInfoRow(it, includeRuntime) }
item?.let { BaseItemInfoRow(it, mediaSource, includeRuntime) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.ui.graphics.Color
*/
object InfoRowColors {
val Transparent = Color.Transparent to Color.White
val Default = Color(0x80FFFFFF) to Color.Black
val Green = Color(0x8034D97C) to Color.Black
val Red = Color(0x80F2364D) to Color.Black
val Default = Color(0xB3FFFFFF) to Color.Black
val Green = Color(0xB3089562) to Color.White
val Red = Color(0xB3F2364D) to Color.White
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.tv.material3.ProvideTextStyle
Expand Down Expand Up @@ -46,6 +47,7 @@ fun InfoRowItem(
value = TextStyle(
color = foregroundColor,
fontSize = if (backgroundColor.alpha > 0f) 12.sp else 16.sp,
fontWeight = if (backgroundColor.alpha > 0f) FontWeight.W600 else FontWeight.W500,
)
) {
Row(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jellyfin.androidtv.ui.itemdetail

import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.jellyfin.androidtv.data.repository.ItemMutationRepository
import org.jellyfin.sdk.api.client.ApiClient
Expand Down Expand Up @@ -29,7 +30,7 @@ fun ItemListFragment.loadItem(itemId: UUID) {

lifecycleScope.launch {
val item by api.userLibraryApi.getItem(itemId)
setBaseItem(item)
if (isActive) setBaseItem(item)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import android.graphics.Color;
import android.media.AudioManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -1281,5 +1283,12 @@ public void onDestroy() {
// Show system bars
WindowCompat.setDecorFitsSystemWindows(requireActivity().getWindow(), true);
WindowCompat.getInsetsController(requireActivity().getWindow(), requireActivity().getWindow().getDecorView()).show(WindowInsetsCompat.Type.systemBars());

// Reset display mode
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
WindowManager.LayoutParams params = getActivity().getWindow().getAttributes();
params.preferredDisplayModeId = 0;
getActivity().getWindow().setAttributes(params);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MyDetailsOverviewRowPresenter(
fun setItem(row: MyDetailsOverviewRow) {
setTitle(row.item.name)

InfoLayoutHelper.addInfoRow(view.context, row.item, binding.fdMainInfoRow, false)
InfoLayoutHelper.addInfoRow(view.context, row.item, row.item.mediaSources?.getOrNull(row.selectedMediaSourceIndex), binding.fdMainInfoRow, false)
binding.fdGenreRow.text = row.item.genres?.joinToString(" / ")

binding.infoTitle1.text = row.infoItem1?.label
Expand Down

This file was deleted.

48 changes: 48 additions & 0 deletions app/src/main/java/org/jellyfin/androidtv/util/InfoLayoutHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jellyfin.androidtv.util

import android.content.Context
import android.widget.LinearLayout
import org.jellyfin.androidtv.ui.browsing.composable.inforow.BaseItemInfoRowView
import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.MediaSourceInfo

object InfoLayoutHelper {
@JvmStatic
fun addInfoRow(
context: Context,
item: BaseItemDto?,
mediaSource: MediaSourceInfo?,
layout: LinearLayout,
includeRuntime: Boolean
) {
// Find existing BaseItemInfoRowView or create a new one
var baseItemInfoRowView: BaseItemInfoRowView? = null

for (i in 0 until layout.childCount) {
val child = layout.getChildAt(i)

if (child is BaseItemInfoRowView) {
baseItemInfoRowView = child
break
}
}

if (baseItemInfoRowView == null) {
baseItemInfoRowView = BaseItemInfoRowView(context)
layout.addView(baseItemInfoRowView)
}

// Update item info
baseItemInfoRowView.item = item
baseItemInfoRowView.mediaSource = mediaSource ?: item?.mediaSources?.firstOrNull()
baseItemInfoRowView.includeRuntime = includeRuntime
}

@JvmStatic
fun addInfoRow(
context: Context,
item: BaseItemDto?,
layout: LinearLayout,
includeRuntime: Boolean
) = addInfoRow(context, item, null, layout, includeRuntime)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.jellyfin.androidtv.util.profile.ProfileHelper.max1080pProfileConditio
import org.jellyfin.androidtv.util.profile.ProfileHelper.maxAudioChannelsCodecProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.photoDirectPlayProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.subtitleProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.supportsHevc
import org.jellyfin.apiclient.model.dlna.CodecProfile
import org.jellyfin.apiclient.model.dlna.CodecType
import org.jellyfin.apiclient.model.dlna.DeviceProfile
Expand Down Expand Up @@ -76,7 +77,7 @@ class ExoPlayerProfile(
this.context = EncodingContext.Streaming
container = Codec.Container.TS
videoCodec = buildList {
if (deviceHevcCodecProfile.ContainsCodec(Codec.Video.HEVC, Codec.Container.TS)) add(Codec.Video.HEVC)
if (supportsHevc) add(Codec.Video.HEVC)
add(Codec.Video.H264)
}.joinToString(",")
audioCodec = when (downMixAudio) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ object ProfileHelper {
}
}

val supportsHevc by lazy {
MediaTest.supportsHevc()
}

val deviceHevcCodecProfile by lazy {
CodecProfile().apply {
type = CodecType.Video
codec = Codec.Video.HEVC

conditions = when {
!MediaTest.supportsHevc() -> {
!supportsHevc -> {
// The following condition is a method to exclude all HEVC
Timber.i("*** Does NOT support HEVC")
arrayOf(
Expand Down Expand Up @@ -107,7 +111,7 @@ object ProfileHelper {

val deviceHevcLevelCodecProfiles by lazy {
buildList {
if (MediaTest.supportsHevc()) {
if (supportsHevc) {
add(CodecProfile().apply {
type = CodecType.Video
codec = Codec.Video.HEVC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ class SdkPlaybackHelper(
val addIntros = allowIntros && userPreferences[UserPreferences.cinemaModeEnabled]

if (addIntros) {
val intros = runCatching {
api.userLibraryApi.getIntros(mainItem.id).content.items
}.getOrNull().orEmpty()
val intros = runCatching { api.userLibraryApi.getIntros(mainItem.id).content.items }.getOrNull()
.orEmpty()
// Force the type to be trailer as the legacy playback UI uses it to determine if it should show the next up screen
.map { it.copy(type = BaseItemKind.TRAILER) }

intros + parts
} else {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,4 @@
<string name="pref_subtitles_size_normal">Нормальні</string>
<string name="pref_subtitles_size_large">Великі</string>
</resources>
</resources>

0 comments on commit 98458c8

Please sign in to comment.