From 8856e97c62442e3de1abc1fc09594a004a5bcc49 Mon Sep 17 00:00:00 2001 From: Stypox Date: Fri, 5 Sep 2025 17:17:23 +0200 Subject: [PATCH] Reorder buttons in error panel and don't allow reporting recaptchas --- .../org/schabi/newpipe/error/ErrorInfo.kt | 4 +- .../ui/components/common/ErrorPanel.kt | 56 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt index a3c0aa993..45ab8daa0 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt @@ -3,7 +3,6 @@ package org.schabi.newpipe.error import android.content.Context import android.os.Parcelable import androidx.annotation.StringRes -import androidx.core.content.ContextCompat import com.google.android.exoplayer2.ExoPlaybackException import com.google.android.exoplayer2.upstream.HttpDataSource import com.google.android.exoplayer2.upstream.Loader @@ -275,6 +274,9 @@ class ErrorInfo private constructor( // we don't have an exception, so this is a manually built error, which likely // indicates that it's important and is thus reportable null -> true + // a recaptcha was detected, and the user needs to solve it, there is no use in + // letting users report it + is ReCaptchaException -> false // the service explicitly said that content is not available (e.g. age restrictions, // video deleted, etc.), there is no use in letting users report it is ContentNotAvailableException -> false diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/common/ErrorPanel.kt b/app/src/main/java/org/schabi/newpipe/ui/components/common/ErrorPanel.kt index 3a2771a6f..74de30ea5 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/common/ErrorPanel.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/common/ErrorPanel.kt @@ -1,9 +1,8 @@ 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.foundation.layout.Spacer -import androidx.compose.foundation.layout.height import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -15,12 +14,14 @@ 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.ui.theme.SizeTokens import org.schabi.newpipe.util.external_communication.ShareUtils @Composable @@ -28,7 +29,6 @@ fun ErrorPanel( errorInfo: ErrorInfo, modifier: Modifier = Modifier, onRetry: (() -> Unit)? = null, - ) { val context = LocalContext.current val isPreview = LocalInspectionMode.current @@ -39,29 +39,24 @@ fun ErrorPanel( } Column( + verticalArrangement = Arrangement.spacedBy(12.dp), horizontalAlignment = Alignment.CenterHorizontally, - modifier = modifier + modifier = modifier, ) { - Text( text = messageText, style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold), textAlign = TextAlign.Center ) - Spacer(Modifier.height(SizeTokens.SpacingMedium)) - if (errorInfo.isReportable) { - ServiceColoredButton(onClick = { - ErrorUtil.openActivity(context, errorInfo) - }) { - Text(stringResource(R.string.error_snackbar_action).uppercase()) - } - } - - errorInfo.recaptchaUrl?.let { recaptchaUrl -> + if (errorInfo.recaptchaUrl != null) { ServiceColoredButton(onClick = { + // Starting ReCaptcha Challenge Activity val intent = Intent(context, ReCaptchaActivity::class.java) - .putExtra(ReCaptchaActivity.RECAPTCHA_URL_EXTRA, recaptchaUrl) + .putExtra( + ReCaptchaActivity.RECAPTCHA_URL_EXTRA, + errorInfo.recaptchaUrl + ) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) context.startActivity(intent) }) { @@ -77,29 +72,32 @@ fun ErrorPanel( } } - errorInfo.openInBrowserUrl?.let { url -> - ServiceColoredButton(onClick = { - ShareUtils.openUrlInBrowser(context, url) - }) { - Text(stringResource(R.string.open_in_browser).uppercase()) + if (errorInfo.isReportable) { + ServiceColoredButton(onClick = { ErrorUtil.openActivity(context, errorInfo) }) { + Text(stringResource(R.string.error_snackbar_action).uppercase()) } } - Spacer(Modifier.height(SizeTokens.SpacingExtraLarge)) + 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) - +@Preview(showBackground = true, widthDp = 360, heightDp = 640, backgroundColor = 0xffffffff) @Composable fun ErrorPanelPreview() { AppTheme { ErrorPanel( errorInfo = ErrorInfo( - throwable = Exception("Network error"), - userAction = org.schabi.newpipe.error.UserAction.UI_ERROR, - request = "Preview request" - ) + throwable = ReCaptchaException("An error", "https://example.com"), + userAction = UserAction.REQUESTED_STREAM, + request = "Preview request", + openInBrowserUrl = "https://example.com", + ), + onRetry = {}, ) } }