Skip to content

Commit 4892661

Browse files
committed
Include all button conditions in ErrorPanel
1 parent b86d121 commit 4892661

2 files changed

Lines changed: 27 additions & 24 deletions

File tree

app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.schabi.newpipe.error
33
import android.content.Context
44
import android.os.Parcelable
55
import androidx.annotation.StringRes
6-
import androidx.core.content.ContextCompat
76
import com.google.android.exoplayer2.ExoPlaybackException
87
import com.google.android.exoplayer2.upstream.HttpDataSource
98
import com.google.android.exoplayer2.upstream.Loader
@@ -275,6 +274,9 @@ class ErrorInfo private constructor(
275274
// we don't have an exception, so this is a manually built error, which likely
276275
// indicates that it's important and is thus reportable
277276
null -> true
277+
// a recaptcha was detected, and the user needs to solve it, there is no use in
278+
// letting users report it
279+
is ReCaptchaException -> false
278280
// the service explicitly said that content is not available (e.g. age restrictions,
279281
// video deleted, etc.), there is no use in letting users report it
280282
is ContentNotAvailableException -> false
Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.schabi.newpipe.ui.components.common
22

33
import android.content.Intent
4+
import androidx.compose.foundation.layout.Arrangement
45
import androidx.compose.foundation.layout.Column
5-
import androidx.compose.foundation.layout.Spacer
6-
import androidx.compose.foundation.layout.height
76
import androidx.compose.material3.MaterialTheme
87
import androidx.compose.material3.Text
98
import androidx.compose.runtime.Composable
@@ -14,37 +13,35 @@ import androidx.compose.ui.res.stringResource
1413
import androidx.compose.ui.text.font.FontWeight
1514
import androidx.compose.ui.text.style.TextAlign
1615
import androidx.compose.ui.tooling.preview.Preview
16+
import androidx.compose.ui.unit.dp
1717
import org.schabi.newpipe.R
1818
import org.schabi.newpipe.error.ErrorInfo
1919
import org.schabi.newpipe.error.ErrorUtil
2020
import org.schabi.newpipe.error.ReCaptchaActivity
21+
import org.schabi.newpipe.error.UserAction
22+
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
2123
import org.schabi.newpipe.ui.theme.AppTheme
22-
import org.schabi.newpipe.ui.theme.SizeTokens.SpacingExtraLarge
23-
import org.schabi.newpipe.ui.theme.SizeTokens.SpacingMedium
2424
import org.schabi.newpipe.util.external_communication.ShareUtils
2525

2626
@Composable
2727
fun ErrorPanel(
2828
errorInfo: ErrorInfo,
2929
modifier: Modifier = Modifier,
3030
onRetry: (() -> Unit)? = null,
31-
3231
) {
3332
val context = LocalContext.current
3433

3534
Column(
35+
verticalArrangement = Arrangement.spacedBy(12.dp),
3636
horizontalAlignment = Alignment.CenterHorizontally,
37-
modifier = modifier
37+
modifier = modifier,
3838
) {
39-
4039
Text(
4140
text = errorInfo.getMessage(context),
4241
style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold),
4342
textAlign = TextAlign.Center
4443
)
4544

46-
Spacer(Modifier.height(SpacingMedium))
47-
4845
if (errorInfo.recaptchaUrl != null) {
4946
ServiceColoredButton(onClick = {
5047
// Starting ReCaptcha Challenge Activity
@@ -58,19 +55,24 @@ fun ErrorPanel(
5855
}) {
5956
Text(stringResource(R.string.recaptcha_solve).uppercase())
6057
}
61-
} else if (errorInfo.isReportable) {
58+
}
59+
60+
if (errorInfo.isRetryable) {
61+
onRetry?.let {
62+
ServiceColoredButton(onClick = it) {
63+
Text(stringResource(R.string.retry).uppercase())
64+
}
65+
}
66+
}
67+
68+
if (errorInfo.isReportable) {
6269
ServiceColoredButton(onClick = {
6370
ErrorUtil.openActivity(context, errorInfo)
6471
}) {
6572
Text(stringResource(R.string.error_snackbar_action).uppercase())
6673
}
6774
}
6875

69-
onRetry?.let {
70-
ServiceColoredButton(onClick = it) {
71-
Text(stringResource(R.string.retry).uppercase())
72-
}
73-
}
7476
if (errorInfo.openInBrowserUrl != null) {
7577
ServiceColoredButton(onClick = {
7678
errorInfo.openInBrowserUrl.let { url ->
@@ -80,22 +82,21 @@ fun ErrorPanel(
8082
Text(stringResource(R.string.open_in_browser).uppercase())
8183
}
8284
}
83-
84-
Spacer(Modifier.height(SpacingExtraLarge))
8585
}
8686
}
8787

88-
@Preview(showBackground = true, widthDp = 360, heightDp = 640)
89-
88+
@Preview(showBackground = true, widthDp = 360, heightDp = 640, backgroundColor = 0xffffffff)
9089
@Composable
9190
fun ErrorPanelPreview() {
9291
AppTheme {
9392
ErrorPanel(
9493
errorInfo = ErrorInfo(
95-
throwable = Exception("Network error"),
96-
userAction = org.schabi.newpipe.error.UserAction.UI_ERROR,
97-
request = "Preview request"
98-
)
94+
throwable = ReCaptchaException("An error", "https://example.com"),
95+
userAction = UserAction.REQUESTED_STREAM,
96+
request = "Preview request",
97+
openInBrowserUrl = "https://example.com",
98+
),
99+
onRetry = {},
99100
)
100101
}
101102
}

0 commit comments

Comments
 (0)