mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-17 15:32:01 +00:00
Refactor MetaDetailsScreen for clarity and efficiency
This commit is contained in:
parent
5fb414ea2f
commit
9affc87efd
1 changed files with 51 additions and 22 deletions
|
|
@ -166,9 +166,9 @@ fun MetaDetailsScreen(
|
||||||
var pickerError by remember(type, id) { mutableStateOf<String?>(null) }
|
var pickerError by remember(type, id) { mutableStateOf<String?>(null) }
|
||||||
|
|
||||||
val shouldShowComments = commentsEnabled &&
|
val shouldShowComments = commentsEnabled &&
|
||||||
traktAuthUiState.mode == TraktConnectionMode.CONNECTED &&
|
traktAuthUiState.mode == TraktConnectionMode.CONNECTED &&
|
||||||
displayedMeta != null &&
|
displayedMeta != null &&
|
||||||
displayedMeta.type.lowercase().let { it == "movie" || it == "series" || it == "show" || it == "tv" }
|
displayedMeta.type.lowercase().let { it == "movie" || it == "series" || it == "show" || it == "tv" }
|
||||||
|
|
||||||
LaunchedEffect(displayedMeta?.id, shouldShowComments) {
|
LaunchedEffect(displayedMeta?.id, shouldShowComments) {
|
||||||
if (!shouldShowComments || displayedMeta == null) {
|
if (!shouldShowComments || displayedMeta == null) {
|
||||||
|
|
@ -202,7 +202,7 @@ fun MetaDetailsScreen(
|
||||||
when (networkStatusUiState.condition) {
|
when (networkStatusUiState.condition) {
|
||||||
NetworkCondition.NoInternet,
|
NetworkCondition.NoInternet,
|
||||||
NetworkCondition.ServersUnreachable,
|
NetworkCondition.ServersUnreachable,
|
||||||
-> {
|
-> {
|
||||||
observedOfflineState = true
|
observedOfflineState = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,7 +216,7 @@ fun MetaDetailsScreen(
|
||||||
|
|
||||||
NetworkCondition.Unknown,
|
NetworkCondition.Unknown,
|
||||||
NetworkCondition.Checking,
|
NetworkCondition.Checking,
|
||||||
-> Unit
|
-> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -284,30 +284,56 @@ fun MetaDetailsScreen(
|
||||||
{
|
{
|
||||||
val libraryItem = meta.toLibraryItem(savedAtEpochMs = 0L)
|
val libraryItem = meta.toLibraryItem(savedAtEpochMs = 0L)
|
||||||
if (!isTraktConnected) {
|
if (!isTraktConnected) {
|
||||||
|
// Not on Trakt — toggle local library directly
|
||||||
LibraryRepository.toggleSaved(libraryItem)
|
LibraryRepository.toggleSaved(libraryItem)
|
||||||
} else {
|
} else {
|
||||||
pickerTabs = LibraryRepository.traktListTabs()
|
// On Trakt — tap directly toggles the watchlist (first list tab)
|
||||||
pickerMembership = pickerTabs.associate { it.key to false }
|
|
||||||
pickerPending = true
|
|
||||||
pickerError = null
|
|
||||||
showLibraryListPicker = true
|
|
||||||
detailsScope.launch {
|
detailsScope.launch {
|
||||||
runCatching {
|
runCatching {
|
||||||
val snapshot = LibraryRepository.getMembershipSnapshot(libraryItem)
|
val snapshot = LibraryRepository.getMembershipSnapshot(libraryItem)
|
||||||
val tabs = LibraryRepository.traktListTabs()
|
val tabs = LibraryRepository.traktListTabs()
|
||||||
pickerTabs = tabs
|
// Use the first tab (watchlist) as the quick-save target
|
||||||
pickerMembership = tabs.associate { tab ->
|
val watchlistKey = tabs.firstOrNull()?.key
|
||||||
tab.key to (snapshot[tab.key] == true)
|
if (watchlistKey != null) {
|
||||||
|
val currentlyIn = snapshot[watchlistKey] == true
|
||||||
|
val desired = tabs.associate { tab ->
|
||||||
|
tab.key to if (tab.key == watchlistKey) !currentlyIn else (snapshot[tab.key] == true)
|
||||||
|
}
|
||||||
|
LibraryRepository.applyMembershipChanges(libraryItem, desired)
|
||||||
}
|
}
|
||||||
}.onFailure { error ->
|
}.onFailure { e ->
|
||||||
pickerError = error.message ?: "Failed to load Trakt lists"
|
// Fallback: toggle via standard path
|
||||||
|
LibraryRepository.toggleSaved(libraryItem)
|
||||||
}
|
}
|
||||||
pickerPending = false
|
|
||||||
}
|
}
|
||||||
Unit
|
Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val openListPicker = remember(meta, isTraktConnected) {
|
||||||
|
if (!isTraktConnected) null else ({
|
||||||
|
val libraryItem = meta.toLibraryItem(savedAtEpochMs = 0L)
|
||||||
|
pickerTabs = LibraryRepository.traktListTabs()
|
||||||
|
pickerMembership = pickerTabs.associate { it.key to false }
|
||||||
|
pickerPending = true
|
||||||
|
pickerError = null
|
||||||
|
showLibraryListPicker = true
|
||||||
|
detailsScope.launch {
|
||||||
|
runCatching {
|
||||||
|
val snapshot = LibraryRepository.getMembershipSnapshot(libraryItem)
|
||||||
|
val tabs = LibraryRepository.traktListTabs()
|
||||||
|
pickerTabs = tabs
|
||||||
|
pickerMembership = tabs.associate { tab ->
|
||||||
|
tab.key to (snapshot[tab.key] == true)
|
||||||
|
}
|
||||||
|
}.onFailure { error ->
|
||||||
|
pickerError = error.message ?: "Failed to load Trakt lists"
|
||||||
|
}
|
||||||
|
pickerPending = false
|
||||||
|
}
|
||||||
|
Unit
|
||||||
|
})
|
||||||
|
}
|
||||||
val movieProgress = watchProgressUiState.byVideoId[meta.id]
|
val movieProgress = watchProgressUiState.byVideoId[meta.id]
|
||||||
?.takeUnless { it.isCompleted }
|
?.takeUnless { it.isCompleted }
|
||||||
val cwPrefs by ContinueWatchingPreferencesRepository.uiState.collectAsStateWithLifecycle()
|
val cwPrefs by ContinueWatchingPreferencesRepository.uiState.collectAsStateWithLifecycle()
|
||||||
|
|
@ -324,7 +350,7 @@ fun MetaDetailsScreen(
|
||||||
meta.videos.firstOrNull { video ->
|
meta.videos.firstOrNull { video ->
|
||||||
if (action.seasonNumber != null && action.episodeNumber != null) {
|
if (action.seasonNumber != null && action.episodeNumber != null) {
|
||||||
video.season == action.seasonNumber &&
|
video.season == action.seasonNumber &&
|
||||||
video.episode == action.episodeNumber
|
video.episode == action.episodeNumber
|
||||||
} else {
|
} else {
|
||||||
buildPlaybackVideoId(
|
buildPlaybackVideoId(
|
||||||
parentMetaId = meta.id,
|
parentMetaId = meta.id,
|
||||||
|
|
@ -348,11 +374,11 @@ fun MetaDetailsScreen(
|
||||||
}
|
}
|
||||||
val hasAdditionalInfoSection = remember(meta) {
|
val hasAdditionalInfoSection = remember(meta) {
|
||||||
meta.status != null ||
|
meta.status != null ||
|
||||||
meta.releaseInfo != null ||
|
meta.releaseInfo != null ||
|
||||||
meta.runtime != null ||
|
meta.runtime != null ||
|
||||||
meta.ageRating != null ||
|
meta.ageRating != null ||
|
||||||
meta.country != null ||
|
meta.country != null ||
|
||||||
meta.language != null
|
meta.language != null
|
||||||
}
|
}
|
||||||
val hasCollectionSection = remember(meta) {
|
val hasCollectionSection = remember(meta) {
|
||||||
meta.collectionName != null && meta.collectionItems.isNotEmpty()
|
meta.collectionName != null && meta.collectionItems.isNotEmpty()
|
||||||
|
|
@ -634,6 +660,7 @@ fun MetaDetailsScreen(
|
||||||
onPrimaryPlayClick = onPrimaryPlayClick,
|
onPrimaryPlayClick = onPrimaryPlayClick,
|
||||||
onPrimaryPlayLongClick = onPrimaryPlayLongClick,
|
onPrimaryPlayLongClick = onPrimaryPlayLongClick,
|
||||||
onSaveClick = toggleSaved,
|
onSaveClick = toggleSaved,
|
||||||
|
onSaveLongClick = openListPicker,
|
||||||
showManualPlayOption = showManualPlayOption,
|
showManualPlayOption = showManualPlayOption,
|
||||||
preferredEpisodeSeasonNumber = seriesAction?.seasonNumber,
|
preferredEpisodeSeasonNumber = seriesAction?.seasonNumber,
|
||||||
preferredEpisodeNumber = seriesAction?.episodeNumber,
|
preferredEpisodeNumber = seriesAction?.episodeNumber,
|
||||||
|
|
@ -939,6 +966,7 @@ private fun ConfiguredMetaSections(
|
||||||
onPrimaryPlayClick: () -> Unit,
|
onPrimaryPlayClick: () -> Unit,
|
||||||
onPrimaryPlayLongClick: (() -> Unit)?,
|
onPrimaryPlayLongClick: (() -> Unit)?,
|
||||||
onSaveClick: () -> Unit,
|
onSaveClick: () -> Unit,
|
||||||
|
onSaveLongClick: (() -> Unit)?,
|
||||||
showManualPlayOption: Boolean,
|
showManualPlayOption: Boolean,
|
||||||
preferredEpisodeSeasonNumber: Int?,
|
preferredEpisodeSeasonNumber: Int?,
|
||||||
preferredEpisodeNumber: Int?,
|
preferredEpisodeNumber: Int?,
|
||||||
|
|
@ -999,6 +1027,7 @@ private fun ConfiguredMetaSections(
|
||||||
onPlayClick = onPrimaryPlayClick,
|
onPlayClick = onPrimaryPlayClick,
|
||||||
onPlayLongClick = if (showManualPlayOption) onPrimaryPlayLongClick else null,
|
onPlayLongClick = if (showManualPlayOption) onPrimaryPlayLongClick else null,
|
||||||
onSaveClick = onSaveClick,
|
onSaveClick = onSaveClick,
|
||||||
|
onSaveLongClick = onSaveLongClick,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
MetaScreenSectionKey.OVERVIEW -> {
|
MetaScreenSectionKey.OVERVIEW -> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue