mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-17 07:21:58 +00:00
Merge 8291113257 into 70d3eee9d2
This commit is contained in:
commit
86922b4d36
1 changed files with 53 additions and 43 deletions
|
|
@ -21,10 +21,10 @@ import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.nuvio.app.core.network.NetworkCondition
|
import com.nuvio.app.core.network.NetworkCondition
|
||||||
import com.nuvio.app.core.network.NetworkStatusRepository
|
import com.nuvio.app.core.network.NetworkStatusRepository
|
||||||
|
import com.nuvio.app.core.ui.NuvioPosterActionSheet
|
||||||
import com.nuvio.app.core.ui.NuvioScreen
|
import com.nuvio.app.core.ui.NuvioScreen
|
||||||
import com.nuvio.app.core.ui.NuvioNetworkOfflineCard
|
import com.nuvio.app.core.ui.NuvioNetworkOfflineCard
|
||||||
import com.nuvio.app.core.ui.NuvioScreenHeader
|
import com.nuvio.app.core.ui.NuvioScreenHeader
|
||||||
import com.nuvio.app.core.ui.NuvioStatusModal
|
|
||||||
import com.nuvio.app.core.ui.NuvioToastController
|
import com.nuvio.app.core.ui.NuvioToastController
|
||||||
import com.nuvio.app.core.ui.NuvioViewAllPillSize
|
import com.nuvio.app.core.ui.NuvioViewAllPillSize
|
||||||
import com.nuvio.app.core.ui.NuvioShelfSection
|
import com.nuvio.app.core.ui.NuvioShelfSection
|
||||||
|
|
@ -32,15 +32,17 @@ import com.nuvio.app.features.home.components.HomeEmptyStateCard
|
||||||
import com.nuvio.app.features.home.components.HomePosterCard
|
import com.nuvio.app.features.home.components.HomePosterCard
|
||||||
import com.nuvio.app.features.home.components.HomeSkeletonRow
|
import com.nuvio.app.features.home.components.HomeSkeletonRow
|
||||||
import com.nuvio.app.features.profiles.ProfileRepository
|
import com.nuvio.app.features.profiles.ProfileRepository
|
||||||
|
import com.nuvio.app.features.watched.WatchedRepository
|
||||||
|
import com.nuvio.app.features.watching.application.WatchingActions
|
||||||
|
import com.nuvio.app.features.watching.application.WatchingState
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import nuvio.composeapp.generated.resources.*
|
import nuvio.composeapp.generated.resources.*
|
||||||
import org.jetbrains.compose.resources.getString
|
import org.jetbrains.compose.resources.getString
|
||||||
import org.jetbrains.compose.resources.stringResource
|
import org.jetbrains.compose.resources.stringResource
|
||||||
|
|
||||||
private data class LibraryRemovalTarget(
|
private data class LibraryActionTarget(
|
||||||
val item: LibraryItem,
|
val item: LibraryItem,
|
||||||
val listKey: String? = null,
|
val section: LibrarySection,
|
||||||
val listTitle: String? = null,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -54,7 +56,11 @@ fun LibraryScreen(
|
||||||
LibraryRepository.uiState
|
LibraryRepository.uiState
|
||||||
}.collectAsStateWithLifecycle()
|
}.collectAsStateWithLifecycle()
|
||||||
val networkStatusUiState by NetworkStatusRepository.uiState.collectAsStateWithLifecycle()
|
val networkStatusUiState by NetworkStatusRepository.uiState.collectAsStateWithLifecycle()
|
||||||
var pendingRemovalTarget by remember { mutableStateOf<LibraryRemovalTarget?>(null) }
|
val watchedUiState by remember {
|
||||||
|
WatchedRepository.ensureLoaded()
|
||||||
|
WatchedRepository.uiState
|
||||||
|
}.collectAsStateWithLifecycle()
|
||||||
|
var actionTarget by remember { mutableStateOf<LibraryActionTarget?>(null) }
|
||||||
var observedOfflineState by remember { mutableStateOf(false) }
|
var observedOfflineState by remember { mutableStateOf(false) }
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
val isTraktSource = uiState.sourceMode == LibrarySourceMode.TRAKT
|
val isTraktSource = uiState.sourceMode == LibrarySourceMode.TRAKT
|
||||||
|
|
@ -69,7 +75,7 @@ fun LibraryScreen(
|
||||||
when (networkStatusUiState.condition) {
|
when (networkStatusUiState.condition) {
|
||||||
NetworkCondition.NoInternet,
|
NetworkCondition.NoInternet,
|
||||||
NetworkCondition.ServersUnreachable,
|
NetworkCondition.ServersUnreachable,
|
||||||
-> {
|
-> {
|
||||||
observedOfflineState = true
|
observedOfflineState = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,7 +91,7 @@ fun LibraryScreen(
|
||||||
|
|
||||||
NetworkCondition.Unknown,
|
NetworkCondition.Unknown,
|
||||||
NetworkCondition.Checking,
|
NetworkCondition.Checking,
|
||||||
-> Unit
|
-> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,63 +177,62 @@ fun LibraryScreen(
|
||||||
else -> {
|
else -> {
|
||||||
librarySections(
|
librarySections(
|
||||||
sections = uiState.sections,
|
sections = uiState.sections,
|
||||||
|
watchedKeys = watchedUiState.watchedKeys,
|
||||||
onPosterClick = onPosterClick,
|
onPosterClick = onPosterClick,
|
||||||
onSectionViewAllClick = onSectionViewAllClick,
|
onSectionViewAllClick = onSectionViewAllClick,
|
||||||
onPosterLongClick = { item, section ->
|
onPosterLongClick = { item, section ->
|
||||||
pendingRemovalTarget = if (isTraktSource) {
|
actionTarget = LibraryActionTarget(item = item, section = section)
|
||||||
LibraryRemovalTarget(
|
|
||||||
item = item,
|
|
||||||
listKey = section.type,
|
|
||||||
listTitle = section.displayTitle,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
LibraryRemovalTarget(item = item)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NuvioStatusModal(
|
// Action sheet — same UI as home screen poster long-press
|
||||||
title = stringResource(Res.string.library_remove_title),
|
val target = actionTarget
|
||||||
message = pendingRemovalTarget?.let { target ->
|
if (target != null) {
|
||||||
val listTitle = target.listTitle
|
val preview = target.item.toMetaPreview()
|
||||||
if (listTitle.isNullOrBlank()) {
|
NuvioPosterActionSheet(
|
||||||
stringResource(Res.string.library_remove_message, target.item.name)
|
item = preview,
|
||||||
} else {
|
isSaved = LibraryRepository.isSaved(preview.id, preview.type),
|
||||||
stringResource(Res.string.library_remove_from_list_message, target.item.name, listTitle)
|
isWatched = WatchingState.isPosterWatched(
|
||||||
}
|
watchedKeys = watchedUiState.watchedKeys,
|
||||||
}.orEmpty(),
|
item = preview,
|
||||||
isVisible = pendingRemovalTarget != null,
|
),
|
||||||
confirmText = stringResource(Res.string.library_remove_confirm),
|
onDismiss = { actionTarget = null },
|
||||||
dismissText = stringResource(Res.string.action_cancel),
|
onToggleLibrary = {
|
||||||
onConfirm = {
|
actionTarget = null
|
||||||
val target = pendingRemovalTarget
|
val libraryItem = target.item
|
||||||
pendingRemovalTarget = null
|
if (isTraktSource) {
|
||||||
target?.let {
|
|
||||||
val listKey = target.listKey
|
|
||||||
if (listKey.isNullOrBlank()) {
|
|
||||||
LibraryRepository.remove(target.item.id)
|
|
||||||
} else {
|
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
runCatching {
|
runCatching {
|
||||||
LibraryRepository.removeFromList(target.item, listKey)
|
LibraryRepository.removeFromList(
|
||||||
|
libraryItem,
|
||||||
|
target.section.type,
|
||||||
|
)
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
NuvioToastController.show(
|
NuvioToastController.show(
|
||||||
error.message ?: getString(Res.string.trakt_lists_update_failed),
|
error.message ?: getString(Res.string.trakt_lists_update_failed),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
LibraryRepository.toggleSaved(libraryItem)
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
onToggleWatched = {
|
||||||
onDismiss = { pendingRemovalTarget = null },
|
actionTarget = null
|
||||||
)
|
coroutineScope.launch {
|
||||||
|
WatchingActions.togglePosterWatched(preview)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun LazyListScope.librarySections(
|
private fun LazyListScope.librarySections(
|
||||||
sections: List<LibrarySection>,
|
sections: List<LibrarySection>,
|
||||||
|
watchedKeys: Set<String>,
|
||||||
onPosterClick: ((LibraryItem) -> Unit)?,
|
onPosterClick: ((LibraryItem) -> Unit)?,
|
||||||
onSectionViewAllClick: ((LibrarySection) -> Unit)?,
|
onSectionViewAllClick: ((LibrarySection) -> Unit)?,
|
||||||
onPosterLongClick: (LibraryItem, LibrarySection) -> Unit,
|
onPosterLongClick: (LibraryItem, LibrarySection) -> Unit,
|
||||||
|
|
@ -250,8 +255,13 @@ private fun LazyListScope.librarySections(
|
||||||
viewAllPillSize = NuvioViewAllPillSize.Compact,
|
viewAllPillSize = NuvioViewAllPillSize.Compact,
|
||||||
key = { item -> "${item.type}:${item.id}" },
|
key = { item -> "${item.type}:${item.id}" },
|
||||||
) { item ->
|
) { item ->
|
||||||
|
val preview = item.toMetaPreview()
|
||||||
HomePosterCard(
|
HomePosterCard(
|
||||||
item = item.toMetaPreview(),
|
item = preview,
|
||||||
|
isWatched = WatchingState.isPosterWatched(
|
||||||
|
watchedKeys = watchedKeys,
|
||||||
|
item = preview,
|
||||||
|
),
|
||||||
onClick = onPosterClick?.let { { it(item) } },
|
onClick = onPosterClick?.let { { it(item) } },
|
||||||
onLongClick = { onPosterLongClick(item, section) },
|
onLongClick = { onPosterLongClick(item, section) },
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue