mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-17 23:42:04 +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(),
|
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(
|
data class MetaExternalRating(
|
||||||
val source: String,
|
val source: String,
|
||||||
val value: Double,
|
val value: Double,
|
||||||
|
|
|
||||||
|
|
@ -663,7 +663,7 @@ fun MetaDetailsScreen(
|
||||||
isTablet = isTablet,
|
isTablet = isTablet,
|
||||||
playButtonLabel = playButtonLabel,
|
playButtonLabel = playButtonLabel,
|
||||||
isSaved = isSaved,
|
isSaved = isSaved,
|
||||||
isMarkedAsWatched = watchedUiState.watchedKeys.contains(watchedItemKey(meta.type, meta.id)),
|
isWatched = WatchingState.isPosterWatched(watchedUiState.watchedKeys, meta.type, meta.id),
|
||||||
onPrimaryPlayClick = onPrimaryPlayClick,
|
onPrimaryPlayClick = onPrimaryPlayClick,
|
||||||
onPrimaryPlayLongClick = onPrimaryPlayLongClick,
|
onPrimaryPlayLongClick = onPrimaryPlayLongClick,
|
||||||
onSaveClick = toggleSaved,
|
onSaveClick = toggleSaved,
|
||||||
|
|
@ -999,7 +999,7 @@ private fun ConfiguredMetaSections(
|
||||||
isTablet: Boolean,
|
isTablet: Boolean,
|
||||||
playButtonLabel: String,
|
playButtonLabel: String,
|
||||||
isSaved: Boolean,
|
isSaved: Boolean,
|
||||||
isMarkedAsWatched: Boolean,
|
isWatched: Boolean,
|
||||||
onPrimaryPlayClick: () -> Unit,
|
onPrimaryPlayClick: () -> Unit,
|
||||||
onPrimaryPlayLongClick: (() -> Unit)?,
|
onPrimaryPlayLongClick: (() -> Unit)?,
|
||||||
onSaveClick: () -> Unit,
|
onSaveClick: () -> Unit,
|
||||||
|
|
@ -1067,7 +1067,7 @@ private fun ConfiguredMetaSections(
|
||||||
stringResource(Res.string.action_save)
|
stringResource(Res.string.action_save)
|
||||||
},
|
},
|
||||||
isSaved = isSaved,
|
isSaved = isSaved,
|
||||||
isWatched = isMarkedAsWatched,
|
isWatched = isWatched,
|
||||||
isTablet = isTablet,
|
isTablet = isTablet,
|
||||||
onPlayClick = onPrimaryPlayClick,
|
onPlayClick = onPrimaryPlayClick,
|
||||||
onPlayLongClick = if (showManualPlayOption) onPrimaryPlayLongClick else null,
|
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.MetaDetails
|
||||||
import com.nuvio.app.features.details.MetaDetailsRepository
|
import com.nuvio.app.features.details.MetaDetailsRepository
|
||||||
import com.nuvio.app.features.details.MetaVideo
|
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.home.MetaPreview
|
||||||
import com.nuvio.app.features.watched.WatchedItem
|
import com.nuvio.app.features.watched.WatchedItem
|
||||||
import com.nuvio.app.features.watched.WatchedRepository
|
import com.nuvio.app.features.watched.WatchedRepository
|
||||||
|
|
@ -23,38 +24,8 @@ object WatchingActions {
|
||||||
private val actionScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
private val actionScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||||
|
|
||||||
fun toggleMetaWatched(meta: MetaDetails) {
|
fun toggleMetaWatched(meta: MetaDetails) {
|
||||||
if (meta.type != "series" && meta.type != "show" && meta.type != "tv") {
|
actionScope.launch {
|
||||||
WatchedRepository.toggleWatched(
|
togglePosterWatched(meta.toMetaPreview())
|
||||||
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),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,13 @@ object WatchingState {
|
||||||
fun isPosterWatched(
|
fun isPosterWatched(
|
||||||
watchedKeys: Set<String>,
|
watchedKeys: Set<String>,
|
||||||
item: MetaPreview,
|
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(
|
fun isEpisodeWatched(
|
||||||
watchedKeys: Set<String>,
|
watchedKeys: Set<String>,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue