Refactor MetaDetailsScreen for clarity and efficiency

This commit is contained in:
AdityasahuX07 2026-04-24 21:32:11 +05:30 committed by GitHub
parent 5fb414ea2f
commit 9affc87efd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -284,8 +284,35 @@ 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 {
// On Trakt — tap directly toggles the watchlist (first list tab)
detailsScope.launch {
runCatching {
val snapshot = LibraryRepository.getMembershipSnapshot(libraryItem)
val tabs = LibraryRepository.traktListTabs()
// Use the first tab (watchlist) as the quick-save target
val watchlistKey = tabs.firstOrNull()?.key
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 { e ->
// Fallback: toggle via standard path
LibraryRepository.toggleSaved(libraryItem)
}
}
Unit
}
}
}
val openListPicker = remember(meta, isTraktConnected) {
if (!isTraktConnected) null else ({
val libraryItem = meta.toLibraryItem(savedAtEpochMs = 0L)
pickerTabs = LibraryRepository.traktListTabs() pickerTabs = LibraryRepository.traktListTabs()
pickerMembership = pickerTabs.associate { it.key to false } pickerMembership = pickerTabs.associate { it.key to false }
pickerPending = true pickerPending = true
@ -305,8 +332,7 @@ fun MetaDetailsScreen(
pickerPending = false pickerPending = false
} }
Unit Unit
} })
}
} }
val movieProgress = watchProgressUiState.byVideoId[meta.id] val movieProgress = watchProgressUiState.byVideoId[meta.id]
?.takeUnless { it.isCompleted } ?.takeUnless { it.isCompleted }
@ -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 -> {