mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2025-10-03 09:49:21 +02:00
Reorder buttons in error panel and don't allow reporting recaptchas
This commit is contained in:
parent
aed4278388
commit
8856e97c62
2 changed files with 30 additions and 30 deletions
|
@ -3,7 +3,6 @@ package org.schabi.newpipe.error
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import com.google.android.exoplayer2.ExoPlaybackException
|
import com.google.android.exoplayer2.ExoPlaybackException
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource
|
import com.google.android.exoplayer2.upstream.HttpDataSource
|
||||||
import com.google.android.exoplayer2.upstream.Loader
|
import com.google.android.exoplayer2.upstream.Loader
|
||||||
|
@ -275,6 +274,9 @@ class ErrorInfo private constructor(
|
||||||
// we don't have an exception, so this is a manually built error, which likely
|
// we don't have an exception, so this is a manually built error, which likely
|
||||||
// indicates that it's important and is thus reportable
|
// indicates that it's important and is thus reportable
|
||||||
null -> true
|
null -> true
|
||||||
|
// a recaptcha was detected, and the user needs to solve it, there is no use in
|
||||||
|
// letting users report it
|
||||||
|
is ReCaptchaException -> false
|
||||||
// the service explicitly said that content is not available (e.g. age restrictions,
|
// the service explicitly said that content is not available (e.g. age restrictions,
|
||||||
// video deleted, etc.), there is no use in letting users report it
|
// video deleted, etc.), there is no use in letting users report it
|
||||||
is ContentNotAvailableException -> false
|
is ContentNotAvailableException -> false
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package org.schabi.newpipe.ui.components.common
|
package org.schabi.newpipe.ui.components.common
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
@ -15,12 +14,14 @@ import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.error.ErrorInfo
|
import org.schabi.newpipe.error.ErrorInfo
|
||||||
import org.schabi.newpipe.error.ErrorUtil
|
import org.schabi.newpipe.error.ErrorUtil
|
||||||
import org.schabi.newpipe.error.ReCaptchaActivity
|
import org.schabi.newpipe.error.ReCaptchaActivity
|
||||||
|
import org.schabi.newpipe.error.UserAction
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
|
||||||
import org.schabi.newpipe.ui.theme.AppTheme
|
import org.schabi.newpipe.ui.theme.AppTheme
|
||||||
import org.schabi.newpipe.ui.theme.SizeTokens
|
|
||||||
import org.schabi.newpipe.util.external_communication.ShareUtils
|
import org.schabi.newpipe.util.external_communication.ShareUtils
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -28,7 +29,6 @@ fun ErrorPanel(
|
||||||
errorInfo: ErrorInfo,
|
errorInfo: ErrorInfo,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
onRetry: (() -> Unit)? = null,
|
onRetry: (() -> Unit)? = null,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val isPreview = LocalInspectionMode.current
|
val isPreview = LocalInspectionMode.current
|
||||||
|
@ -39,29 +39,24 @@ fun ErrorPanel(
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = modifier
|
modifier = modifier,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = messageText,
|
text = messageText,
|
||||||
style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold),
|
style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold),
|
||||||
textAlign = TextAlign.Center
|
textAlign = TextAlign.Center
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(Modifier.height(SizeTokens.SpacingMedium))
|
if (errorInfo.recaptchaUrl != null) {
|
||||||
if (errorInfo.isReportable) {
|
|
||||||
ServiceColoredButton(onClick = {
|
|
||||||
ErrorUtil.openActivity(context, errorInfo)
|
|
||||||
}) {
|
|
||||||
Text(stringResource(R.string.error_snackbar_action).uppercase())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
errorInfo.recaptchaUrl?.let { recaptchaUrl ->
|
|
||||||
ServiceColoredButton(onClick = {
|
ServiceColoredButton(onClick = {
|
||||||
|
// Starting ReCaptcha Challenge Activity
|
||||||
val intent = Intent(context, ReCaptchaActivity::class.java)
|
val intent = Intent(context, ReCaptchaActivity::class.java)
|
||||||
.putExtra(ReCaptchaActivity.RECAPTCHA_URL_EXTRA, recaptchaUrl)
|
.putExtra(
|
||||||
|
ReCaptchaActivity.RECAPTCHA_URL_EXTRA,
|
||||||
|
errorInfo.recaptchaUrl
|
||||||
|
)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}) {
|
}) {
|
||||||
|
@ -77,29 +72,32 @@ fun ErrorPanel(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (errorInfo.isReportable) {
|
||||||
|
ServiceColoredButton(onClick = { ErrorUtil.openActivity(context, errorInfo) }) {
|
||||||
|
Text(stringResource(R.string.error_snackbar_action).uppercase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
errorInfo.openInBrowserUrl?.let { url ->
|
errorInfo.openInBrowserUrl?.let { url ->
|
||||||
ServiceColoredButton(onClick = {
|
ServiceColoredButton(onClick = { ShareUtils.openUrlInBrowser(context, url) }) {
|
||||||
ShareUtils.openUrlInBrowser(context, url)
|
|
||||||
}) {
|
|
||||||
Text(stringResource(R.string.open_in_browser).uppercase())
|
Text(stringResource(R.string.open_in_browser).uppercase())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(Modifier.height(SizeTokens.SpacingExtraLarge))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(showBackground = true, widthDp = 360, heightDp = 640)
|
@Preview(showBackground = true, widthDp = 360, heightDp = 640, backgroundColor = 0xffffffff)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ErrorPanelPreview() {
|
fun ErrorPanelPreview() {
|
||||||
AppTheme {
|
AppTheme {
|
||||||
ErrorPanel(
|
ErrorPanel(
|
||||||
errorInfo = ErrorInfo(
|
errorInfo = ErrorInfo(
|
||||||
throwable = Exception("Network error"),
|
throwable = ReCaptchaException("An error", "https://example.com"),
|
||||||
userAction = org.schabi.newpipe.error.UserAction.UI_ERROR,
|
userAction = UserAction.REQUESTED_STREAM,
|
||||||
request = "Preview request"
|
request = "Preview request",
|
||||||
)
|
openInBrowserUrl = "https://example.com",
|
||||||
|
),
|
||||||
|
onRetry = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue