Skip to content

Commit

Permalink
Shrink BaseItemInfoRowRuntime size
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Jul 6, 2024
1 parent fda20e0 commit 19bfaa6
Showing 1 changed file with 14 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.platform.AbstractComposeView
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.tv.material3.Text
import kotlinx.coroutines.flow.MutableStateFlow
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.preference.UserPreferences
import org.jellyfin.androidtv.preference.constant.ClockBehavior
import org.jellyfin.androidtv.preference.constant.RatingType
import org.jellyfin.androidtv.ui.composable.getResolutionName
import org.jellyfin.androidtv.util.TimeUtils
import org.jellyfin.androidtv.util.sdk.getProgramSubText
import org.jellyfin.androidtv.util.sdk.getSeasonEpisodeName
import org.jellyfin.androidtv.util.sdk.isNew
Expand All @@ -34,9 +35,7 @@ import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.time.temporal.ChronoUnit
import kotlin.math.max
import kotlin.time.Duration
import kotlin.time.toJavaDuration

@Composable
fun InfoRowDate(
Expand Down Expand Up @@ -115,22 +114,12 @@ fun InfoRowSeriesStatus(
@Composable
fun BaseItemInfoRowRuntime(
runTime: Duration,
endTime: LocalDateTime?,
) {
InfoRowItem(contentDescription = null) {
Text(buildString {
// Run time
val runTimeMinutes = max(1, runTime.inWholeMinutes.toInt())
append(pluralStringResource(R.plurals.minutes, runTimeMinutes, runTimeMinutes))

// End time
if (endTime != null) {
// Format: (Ends 14:50)
append(" (", stringResource(R.string.lbl_ends), " ")
append(endTime.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)))
append(")")
}
})
InfoRowItem(
icon = painterResource(id = R.drawable.ic_time),
contentDescription = null,
) {
Text(TimeUtils.formatMillis(runTime.inWholeMilliseconds))
}
}

Expand Down Expand Up @@ -235,20 +224,8 @@ fun BaseItemInfoRow(
val userPreferences = koinInject<UserPreferences>()
val ratingType = userPreferences[UserPreferences.defaultRatingType]

val endTime = when (userPreferences[UserPreferences.clockBehavior]) {
ClockBehavior.ALWAYS,
ClockBehavior.IN_MENUS -> {
val runTime = item.runTimeTicks?.ticks
val progress = item.userData?.playbackPositionTicks?.ticks ?: Duration.ZERO
if (runTime != null) LocalDateTime.now() + (runTime - progress).toJavaDuration()
else null
}

else -> null
}

Row(
horizontalArrangement = Arrangement.spacedBy(10.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
if (ratingType != RatingType.RATING_HIDDEN) {
Expand All @@ -260,7 +237,7 @@ fun BaseItemInfoRow(
BaseItemKind.EPISODE -> {
InfoRowSeasonEpisode(item)
InfoRowDate(item)
if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it, endTime) }
if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it) }
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
}
Expand All @@ -278,14 +255,14 @@ fun BaseItemInfoRow(
}
}
val runtime = item.cumulativeRunTimeTicks ?: item.runTimeTicks
if (includeRuntime) runtime?.ticks?.let { BaseItemInfoRowRuntime(it, endTime) }
if (includeRuntime) runtime?.ticks?.let { BaseItemInfoRowRuntime(it) }
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
}

BaseItemKind.SERIES -> {
InfoRowDate(item)
if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it, null) }
if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it) }
InfoRowSeriesStatus(item)
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
Expand Down Expand Up @@ -324,7 +301,7 @@ fun BaseItemInfoRow(
}
}

if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it, endTime) }
if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it) }
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
}
Expand Down Expand Up @@ -364,14 +341,14 @@ fun BaseItemInfoRow(
}

val runtime = item.cumulativeRunTimeTicks ?: item.runTimeTicks
if (includeRuntime) runtime?.ticks?.let { BaseItemInfoRowRuntime(it, endTime) }
if (includeRuntime) runtime?.ticks?.let { BaseItemInfoRowRuntime(it) }
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
}

else -> {
InfoRowDate(item)
if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it, endTime) }
if (includeRuntime) item.runTimeTicks?.ticks?.let { BaseItemInfoRowRuntime(it) }
item.officialRating?.let { InfoRowParentalRating(it) }
InfoRowMediaDetails(item)
}
Expand Down

0 comments on commit 19bfaa6

Please sign in to comment.