-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Implement Compose-based Error Panel, Error UI Model, and Tests for Comments #12404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
theimpulson
merged 15 commits into
TeamNewPipe:refactor
from
SttApollo:Create_CommentSection_ErrorPanel
Oct 7, 2025
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
da4878d
feat(ui):Add ErrorPanel composable to Comments Section, related UI mo…
SttApollo 19fb989
Fix CommentSectionErrorTest to use named NetworkException for instrum…
SttApollo 8292f72
Updated ERefactor ErrorPanel to use ErrorInfo directly and remove UI …
SttApollo f9222a6
Update app/src/main/java/org/schabi/newpipe/ui/components/common/Erro…
SttApollo 848b886
Update app/src/main/java/org/schabi/newpipe/ui/components/video/comme…
SttApollo 9cbcaec
Update app/src/main/java/org/schabi/newpipe/ui/components/video/comme…
SttApollo 2d3a4b6
Convert CommentSectionErrorIntegrationTest to unit test
SttApollo 5ba95a2
Add ErrorPanelPreview
SttApollo fab0d35
Update ErrorPanel and retest
SttApollo 3ab1322
test,ui: move comment error tests to error; remove unused ComposeView
SttApollo aed4278
Unify getString for compatibility
Stypox 8856e97
Reorder buttons in error panel and don't allow reporting recaptchas
Stypox d9ddc07
Fix failing recaptcha mapping test
absurdlylongusername 9d3ac1b
Add Compose UI tests covering ErrorPanel and comment section flows
SttApollo 25e96d5
Address reviewer changes - make previews private and remove white space
SttApollo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,3 +19,6 @@ app/release/ | |
| bin/ | ||
| .vscode/ | ||
| *.code-workspace | ||
|
|
||
| # logs | ||
| *.log | ||
59 changes: 59 additions & 0 deletions
59
app/src/androidTest/java/org/schabi/newpipe/error/ErrorInfoCommentsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package org.schabi.newpipe.error | ||
|
|
||
| import android.content.Context | ||
| import androidx.test.core.app.ApplicationProvider | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import org.junit.Assert | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.schabi.newpipe.R | ||
| import org.schabi.newpipe.extractor.exceptions.ReCaptchaException | ||
| import java.io.IOException | ||
| import java.net.SocketTimeoutException | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class ErrorInfoCommentsTest { | ||
| private val context: Context by lazy { ApplicationProvider.getApplicationContext<Context>() } | ||
| // Test 1: Network error on initial load (Resource.Error) | ||
| @Test | ||
| fun testInitialCommentNetworkError() { | ||
| val errorInfo = ErrorInfo( | ||
| throwable = SocketTimeoutException("Connection timeout"), | ||
| userAction = UserAction.REQUESTED_COMMENTS, | ||
| request = "comments" | ||
| ) | ||
| Assert.assertEquals(context.getString(R.string.network_error), errorInfo.getMessage(context)) | ||
| Assert.assertTrue(errorInfo.isReportable) | ||
| Assert.assertTrue(errorInfo.isRetryable) | ||
| Assert.assertNull(errorInfo.recaptchaUrl) | ||
| } | ||
|
|
||
| // Test 2: Network error on paging (LoadState.Error) | ||
| @Test | ||
| fun testPagingNetworkError() { | ||
| val errorInfo = ErrorInfo( | ||
| throwable = IOException("Paging failed"), | ||
| userAction = UserAction.REQUESTED_COMMENTS, | ||
| request = "comments" | ||
| ) | ||
| Assert.assertEquals(context.getString(R.string.network_error), errorInfo.getMessage(context)) | ||
| Assert.assertTrue(errorInfo.isReportable) | ||
| Assert.assertTrue(errorInfo.isRetryable) | ||
| Assert.assertNull(errorInfo.recaptchaUrl) | ||
| } | ||
|
|
||
| // Test 3: ReCaptcha during comments load | ||
| @Test | ||
| fun testReCaptchaDuringComments() { | ||
| val url = "https://www.google.com/recaptcha/api/fallback?k=test" | ||
| val errorInfo = ErrorInfo( | ||
| throwable = ReCaptchaException("ReCaptcha needed", url), | ||
| userAction = UserAction.REQUESTED_COMMENTS, | ||
| request = "comments" | ||
| ) | ||
| Assert.assertEquals(context.getString(R.string.recaptcha_request_toast), errorInfo.getMessage(context)) | ||
| Assert.assertEquals(url, errorInfo.recaptchaUrl) | ||
| Assert.assertTrue(errorInfo.isReportable) | ||
| Assert.assertTrue(errorInfo.isRetryable) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
app/src/main/java/org/schabi/newpipe/ui/components/common/ErrorPanel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package org.schabi.newpipe.ui.components.common | ||
|
|
||
| import android.content.Intent | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.platform.LocalInspectionMode | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import org.schabi.newpipe.R | ||
| import org.schabi.newpipe.error.ErrorInfo | ||
| import org.schabi.newpipe.error.ErrorUtil | ||
| import org.schabi.newpipe.error.ReCaptchaActivity | ||
| import org.schabi.newpipe.error.UserAction | ||
| import org.schabi.newpipe.extractor.exceptions.ReCaptchaException | ||
| import org.schabi.newpipe.ui.theme.AppTheme | ||
| import org.schabi.newpipe.util.external_communication.ShareUtils | ||
|
|
||
| @Composable | ||
| fun ErrorPanel( | ||
| errorInfo: ErrorInfo, | ||
| modifier: Modifier = Modifier, | ||
| onRetry: (() -> Unit)? = null, | ||
| ) { | ||
| val context = LocalContext.current | ||
| val isPreview = LocalInspectionMode.current | ||
| val messageText = if (isPreview) { | ||
| stringResource(R.string.error_snackbar_message) | ||
| } else { | ||
| errorInfo.getMessage(context) | ||
| } | ||
|
|
||
| Column( | ||
| verticalArrangement = Arrangement.spacedBy(12.dp), | ||
| horizontalAlignment = Alignment.CenterHorizontally, | ||
| modifier = modifier, | ||
| ) { | ||
| Text( | ||
| text = messageText, | ||
| style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold), | ||
| textAlign = TextAlign.Center | ||
| ) | ||
|
|
||
| if (errorInfo.recaptchaUrl != null) { | ||
| ServiceColoredButton(onClick = { | ||
| // Starting ReCaptcha Challenge Activity | ||
| val intent = Intent(context, ReCaptchaActivity::class.java) | ||
| .putExtra( | ||
| ReCaptchaActivity.RECAPTCHA_URL_EXTRA, | ||
| errorInfo.recaptchaUrl | ||
| ) | ||
| .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
| context.startActivity(intent) | ||
| }) { | ||
| Text(stringResource(R.string.recaptcha_solve).uppercase()) | ||
| } | ||
| } | ||
|
|
||
| if (errorInfo.isRetryable) { | ||
| onRetry?.let { | ||
| ServiceColoredButton(onClick = it) { | ||
| Text(stringResource(R.string.retry).uppercase()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (errorInfo.isReportable) { | ||
| ServiceColoredButton(onClick = { ErrorUtil.openActivity(context, errorInfo) }) { | ||
| Text(stringResource(R.string.error_snackbar_action).uppercase()) | ||
| } | ||
| } | ||
|
|
||
| errorInfo.openInBrowserUrl?.let { url -> | ||
| ServiceColoredButton(onClick = { ShareUtils.openUrlInBrowser(context, url) }) { | ||
| Text(stringResource(R.string.open_in_browser).uppercase()) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true, widthDp = 360, heightDp = 640, backgroundColor = 0xffffffff) | ||
| @Composable | ||
| fun ErrorPanelPreview() { | ||
| AppTheme { | ||
| ErrorPanel( | ||
| errorInfo = ErrorInfo( | ||
| throwable = ReCaptchaException("An error", "https://example.com"), | ||
| userAction = UserAction.REQUESTED_STREAM, | ||
| request = "Preview request", | ||
| openInBrowserUrl = "https://example.com", | ||
| ), | ||
| onRetry = {}, | ||
| ) | ||
| } | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
app/src/main/java/org/schabi/newpipe/ui/components/common/ServiceColoredButton.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package org.schabi.newpipe.ui.components.common | ||
|
|
||
| import androidx.compose.foundation.layout.PaddingValues | ||
| import androidx.compose.foundation.layout.RowScope | ||
| import androidx.compose.foundation.layout.wrapContentWidth | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.ButtonDefaults | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.RectangleShape | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import org.schabi.newpipe.ui.theme.AppTheme | ||
| import org.schabi.newpipe.ui.theme.SizeTokens.SpacingMedium | ||
| import org.schabi.newpipe.ui.theme.SizeTokens.SpacingSmall | ||
|
|
||
| @Composable | ||
| fun ServiceColoredButton( | ||
| onClick: () -> Unit, | ||
| modifier: Modifier = Modifier, | ||
|
theimpulson marked this conversation as resolved.
|
||
| content: @Composable() RowScope.() -> Unit, | ||
| ) { | ||
| Button( | ||
| onClick = onClick, | ||
| modifier = modifier.wrapContentWidth(), | ||
| colors = ButtonDefaults.buttonColors( | ||
| containerColor = MaterialTheme.colorScheme.error, | ||
| contentColor = MaterialTheme.colorScheme.onError | ||
| ), | ||
| contentPadding = PaddingValues(horizontal = SpacingMedium, vertical = SpacingSmall), | ||
| shape = RectangleShape, | ||
| elevation = ButtonDefaults.buttonElevation( | ||
| defaultElevation = 8.dp, | ||
|
|
||
| ), | ||
| ) { | ||
| content() | ||
| } | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| fun ServiceColoredButtonPreview() { | ||
|
SttApollo marked this conversation as resolved.
Outdated
|
||
| AppTheme { | ||
| ServiceColoredButton( | ||
| onClick = {}, | ||
| content = { | ||
| Text("Button") | ||
| } | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.