Skip to content

Commit 79988d8

Browse files
committed
feat(player): Auto-switch to newly downloaded subtitle in the player screen
1 parent cc5bafd commit 79988d8

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/ui/component/common/dialog/SubtitleSearchDialog.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fun SubtitleSearchDialog(
7777
trimIdList: List<String>,
7878
mediaFileName: String,
7979
onDismissRequest: () -> Unit = {},
80-
onSubtitleDownloadSuccess: () -> Unit = {},
80+
onSubtitleDownloadSuccess: (String) -> Unit = {},
8181
onSubtitleDownloadFailed: (String) -> Unit = {_ ->}
8282
) {
8383
var language by remember(visible) { mutableStateOf("zh-CN") }
@@ -220,7 +220,7 @@ private fun LanguageSwitchFlyout(
220220
fun SubtitleResultList(results: List<SubtitleItemData>,
221221
mediaGuid: String,
222222
trimIdList: List<String>,
223-
onSubtitleDownloadSuccess: () -> Unit = {},
223+
onSubtitleDownloadSuccess: (String) -> Unit = {},
224224
onSubtitleDownloadFailed: (String) -> Unit = {_ ->}
225225
) {
226226
val subtitleDownloadViewModel: SubtitleDownloadViewModel = koinViewModel()
@@ -236,7 +236,7 @@ fun SubtitleResultList(results: List<SubtitleItemData>,
236236
(subtitleDownloadState as UiState.Success).data
237237
downloadStatusMap[subtitleDownloadResponse.trimId] = 2
238238
toastManager.showToast("下载成功")
239-
onSubtitleDownloadSuccess()
239+
onSubtitleDownloadSuccess(subtitleDownloadResponse.trimId)
240240
subtitleDownloadViewModel.clearError()
241241
} else if (subtitleDownloadState is UiState.Error) {
242242
val subtitleDownloadError =

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/ui/screen/PlayerScreen.kt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ fun PlayerOverlay(
670670

671671
val refreshSubtitleList =
672672
remember(playerViewModel, userInfoViewModel, streamViewModel, subtitleDeleteState) {
673-
{
673+
{ targetTrimId: String? ->
674674
val cache = playerViewModel.playingInfoCache.value
675675
if (cache != null) {
676676
kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Main).launch {
@@ -698,6 +698,17 @@ fun PlayerOverlay(
698698
playerViewModel.updateSubtitleList(
699699
streamResponse.subtitleStreams ?: emptyList(), streamResponse
700700
)
701+
if (targetTrimId != null) {
702+
val targetSubtitle =
703+
streamResponse.subtitleStreams?.find { it.trimId == targetTrimId }
704+
if (targetSubtitle != null) {
705+
playerViewModel.updatePlayingInfo(
706+
playerViewModel.playingInfoCache.value?.copy(
707+
currentSubtitleStream = targetSubtitle
708+
)
709+
)
710+
}
711+
}
701712
}
702713
} catch (e: Exception) {
703714
logger.e("Failed to refresh subtitle list", e)
@@ -709,14 +720,14 @@ fun PlayerOverlay(
709720

710721
LaunchedEffect(subtitleDeleteState) {
711722
if (subtitleDeleteState is UiState.Success) {
712-
refreshSubtitleList()
723+
refreshSubtitleList(null)
713724
subtitleDeleteViewModel.clearError()
714725
}
715726
}
716727

717728
LaunchedEffect(subtitleUploadState) {
718729
if (subtitleUploadState is UiState.Success) {
719-
refreshSubtitleList()
730+
refreshSubtitleList(null)
720731
subtitleUploadViewModel.clearError()
721732
}
722733
}
@@ -2497,7 +2508,7 @@ fun PlayerDialogs(
24972508
playingInfoCache: PlayingInfoCache?,
24982509
subtitleToDelete: SubtitleStream?,
24992510
onSubtitleDeleteConfirm: () -> Unit,
2500-
refreshSubtitleList: () -> Unit
2511+
refreshSubtitleList: (String?) -> Unit
25012512
) {
25022513
if (showSubtitleSearchDialog) {
25032514
val mediaGuid = playingInfoCache?.currentFileStream?.guid ?: ""
@@ -2512,8 +2523,8 @@ fun PlayerDialogs(
25122523
trimIdList = trimIdList,
25132524
mediaFileName = mediaFileName,
25142525
onDismissRequest = onSubtitleSearchDialogDismiss,
2515-
onSubtitleDownloadSuccess = {
2516-
refreshSubtitleList()
2526+
onSubtitleDownloadSuccess = { trimId ->
2527+
refreshSubtitleList(trimId)
25172528
}
25182529
)
25192530
}
@@ -2530,7 +2541,7 @@ fun PlayerDialogs(
25302541
onButtonClick = { button, paths ->
25312542
if (button == ContentDialogButton.Primary && !paths.isNullOrEmpty()) {
25322543
subtitleMarkViewModel.markSubtitles(mediaGuid, paths.toList())
2533-
refreshSubtitleList()
2544+
refreshSubtitleList(null)
25342545
onAddNasSubtitleDialogDismiss()
25352546
} else if (button == ContentDialogButton.Close) {
25362547
onAddNasSubtitleDialogDismiss()

0 commit comments

Comments
 (0)