Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AudiobookPlayerViewModel(
savedStateHandle: SavedStateHandle,
) : ViewModel() {

private val libraryId: Int? = savedStateHandle.get<String>("libraryId")?.toIntOrNull()
private val contentId: String = savedStateHandle.get<String>("contentId") ?: ""
private val requestedFileIdRaw: String? = savedStateHandle.get<String>("fileId")
private val hasRequestedFileId: Boolean = !requestedFileIdRaw.isNullOrBlank()
Expand Down Expand Up @@ -321,7 +322,7 @@ class AudiobookPlayerViewModel(
// older load can't overwrite the context of a newer one (Apple parity).
val generation = ++startGeneration
viewModelScope.launch {
when (val r = catalogRepository.getItemDetail(contentId)) {
when (val r = catalogRepository.getItemDetail(contentId, libraryId)) {
is ApiResult.Success -> {
if (generation != startGeneration) return@launch
val d = r.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ data class VideoPlaybackStartRequest(
* context here would silently turn it into a different playback decision.
*/
val recoveryStartParams: StartParams? = null,
val libraryId: Int? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,15 @@ fun AppNavigation(
// external link to item B while item A's detail is showing
// reused A's entry and Back skipped A entirely — the same
// defect this branch fixes for in-app navigation.
val useSingleTop = shouldLaunchExternalRouteSingleTop(
currentDestinationRoute = navController.currentBackStackEntry
?.destination?.route,
currentContentId = navController.currentBackStackEntry
?.savedStateHandle?.get<String>(DisplayedDetailContentIdKey)
?: navController.currentBackStackEntry?.arguments?.getString("contentId"),
targetRoute = route,
)
val useSingleTop = navController.currentBackStackEntry?.arguments?.getString("libraryId") == null &&
shouldLaunchExternalRouteSingleTop(
currentDestinationRoute = navController.currentBackStackEntry
?.destination?.route,
currentContentId = navController.currentBackStackEntry
?.savedStateHandle?.get<String>(DisplayedDetailContentIdKey)
?: navController.currentBackStackEntry?.arguments?.getString("contentId"),
targetRoute = route,
)
navController.navigate(route) {
if (replaceCurrentPlayer) {
popUpTo(Route.Player.ROUTE) { inclusive = true }
Expand Down Expand Up @@ -855,11 +856,16 @@ fun AppNavigation(
defaultValue = null
},
),
) {
) { backStackEntry ->
val browseViewModel = koinViewModel<BrowseViewModel>()
BrowseScreen(
onItemClick = { contentId ->
navController.navigate(Route.ItemDetail(contentId).route)
navController.navigate(
Route.ItemDetail(
contentId,
libraryId = backStackEntry.arguments?.getString("libraryId")?.toIntOrNull(),
).route,
)
},
onBackClick = { navController.popBackStack() },
viewModel = browseViewModel,
Expand All @@ -881,7 +887,12 @@ fun AppNavigation(
collectionId = backStackEntry.arguments?.getString("collectionId") ?: "",
onBackClick = { navController.popBackStack() },
onItemClick = { contentId ->
navController.navigate(Route.ItemDetail(contentId).route)
navController.navigate(
Route.ItemDetail(
contentId,
libraryId = backStackEntry.arguments?.getString("libraryId")?.toIntOrNull(),
).route,
)
},
)
}
Expand All @@ -890,6 +901,11 @@ fun AppNavigation(
composable(
route = Route.ItemDetail.ROUTE,
arguments = listOf(
navArgument("libraryId") {
type = NavType.StringType
nullable = true
defaultValue = null
},
navArgument("contentId") { type = NavType.StringType },
navArgument("seasonNumber") {
type = NavType.StringType
Expand All @@ -903,6 +919,7 @@ fun AppNavigation(
},
),
) { backStackEntry ->
val libraryId = backStackEntry.arguments?.getString("libraryId")?.toIntOrNull()
// Keep the destination scope available to media cards nested in
// the detail page so the poster shared-element hand-off still runs.
CompositionLocalProvider(LocalNavAnimatedVisibilityScope provides this) {
Expand Down Expand Up @@ -938,6 +955,7 @@ fun AppNavigation(
// ahead of explicit parameters, so replace its route args.
set(DEFAULT_ARGS_KEY, bundleOf(
"contentId" to resolvedContentId,
"libraryId" to libraryId?.toString(),
"seasonNumber" to resolvedSeason?.toString(),
"episodeContentId" to resolvedEpisodeId,
))
Expand All @@ -954,6 +972,7 @@ fun AppNavigation(
val launchedRemotely = siloCastController.launchOnConnectedTarget(
SiloCastPlaybackRequest(
contentId = contentId,
libraryId = libraryId,
fileId = fileId,
audioTrackIndex = audioTrackIndex,
subtitleTrackIndex = subtitleTrackIndex,
Expand All @@ -966,6 +985,7 @@ fun AppNavigation(
} else {
navController.navigate(
Route.Player(
libraryId = libraryId,
Comment thread
Quick104 marked this conversation as resolved.
Resolved
contentId = contentId,
fileId = fileId,
audioTrackIndex = audioTrackIndex,
Expand All @@ -978,8 +998,11 @@ fun AppNavigation(
onItemDetailClick = { contentId ->
navController.navigate(Route.ItemDetail(contentId).route)
},
onEpisodeDetailClick = { contentId ->
navController.navigate(Route.ItemDetail(contentId, libraryId = libraryId).route)
},
onSeriesClick = { seriesId ->
navController.navigate(Route.ItemDetail(seriesId).route)
navController.navigate(Route.ItemDetail(seriesId, libraryId = libraryId).route)
},
onSeriesDetailReplace = { seriesId, seasonNumber, episodeId ->
resolvedSeason = seasonNumber
Expand All @@ -993,11 +1016,11 @@ fun AppNavigation(
},
onAudiobookPlayClick = { contentId, fileId, fromStart, startPosition ->
navController.navigate(
Route.AudiobookPlayer(contentId, fileId, fromStart, startPosition).route,
Route.AudiobookPlayer(contentId, fileId, fromStart, startPosition, libraryId).route,
)
},
onBookReadClick = { contentId, fileId ->
navController.navigate(Route.BookReader(contentId, fileId).route)
navController.navigate(Route.BookReader(contentId, fileId, libraryId).route)
},
onWatchTogether = { contentId, fileId -> wtTarget = contentId to fileId },
onOpenCastRemote = {
Expand Down Expand Up @@ -1043,6 +1066,11 @@ fun AppNavigation(
composable(
route = Route.AudiobookPlayer.ROUTE,
arguments = listOf(
navArgument("libraryId") {
type = NavType.StringType
nullable = true
defaultValue = null
},
navArgument(Route.AudiobookPlayer.ARG_CONTENT_ID) { type = NavType.StringType },
navArgument(Route.AudiobookPlayer.ARG_FILE_ID) {
type = NavType.StringType
Expand All @@ -1069,6 +1097,11 @@ fun AppNavigation(
composable(
route = Route.BookReader.ROUTE,
arguments = listOf(
navArgument("libraryId") {
type = NavType.StringType
nullable = true
defaultValue = null
},
navArgument(Route.BookReader.ARG_CONTENT_ID) { type = NavType.StringType },
navArgument(Route.BookReader.ARG_FILE_ID) {
type = NavType.StringType
Expand Down Expand Up @@ -1102,6 +1135,11 @@ fun AppNavigation(
composable(
route = Route.Player.ROUTE,
arguments = listOf(
navArgument("libraryId") {
type = NavType.StringType
nullable = true
defaultValue = null
},
navArgument("contentId") { type = NavType.StringType },
navArgument("fileId") {
type = NavType.StringType
Expand Down Expand Up @@ -1149,6 +1187,7 @@ fun AppNavigation(
}
}
PlayerScreen(
libraryId = backStackEntry.arguments?.getString("libraryId")?.toIntOrNull(),
contentId = backStackEntry.arguments?.getString("contentId") ?: "",
initialFileId = backStackEntry.arguments?.getString("fileId")?.toIntOrNull(),
initialQuality = VideoPlayerRouteArgs.normalizeQuality(
Expand Down Expand Up @@ -1323,6 +1362,7 @@ private fun NavHostController.isDisplayingExactPlayerRoute(
// merely because a Watch Together room currently happens to play the same
// content/file.
if (!arguments.getString("roomId").isNullOrBlank()) return false
if (arguments.getString("libraryId") != null) return false
val requestedTarget = playerRouteIntentOrNull(route) ?: return false
return currentPlayerTarget?.let(requestedTarget::matches) == true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ sealed class Route(val route: String) {
val contentId: String,
val seasonNumber: Int? = null,
val episodeContentId: String? = null,
val libraryId: Int? = null,
) : Route(
"item/${contentId.routeEncode()}" +
listOfNotNull(
libraryId?.let { "libraryId=$it" },
seasonNumber?.let { "seasonNumber=$it" },
episodeContentId
?.takeIf { it.isNotBlank() }
Expand All @@ -136,7 +138,7 @@ sealed class Route(val route: String) {
) {
companion object {
const val ROUTE =
"item/{contentId}?seasonNumber={seasonNumber}&episodeContentId={episodeContentId}"
"item/{contentId}?seasonNumber={seasonNumber}&episodeContentId={episodeContentId}&libraryId={libraryId}"
}
}

Expand Down Expand Up @@ -181,10 +183,12 @@ sealed class Route(val route: String) {
val subtitleTrackIndex: Int? = null,
val resumePositionSeconds: Double? = null,
val roomId: String? = null,
val libraryId: Int? = null,
) : Route(
buildString {
append("player/${contentId.routeEncode()}")
val queryParams = listOfNotNull(
libraryId?.let { "libraryId=$it" },
fileId?.let { "fileId=$it" },
// normalizeQuality is a closed wire-value set, so no URI
// escaping (or Android framework dependency) is needed here.
Expand All @@ -203,7 +207,7 @@ sealed class Route(val route: String) {
) {
companion object {
const val ROUTE =
"player/{contentId}?fileId={fileId}&quality={quality}&audioTrackIndex={audioTrackIndex}&subtitleTrackIndex={subtitleTrackIndex}&resumePosition={resumePosition}&roomId={roomId}"
"player/{contentId}?libraryId={libraryId}&fileId={fileId}&quality={quality}&audioTrackIndex={audioTrackIndex}&subtitleTrackIndex={subtitleTrackIndex}&resumePosition={resumePosition}&roomId={roomId}"
}
}

Expand All @@ -223,17 +227,19 @@ sealed class Route(val route: String) {
// Whole-book (global) start offset for Parts / Chapters. The player VM
// resolves which part contains it; null resumes from the stored position.
val startPosition: Double? = null,
val libraryId: Int? = null,
) : Route(
"audiobook/${contentId.routeEncode()}" +
listOfNotNull(
libraryId?.let { "libraryId=$it" },
fileId?.let { "fileId=$it" },
if (fromStart) "fromStart=true" else null,
startPosition?.takeIf { it.isFinite() && it >= 0.0 }?.let { "startPosition=$it" },
).let { params -> if (params.isEmpty()) "" else "?" + params.joinToString("&") },
) {
companion object {
const val ROUTE =
"audiobook/{contentId}?fileId={fileId}&fromStart={fromStart}&startPosition={startPosition}"
"audiobook/{contentId}?libraryId={libraryId}&fileId={fileId}&fromStart={fromStart}&startPosition={startPosition}"
const val ARG_CONTENT_ID = "contentId"
const val ARG_FILE_ID = "fileId"
const val ARG_FROM_START = "fromStart"
Expand All @@ -242,11 +248,14 @@ sealed class Route(val route: String) {
}

// --- Book reader (fullscreen, dispatches by BookFormat) ---
data class BookReader(val contentId: String, val fileId: Int? = null) : Route(
"reader/${contentId.routeEncode()}" + fileId?.let { "?fileId=$it" }.orEmpty(),
data class BookReader(val contentId: String, val fileId: Int? = null, val libraryId: Int? = null) : Route(
"reader/${contentId.routeEncode()}" + listOfNotNull(
fileId?.let { "fileId=$it" },
libraryId?.let { "libraryId=$it" },
).let { params -> if (params.isEmpty()) "" else "?" + params.joinToString("&") },
) {
companion object {
const val ROUTE = "reader/{contentId}?fileId={fileId}"
const val ROUTE = "reader/{contentId}?fileId={fileId}&libraryId={libraryId}"
const val ARG_CONTENT_ID = "contentId"
const val ARG_FILE_ID = "fileId"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ fun MainScreen(
}
Tab.Libraries -> {
LibrariesScreen(
onItemClick = { contentId ->
navController.navigate(Route.ItemDetail(contentId).route)
onItemClick = { contentId, libraryId ->
navController.navigate(Route.ItemDetail(contentId, libraryId = libraryId).route)
},
onCollectionClick = { collectionId, libraryId ->
navController.navigate(Route.CollectionDetail(collectionId, libraryId).route)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fun ItemDetailScreen(
onBackClick: () -> Unit,
onPlayClick: (String, Int?, Int?, Int?, Double?) -> Unit,
onItemDetailClick: (String) -> Unit,
onEpisodeDetailClick: (String) -> Unit = onItemDetailClick,
onPersonClick: (String) -> Unit,
onSeriesClick: (String) -> Unit,
onSeriesDetailReplace: (String, Int, String?) -> Unit,
Expand Down Expand Up @@ -922,7 +923,7 @@ fun ItemDetailScreen(
episodesBySeason = state.episodesBySeason,
isLoadingEpisodes = state.isLoadingEpisodes,
onSeasonSelected = { viewModel.selectSeason(it) },
onEpisodeDetailClick = onItemDetailClick,
onEpisodeDetailClick = onEpisodeDetailClick,
onEpisodeWatchedChange = { episodeContentId, watched ->
viewModel.setEpisodeWatched(episodeContentId, watched)
},
Expand Down
Loading
Loading