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