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