diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/details/MetaDetailsModels.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/details/MetaDetailsModels.kt index 3ac52ded..6749ba42 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/details/MetaDetailsModels.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/details/MetaDetailsModels.kt @@ -38,6 +38,17 @@ data class MetaDetails( val videos: List = emptyList(), ) +fun MetaDetails.toMetaPreview(): MetaPreview = MetaPreview( + id = id, + type = type, + name = name, + poster = poster, + banner = background, + logo = logo, + description = description, + releaseInfo = releaseInfo, +) + data class MetaExternalRating( val source: String, val value: Double, diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/details/MetaDetailsScreen.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/details/MetaDetailsScreen.kt index cd25e0ea..823c0da5 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/details/MetaDetailsScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/details/MetaDetailsScreen.kt @@ -663,7 +663,7 @@ fun MetaDetailsScreen( isTablet = isTablet, playButtonLabel = playButtonLabel, isSaved = isSaved, - isMarkedAsWatched = watchedUiState.watchedKeys.contains(watchedItemKey(meta.type, meta.id)), + isWatched = WatchingState.isPosterWatched(watchedUiState.watchedKeys, meta.type, meta.id), onPrimaryPlayClick = onPrimaryPlayClick, onPrimaryPlayLongClick = onPrimaryPlayLongClick, onSaveClick = toggleSaved, @@ -999,7 +999,7 @@ private fun ConfiguredMetaSections( isTablet: Boolean, playButtonLabel: String, isSaved: Boolean, - isMarkedAsWatched: Boolean, + isWatched: Boolean, onPrimaryPlayClick: () -> Unit, onPrimaryPlayLongClick: (() -> Unit)?, onSaveClick: () -> Unit, @@ -1067,7 +1067,7 @@ private fun ConfiguredMetaSections( stringResource(Res.string.action_save) }, isSaved = isSaved, - isWatched = isMarkedAsWatched, + isWatched = isWatched, isTablet = isTablet, onPlayClick = onPrimaryPlayClick, onPlayLongClick = if (showManualPlayOption) onPrimaryPlayLongClick else null, diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watching/application/WatchingActions.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watching/application/WatchingActions.kt index b228cd3e..212394d5 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watching/application/WatchingActions.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watching/application/WatchingActions.kt @@ -3,6 +3,7 @@ package com.nuvio.app.features.watching.application import com.nuvio.app.features.details.MetaDetails import com.nuvio.app.features.details.MetaDetailsRepository import com.nuvio.app.features.details.MetaVideo +import com.nuvio.app.features.details.toMetaPreview import com.nuvio.app.features.home.MetaPreview import com.nuvio.app.features.watched.WatchedItem import com.nuvio.app.features.watched.WatchedRepository @@ -23,38 +24,8 @@ object WatchingActions { private val actionScope = CoroutineScope(SupervisorJob() + Dispatchers.Default) fun toggleMetaWatched(meta: MetaDetails) { - if (meta.type != "series" && meta.type != "show" && meta.type != "tv") { - WatchedRepository.toggleWatched( - WatchedItem( - id = meta.id, - type = meta.type, - name = meta.name, - poster = meta.poster, - releaseInfo = meta.releaseInfo, - markedAtEpochMs = 0L - ) - ) - return - } - - val isCurrentlyWatched = WatchedRepository.isWatched( - id = meta.id, - type = meta.type, - ) - - val todayIsoDate = CurrentDateProvider.todayIsoDate() - val seriesItems = buildList { - add(meta.toSeriesWatchedItem()) - addAll(meta.releasedPlayableEpisodes(todayIsoDate).map(meta::toEpisodeWatchedItem)) - } - - if (isCurrentlyWatched) { - WatchedRepository.unmarkWatched(seriesItems) - } else { - WatchedRepository.markWatched(seriesItems) - WatchProgressRepository.clearProgress( - meta.releasedPlayableEpisodes(todayIsoDate).map(meta::episodePlaybackId), - ) + actionScope.launch { + togglePosterWatched(meta.toMetaPreview()) } } diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watching/application/WatchingState.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watching/application/WatchingState.kt index c0f1474f..6dfd9f63 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watching/application/WatchingState.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watching/application/WatchingState.kt @@ -18,7 +18,13 @@ object WatchingState { fun isPosterWatched( watchedKeys: Set, item: MetaPreview, - ): Boolean = watchedKeys.contains(watchedItemKey(item.type, item.id)) + ): Boolean = isPosterWatched(watchedKeys, item.type, item.id) + + fun isPosterWatched( + watchedKeys: Set, + type: String, + id: String, + ): Boolean = watchedKeys.contains(watchedItemKey(type, id)) fun isEpisodeWatched( watchedKeys: Set,