From df6a85a9443061aef1c08f93c8457762a422012e Mon Sep 17 00:00:00 2001 From: LuftVerbot <97435834+LuftVerbot@users.noreply.github.com> Date: Sun, 26 Nov 2023 13:38:39 +0100 Subject: [PATCH] fix AnimeScreen crash --- .../presentation/entries/anime/AnimeScreen.kt | 26 +++++++++++++++++-- .../anime/components/AnimeEpisodeListItem.kt | 4 +-- .../updates/anime/AnimeUpdatesUiItem.kt | 1 - 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/entries/anime/AnimeScreen.kt b/app/src/main/java/eu/kanade/presentation/entries/anime/AnimeScreen.kt index c9cbfece6..d86b10d1a 100644 --- a/app/src/main/java/eu/kanade/presentation/entries/anime/AnimeScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/entries/anime/AnimeScreen.kt @@ -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, - modifier: Modifier = Modifier, onEpisodeClicked: (Episode, Boolean) -> Unit, onMultiBookmarkClicked: (List, bookmarked: Boolean) -> Unit, onMultiMarkAsSeenClicked: (List, markAsSeen: Boolean) -> Unit, @@ -842,6 +842,7 @@ private fun SharedAnimeBottomActionMenu( onMultiDeleteClicked: (List) -> 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, diff --git a/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeEpisodeListItem.kt b/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeEpisodeListItem.kt index 8a5460d68..1a8818e3e 100644 --- a/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeEpisodeListItem.kt +++ b/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeEpisodeListItem.kt @@ -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), diff --git a/app/src/main/java/eu/kanade/presentation/updates/anime/AnimeUpdatesUiItem.kt b/app/src/main/java/eu/kanade/presentation/updates/anime/AnimeUpdatesUiItem.kt index d957ce794..9696ff504 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/anime/AnimeUpdatesUiItem.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/anime/AnimeUpdatesUiItem.kt @@ -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