Skip to content

Commit e27c7ed

Browse files
committed
Adapt compose code to new ErrorInfo
1 parent 0529a56 commit e27c7ed

2 files changed

Lines changed: 20 additions & 61 deletions

File tree

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,4 @@ class ErrorInfo private constructor(
302302
}
303303
}
304304
}
305-
306-
// fun to extract service explanation
307-
fun getExplanation(): String {
308-
return ""
309-
}
310305
}

app/src/main/java/org/schabi/newpipe/ui/components/common/ErrorPanel.kt

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.schabi.newpipe.ui.components.common
22

33
import android.content.Intent
4-
import androidx.annotation.StringRes
54
import androidx.compose.foundation.layout.Column
65
import androidx.compose.foundation.layout.Spacer
76
import androidx.compose.foundation.layout.height
@@ -19,42 +18,18 @@ import org.schabi.newpipe.R
1918
import org.schabi.newpipe.error.ErrorInfo
2019
import org.schabi.newpipe.error.ErrorUtil
2120
import org.schabi.newpipe.error.ReCaptchaActivity
22-
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException
23-
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
2421
import org.schabi.newpipe.ui.theme.AppTheme
2522
import org.schabi.newpipe.ui.theme.SizeTokens.SpacingExtraLarge
2623
import org.schabi.newpipe.ui.theme.SizeTokens.SpacingMedium
27-
import org.schabi.newpipe.ui.theme.SizeTokens.SpacingSmall
2824
import org.schabi.newpipe.util.external_communication.ShareUtils
2925

30-
enum class ErrorAction(@StringRes val actionStringId: Int) {
31-
REPORT(R.string.error_snackbar_action),
32-
SOLVE_CAPTCHA(R.string.recaptcha_solve)
33-
}
34-
35-
/**
36-
* Determines the error action type based on the throwable in ErrorInfo
37-
*
38-
*/
39-
fun determineErrorAction(errorInfo: ErrorInfo): ErrorAction {
40-
return when (errorInfo.throwable) {
41-
is ReCaptchaException -> ErrorAction.SOLVE_CAPTCHA
42-
is AccountTerminatedException -> ErrorAction.REPORT
43-
else -> ErrorAction.REPORT
44-
}
45-
}
46-
4726
@Composable
4827
fun ErrorPanel(
4928
errorInfo: ErrorInfo,
5029
modifier: Modifier = Modifier,
5130
onRetry: (() -> Unit)? = null,
5231

5332
) {
54-
val explanation = errorInfo.getExplanation()
55-
val canOpenInBrowser = errorInfo.openInBrowserUrl != null
56-
val errorActionType = determineErrorAction(errorInfo)
57-
5833
val context = LocalContext.current
5934

6035
Column(
@@ -68,37 +43,26 @@ fun ErrorPanel(
6843
textAlign = TextAlign.Center
6944
)
7045

71-
if (explanation.isNotBlank()) {
72-
Spacer(Modifier.height(SpacingSmall))
73-
Text(
74-
text = explanation,
75-
style = MaterialTheme.typography.bodyMedium,
76-
textAlign = TextAlign.Center
77-
)
78-
}
79-
8046
Spacer(Modifier.height(SpacingMedium))
81-
when (errorActionType) {
82-
ErrorAction.REPORT -> {
83-
ServiceColoredButton(onClick = {
84-
ErrorUtil.openActivity(context, errorInfo)
85-
}) {
86-
Text(stringResource(errorActionType.actionStringId).uppercase())
87-
}
47+
48+
if (errorInfo.recaptchaUrl != null) {
49+
ServiceColoredButton(onClick = {
50+
// Starting ReCaptcha Challenge Activity
51+
val intent = Intent(context, ReCaptchaActivity::class.java)
52+
.putExtra(
53+
ReCaptchaActivity.RECAPTCHA_URL_EXTRA,
54+
errorInfo.recaptchaUrl
55+
)
56+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
57+
context.startActivity(intent)
58+
}) {
59+
Text(stringResource(R.string.recaptcha_solve).uppercase())
8860
}
89-
ErrorAction.SOLVE_CAPTCHA -> {
90-
ServiceColoredButton(onClick = {
91-
// Starting ReCaptcha Challenge Activity
92-
val intent = Intent(context, ReCaptchaActivity::class.java)
93-
.putExtra(
94-
ReCaptchaActivity.RECAPTCHA_URL_EXTRA,
95-
(errorInfo.throwable as ReCaptchaException).url
96-
)
97-
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
98-
context.startActivity(intent)
99-
}) {
100-
Text(stringResource(errorActionType.actionStringId).uppercase())
101-
}
61+
} else if (errorInfo.isReportable) {
62+
ServiceColoredButton(onClick = {
63+
ErrorUtil.openActivity(context, errorInfo)
64+
}) {
65+
Text(stringResource(R.string.error_snackbar_action).uppercase())
10266
}
10367
}
10468

@@ -107,9 +71,9 @@ fun ErrorPanel(
10771
Text(stringResource(R.string.retry).uppercase())
10872
}
10973
}
110-
if (canOpenInBrowser) {
74+
if (errorInfo.openInBrowserUrl != null) {
11175
ServiceColoredButton(onClick = {
112-
errorInfo.openInBrowserUrl?.let { url ->
76+
errorInfo.openInBrowserUrl.let { url ->
11377
ShareUtils.openUrlInBrowser(context, url)
11478
}
11579
}) {

0 commit comments

Comments
 (0)