mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-17 07:21:58 +00:00
refactor: address PR review comments for Mark as Watched feature
This commit is contained in:
parent
5ab7ea8dfc
commit
55a16954db
4 changed files with 24 additions and 36 deletions
|
|
@ -38,6 +38,17 @@ data class MetaDetails(
|
|||
val videos: List<MetaVideo> = 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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,13 @@ object WatchingState {
|
|||
fun isPosterWatched(
|
||||
watchedKeys: Set<String>,
|
||||
item: MetaPreview,
|
||||
): Boolean = watchedKeys.contains(watchedItemKey(item.type, item.id))
|
||||
): Boolean = isPosterWatched(watchedKeys, item.type, item.id)
|
||||
|
||||
fun isPosterWatched(
|
||||
watchedKeys: Set<String>,
|
||||
type: String,
|
||||
id: String,
|
||||
): Boolean = watchedKeys.contains(watchedItemKey(type, id))
|
||||
|
||||
fun isEpisodeWatched(
|
||||
watchedKeys: Set<String>,
|
||||
|
|
|
|||
Loading…
Reference in a new issue