diff --git a/CHANGELOG.md b/CHANGELOG.md index 63c51715ab6..9c946d601ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ([#2979](https://github.com/Automattic/pocket-casts-android/pull/2979)) * Fix search podcast results scroll back to the start after subscribing ([#2923](https://github.com/Automattic/pocket-casts-android/pull/2923)) + * Display web-page based HTML transcripts in web view + ([#2910](https://github.com/Automattic/pocket-casts-android/pull/2910)) 7.74 ----- diff --git a/app/lint-baseline.xml b/app/lint-baseline.xml index a42627de55f..b591a5a15e3 100644 --- a/app/lint-baseline.xml +++ b/app/lint-baseline.xml @@ -190,7 +190,7 @@ - - - - - - - - - TranscriptItem( - item = item, - searchState = searchState, - ) + if (state.showAsWebPage) { + TranscriptWebView(state, transitionState) + } else { + LazyColumn( + state = scrollState, + modifier = scrollableContentModifier, + contentPadding = PaddingValues( + start = horizontalContentPadding, + end = horizontalContentPadding, + top = 64.dp, + bottom = 80.dp, + ), + ) { + items(state.displayInfo.items) { item -> + TranscriptItem( + item = item, + searchState = searchState, + ) + } } } } @@ -274,6 +291,53 @@ private fun ScrollableTranscriptView( } } +@Composable +private fun TranscriptWebView( + state: UiState.TranscriptLoaded, + transitionState: TransitionState?, +) { + val webViewState = rememberWebViewState(state.transcript.url) + val navigator = rememberWebViewNavigator() + val lastLoadedUri = webViewState.lastLoadedUrl?.toUri() + val transcriptUri = state.transcript.url.toUri() + val isRootUrl = "${lastLoadedUri?.host}${lastLoadedUri?.path}" == "${transcriptUri.host}${transcriptUri.path}" // Ignore scheme http or https + WebView( + state = webViewState, + navigator = navigator, + onCreated = { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + it.settings.isAlgorithmicDarkeningAllowed = true + } else { + if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { + @Suppress("DEPRECATION") + WebSettingsCompat.setForceDark(it.settings, WebSettingsCompat.FORCE_DARK_ON) + } + } + it.setBackgroundColor(android.graphics.Color.TRANSPARENT) + it.setOnKeyListener( + View.OnKeyListener { _, keyCode, event -> + if (event.action == KeyEvent.ACTION_DOWN) { + if (keyCode == KeyEvent.KEYCODE_BACK && it.canGoBack() && !isRootUrl) { + it.goBack() + return@OnKeyListener true + } + } + false + }, + ) + }, + modifier = Modifier + .fillMaxSize() + .padding(bottom = bottomPadding()), + ) + if (webViewState.loadingState is LoadingState.Loading) { + LoadingView(color = TranscriptColors.textColor()) + } + LaunchedEffect(transitionState, webViewState.viewState) { + if (!isRootUrl) navigator.navigateBack() + } +} + @Composable private fun TranscriptItem( item: DisplayItem, @@ -411,6 +475,7 @@ private fun TranscriptContentPreview( ), ), searchState = searchState, + transitionState = null, colors = TranscriptColors(Color.Black), modifier = Modifier.fillMaxSize(), ) @@ -437,6 +502,7 @@ private fun TranscriptEmptyContentPreview() { ), ), searchState = SearchUiState(), + transitionState = null, colors = TranscriptColors(Color.Black), modifier = Modifier.fillMaxSize(), ) diff --git a/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/transcripts/TranscriptPageWrapper.kt b/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/transcripts/TranscriptPageWrapper.kt index 60b40af6208..d15e751fc20 100644 --- a/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/transcripts/TranscriptPageWrapper.kt +++ b/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/transcripts/TranscriptPageWrapper.kt @@ -135,7 +135,7 @@ fun TranscriptPageWrapper( } LaunchedEffect(transcriptUiState.value) { - showSearch = transcriptUiState.value is TranscriptViewModel.UiState.TranscriptLoaded + showSearch = (transcriptUiState.value as? TranscriptViewModel.UiState.TranscriptLoaded)?.showSearch == true if (!showSearch) expandSearch = false } } diff --git a/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/transcripts/TranscriptViewModel.kt b/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/transcripts/TranscriptViewModel.kt index db405573d41..b6c48c0818a 100644 --- a/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/transcripts/TranscriptViewModel.kt +++ b/modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/transcripts/TranscriptViewModel.kt @@ -235,6 +235,8 @@ class TranscriptViewModel @Inject constructor( cuesInfo.isNotEmpty() && cuesInfo[0].cuesWithTiming.cues.any { it.text?.contains("