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.text.DateFormat
import java.util.Date import java.util.Date
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.milliseconds
@Composable @Composable
fun AnimeScreen( fun AnimeScreen(
@ -833,7 +834,6 @@ fun AnimeScreenLargeImpl(
@Composable @Composable
private fun SharedAnimeBottomActionMenu( private fun SharedAnimeBottomActionMenu(
selected: List<EpisodeList.Item>, selected: List<EpisodeList.Item>,
modifier: Modifier = Modifier,
onEpisodeClicked: (Episode, Boolean) -> Unit, onEpisodeClicked: (Episode, Boolean) -> Unit,
onMultiBookmarkClicked: (List<Episode>, bookmarked: Boolean) -> Unit, onMultiBookmarkClicked: (List<Episode>, bookmarked: Boolean) -> Unit,
onMultiMarkAsSeenClicked: (List<Episode>, markAsSeen: Boolean) -> Unit, onMultiMarkAsSeenClicked: (List<Episode>, markAsSeen: Boolean) -> Unit,
@ -842,6 +842,7 @@ private fun SharedAnimeBottomActionMenu(
onMultiDeleteClicked: (List<Episode>) -> Unit, onMultiDeleteClicked: (List<Episode>) -> Unit,
fillFraction: Float, fillFraction: Float,
alwaysUseExternalPlayer: Boolean, alwaysUseExternalPlayer: Boolean,
modifier: Modifier = Modifier,
) { ) {
EntryBottomActionMenu( EntryBottomActionMenu(
visible = selected.isNotEmpty(), visible = selected.isNotEmpty(),
@ -935,7 +936,8 @@ private fun LazyListScope.sharedEpisodeItems(
?.let { ?.let {
stringResource( stringResource(
R.string.episode_progress, R.string.episode_progress,
it + 1, formatProgress(it),
formatProgress(item.episode.totalSeconds),
) )
}, },
scanlator = item.episode.scanlator.takeIf { !it.isNullOrBlank() }, 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( private fun onEpisodeItemClick(
episodeItem: EpisodeList.Item, episodeItem: EpisodeList.Item,
isAnyEpisodeSelected: Boolean, isAnyEpisodeSelected: Boolean,

View file

@ -61,7 +61,6 @@ import kotlin.math.absoluteValue
@Composable @Composable
fun AnimeEpisodeListItem( fun AnimeEpisodeListItem(
modifier: Modifier = Modifier,
title: String, title: String,
date: String?, date: String?,
watchProgress: String?, watchProgress: String?,
@ -78,6 +77,7 @@ fun AnimeEpisodeListItem(
onClick: () -> Unit, onClick: () -> Unit,
onDownloadClick: ((EpisodeDownloadAction) -> Unit)?, onDownloadClick: ((EpisodeDownloadAction) -> Unit)?,
onEpisodeSwipe: (LibraryPreferences.EpisodeSwipeAction) -> Unit, onEpisodeSwipe: (LibraryPreferences.EpisodeSwipeAction) -> Unit,
modifier: Modifier = Modifier,
) { ) {
val haptic = LocalHapticFeedback.current val haptic = LocalHapticFeedback.current
val density = LocalDensity.current val density = LocalDensity.current
@ -261,9 +261,9 @@ private fun getSwipeAction(
@Composable @Composable
fun NextEpisodeAiringListItem( fun NextEpisodeAiringListItem(
modifier: Modifier = Modifier,
title: String, title: String,
date: String, date: String,
modifier: Modifier = Modifier,
) { ) {
Row( Row(
modifier = modifier.padding(start = 16.dp, top = 12.dp, end = 8.dp, bottom = 12.dp), 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.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.platform.LocalHapticFeedback