Skip to content

Commit 8856e97

Browse files
committed
Reorder buttons in error panel and don't allow reporting recaptchas
1 parent aed4278 commit 8856e97

2 files changed

Lines changed: 29 additions & 29 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: 26 additions & 28 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
@@ -15,20 +14,21 @@ import androidx.compose.ui.res.stringResource
1514
import androidx.compose.ui.text.font.FontWeight
1615
import androidx.compose.ui.text.style.TextAlign
1716
import androidx.compose.ui.tooling.preview.Preview
17+
import androidx.compose.ui.unit.dp
1818
import org.schabi.newpipe.R
1919
import org.schabi.newpipe.error.ErrorInfo
2020
import org.schabi.newpipe.error.ErrorUtil
2121
import org.schabi.newpipe.error.ReCaptchaActivity
22+
import org.schabi.newpipe.error.UserAction
23+
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
2224
import org.schabi.newpipe.ui.theme.AppTheme
23-
import org.schabi.newpipe.ui.theme.SizeTokens
2425
import org.schabi.newpipe.util.external_communication.ShareUtils
2526

2627
@Composable
2728
fun ErrorPanel(
2829
errorInfo: ErrorInfo,
2930
modifier: Modifier = Modifier,
3031
onRetry: (() -> Unit)? = null,
31-
3232
) {
3333
val context = LocalContext.current
3434
val isPreview = LocalInspectionMode.current
@@ -39,29 +39,24 @@ fun ErrorPanel(
3939
}
4040

4141
Column(
42+
verticalArrangement = Arrangement.spacedBy(12.dp),
4243
horizontalAlignment = Alignment.CenterHorizontally,
43-
modifier = modifier
44+
modifier = modifier,
4445
) {
45-
4646
Text(
4747
text = messageText,
4848
style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold),
4949
textAlign = TextAlign.Center
5050
)
5151

52-
Spacer(Modifier.height(SizeTokens.SpacingMedium))
53-
if (errorInfo.isReportable) {
54-
ServiceColoredButton(onClick = {
55-
ErrorUtil.openActivity(context, errorInfo)
56-
}) {
57-
Text(stringResource(R.string.error_snackbar_action).uppercase())
58-
}
59-
}
60-
61-
errorInfo.recaptchaUrl?.let { recaptchaUrl ->
52+
if (errorInfo.recaptchaUrl != null) {
6253
ServiceColoredButton(onClick = {
54+
// Starting ReCaptcha Challenge Activity
6355
val intent = Intent(context, ReCaptchaActivity::class.java)
64-
.putExtra(ReCaptchaActivity.RECAPTCHA_URL_EXTRA, recaptchaUrl)
56+
.putExtra(
57+
ReCaptchaActivity.RECAPTCHA_URL_EXTRA,
58+
errorInfo.recaptchaUrl
59+
)
6560
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
6661
context.startActivity(intent)
6762
}) {
@@ -77,29 +72,32 @@ fun ErrorPanel(
7772
}
7873
}
7974

75+
if (errorInfo.isReportable) {
76+
ServiceColoredButton(onClick = { ErrorUtil.openActivity(context, errorInfo) }) {
77+
Text(stringResource(R.string.error_snackbar_action).uppercase())
78+
}
79+
}
80+
8081
errorInfo.openInBrowserUrl?.let { url ->
81-
ServiceColoredButton(onClick = {
82-
ShareUtils.openUrlInBrowser(context, url)
83-
}) {
82+
ServiceColoredButton(onClick = { ShareUtils.openUrlInBrowser(context, url) }) {
8483
Text(stringResource(R.string.open_in_browser).uppercase())
8584
}
8685
}
87-
88-
Spacer(Modifier.height(SizeTokens.SpacingExtraLarge))
8986
}
9087
}
9188

92-
@Preview(showBackground = true, widthDp = 360, heightDp = 640)
93-
89+
@Preview(showBackground = true, widthDp = 360, heightDp = 640, backgroundColor = 0xffffffff)
9490
@Composable
9591
fun ErrorPanelPreview() {
9692
AppTheme {
9793
ErrorPanel(
9894
errorInfo = ErrorInfo(
99-
throwable = Exception("Network error"),
100-
userAction = org.schabi.newpipe.error.UserAction.UI_ERROR,
101-
request = "Preview request"
102-
)
95+
throwable = ReCaptchaException("An error", "https://example.com"),
96+
userAction = UserAction.REQUESTED_STREAM,
97+
request = "Preview request",
98+
openInBrowserUrl = "https://example.com",
99+
),
100+
onRetry = {},
103101
)
104102
}
105103
}

0 commit comments

Comments
 (0)