fix AnimeScreen crash

This commit is contained in:
LuftVerbot 2023-11-26 13:38:39 +01:00
parent 91de0ed82e
commit df6a85a944
3 changed files with 26 additions and 5 deletions

View file

@ -93,6 +93,7 @@ import tachiyomi.presentation.core.util.isScrollingUp
import java.text.DateFormat
import java.util.Date
import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.milliseconds
@Composable
fun AnimeScreen(
@ -833,7 +834,6 @@ fun AnimeScreenLargeImpl(
@Composable
private fun SharedAnimeBottomActionMenu(
selected: List<EpisodeList.Item>,
modifier: Modifier = Modifier,
onEpisodeClicked: (Episode, Boolean) -> Unit,
onMultiBookmarkClicked: (List<Episode>, bookmarked: Boolean) -> Unit,
onMultiMarkAsSeenClicked: (List<Episode>, markAsSeen: Boolean) -> Unit,
@ -842,6 +842,7 @@ private fun SharedAnimeBottomActionMenu(
onMultiDeleteClicked: (List<Episode>) -> Unit,
fillFraction: Float,
alwaysUseExternalPlayer: Boolean,
modifier: Modifier = Modifier,
) {
EntryBottomActionMenu(
visible = selected.isNotEmpty(),
@ -935,7 +936,8 @@ private fun LazyListScope.sharedEpisodeItems(
?.let {
stringResource(
R.string.episode_progress,
it + 1,
formatProgress(it),
formatProgress(item.episode.totalSeconds),
)
},
scanlator = item.episode.scanlator.takeIf { !it.isNullOrBlank() },
@ -973,6 +975,26 @@ private fun LazyListScope.sharedEpisodeItems(
}
}
private fun formatProgress(milliseconds: Long): String {
return if (milliseconds > 3600000L) {
String.format(
"%d:%02d:%02d",
TimeUnit.MILLISECONDS.toHours(milliseconds),
TimeUnit.MILLISECONDS.toMinutes(milliseconds) -
TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(milliseconds)),
TimeUnit.MILLISECONDS.toSeconds(milliseconds) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milliseconds)),
)
} else {
String.format(
"%d:%02d",
TimeUnit.MILLISECONDS.toMinutes(milliseconds),
TimeUnit.MILLISECONDS.toSeconds(milliseconds) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milliseconds)),
)
}
}
private fun onEpisodeItemClick(
episodeItem: EpisodeList.Item,
isAnyEpisodeSelected: Boolean,

View file

@ -61,7 +61,6 @@ import kotlin.math.absoluteValue
@Composable
fun AnimeEpisodeListItem(
modifier: Modifier = Modifier,
title: String,
date: String?,
watchProgress: String?,
@ -78,6 +77,7 @@ fun AnimeEpisodeListItem(
onClick: () -> Unit,
onDownloadClick: ((EpisodeDownloadAction) -> Unit)?,
onEpisodeSwipe: (LibraryPreferences.EpisodeSwipeAction) -> Unit,
modifier: Modifier = Modifier,
) {
val haptic = LocalHapticFeedback.current
val density = LocalDensity.current
@ -261,9 +261,9 @@ private fun getSwipeAction(
@Composable
fun NextEpisodeAiringListItem(
modifier: Modifier = Modifier,
title: String,
date: String,
modifier: Modifier = Modifier,
) {
Row(
modifier = modifier.padding(start = 16.dp, top = 12.dp, end = 8.dp, bottom = 12.dp),

View file

@ -27,7 +27,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback