diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.kt index 5dd0755c59a..c68a2cfd1e1 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.kt @@ -25,6 +25,7 @@ import org.schabi.newpipe.databinding.ActivityErrorBinding import org.schabi.newpipe.util.Localization import org.schabi.newpipe.util.ThemeHelper import org.schabi.newpipe.util.external_communication.ShareUtils +import org.schabi.newpipe.util.text.setTextWithLinks /** * This activity is used to show error details and allow reporting them in various ways. @@ -100,7 +101,7 @@ class ErrorActivity : AppCompatActivity() { // normal bugreport buildInfo(errorInfo) - binding.errorMessageView.text = errorInfo.getMessage(this) + binding.errorMessageView.setTextWithLinks(errorInfo.getMessage(this)) binding.errorView.text = formErrorText(errorInfo.stackTraces) // print stack trace once again for debugging: diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt index cd48fb2984b..82f7d84bf45 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt @@ -29,6 +29,7 @@ import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentExcepti import org.schabi.newpipe.ktx.isNetworkRelated import org.schabi.newpipe.player.mediasource.FailedMediaSource import org.schabi.newpipe.player.resolver.PlaybackResolver +import org.schabi.newpipe.util.text.getText /** * An error has occurred in the app. This class contains plain old parcelable data that can be used @@ -135,8 +136,8 @@ class ErrorInfo private constructor( return getServiceName(serviceId) } - fun getMessage(context: Context): String { - return message.getString(context) + fun getMessage(context: Context): CharSequence { + return message.getText(context) } companion object { @@ -146,20 +147,23 @@ class ErrorInfo private constructor( private val stringRes: Int, private vararg val formatArgs: String ) : Parcelable { - fun getString(context: Context): String { + fun getText(context: Context): CharSequence { + // Ensure locale aware context via ContextCompat.getContextForLanguage() (just in case context is not AppCompatActivity) + val ctx = ContextCompat.getContextForLanguage(context) return if (formatArgs.isEmpty()) { - // use ContextCompat.getString() just in case context is not AppCompatActivity - ContextCompat.getString(context, stringRes) + ctx.getText(stringRes) } else { // ContextCompat.getString() with formatArgs does not exist, so we just // replicate its source code but with formatArgs - ContextCompat.getContextForLanguage(context).getString(stringRes, *formatArgs) + ctx.resources.getText(stringRes, *formatArgs) } } } const val SERVICE_NONE = "" + const val YOUTUBE_IP_BAN_FAQ_URL = "https://newpipe.net/FAQ/#ip-banned-youtube" + private fun getServiceName(serviceId: Int?) = // not using getNameOfServiceById since we want to accept a nullable serviceId and we // want to default to SERVICE_NONE ServiceList.all().firstOrNull { it.serviceId == serviceId }?.serviceInfo?.name @@ -247,7 +251,11 @@ class ErrorInfo private constructor( ErrorMessage(R.string.youtube_music_premium_content) throwable is SignInConfirmNotBotException -> - ErrorMessage(R.string.sign_in_confirm_not_bot_error, getServiceName(serviceId)) + ErrorMessage( + R.string.sign_in_confirm_not_bot_error, + getServiceName(serviceId), + YOUTUBE_IP_BAN_FAQ_URL + ) throwable is ContentNotAvailableException -> ErrorMessage(R.string.content_not_available) diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorPanelHelper.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorPanelHelper.kt index 023d13e9d8d..8136c78d813 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorPanelHelper.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorPanelHelper.kt @@ -16,6 +16,7 @@ import org.schabi.newpipe.MainActivity import org.schabi.newpipe.R import org.schabi.newpipe.ktx.animate import org.schabi.newpipe.util.external_communication.ShareUtils +import org.schabi.newpipe.util.text.setTextWithLinks class ErrorPanelHelper( private val fragment: Fragment, @@ -64,7 +65,7 @@ class ErrorPanelHelper( fun showError(errorInfo: ErrorInfo) { ensureDefaultVisibility() - errorTextView.text = errorInfo.getMessage(context) + errorTextView.setTextWithLinks(errorInfo.getMessage(context)) if (errorInfo.recaptchaUrl != null) { showAndSetErrorButtonAction(R.string.recaptcha_solve) { @@ -109,7 +110,7 @@ class ErrorPanelHelper( fun showTextError(errorString: String) { ensureDefaultVisibility() - errorTextView.text = errorString + errorTextView.setTextWithLinks(errorString) setRootVisible() } diff --git a/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserPlaybackPreparer.kt b/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserPlaybackPreparer.kt index 890c83cfa8e..c0a2f966818 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserPlaybackPreparer.kt +++ b/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserPlaybackPreparer.kt @@ -49,7 +49,7 @@ import org.schabi.newpipe.util.NavigationHelper */ class MediaBrowserPlaybackPreparer( private val context: Context, - private val setMediaSessionError: BiConsumer, // error string, error code + private val setMediaSessionError: BiConsumer, // error string, error code private val clearMediaSessionError: Runnable, private val onPrepare: Consumer ) : PlaybackPreparer { @@ -118,7 +118,7 @@ class MediaBrowserPlaybackPreparer( private fun onPrepareError(throwable: Throwable) { setMediaSessionError.accept( - ErrorInfo.getMessage(throwable, null, null).getString(context), + ErrorInfo.getMessage(throwable, null, null).getText(context), PlaybackStateCompat.ERROR_CODE_APP_ERROR ) } diff --git a/app/src/main/java/org/schabi/newpipe/util/text/TextViewExtensions.kt b/app/src/main/java/org/schabi/newpipe/util/text/TextViewExtensions.kt new file mode 100644 index 00000000000..d2efbf5411a --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/util/text/TextViewExtensions.kt @@ -0,0 +1,29 @@ +package org.schabi.newpipe.util.text + +import android.content.res.Resources +import android.text.SpannableString +import android.text.method.LinkMovementMethod +import android.text.util.Linkify +import android.util.Patterns +import android.widget.TextView +import androidx.annotation.StringRes +import androidx.core.text.parseAsHtml +import androidx.core.text.toHtml +import androidx.core.text.toSpanned + +/** + * Takes in a CharSequence [text] + * and makes raw HTTP URLs and HTML anchor tags clickable + */ +fun TextView.setTextWithLinks(text: CharSequence) { + val spanned = SpannableString(text) + // Using the pattern overload of addLinks since the one with the int masks strips all spans from the text before applying new ones + Linkify.addLinks(spanned, Patterns.WEB_URL, null) + this.text = spanned + this.movementMethod = LinkMovementMethod.getInstance() +} + +/** + * Gets text from string resource with [id] while preserving styling and allowing string format value substitution of [formatArgs] + */ +fun Resources.getText(@StringRes id: Int, vararg formatArgs: Any?): CharSequence = getText(id).toSpanned().toHtml().format(*formatArgs).parseAsHtml() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5ecdb5e97ec..99dd1a74cdb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -878,7 +878,7 @@ HTTP error 403 received from server while playing, likely caused by streaming URL expiration or an IP ban HTTP error %1$s received from server while playing HTTP error 403 received from server while playing, likely caused by an IP ban or streaming URL deobfuscation issues - %1$s refused to provide data, asking for a login to confirm the requester is not a bot.\n\nYour IP might have been temporarily banned by %1$s, you can wait some time or switch to a different IP (for example by turning on/off a VPN, or by switching from WiFi to mobile data). + %1$s refused to provide data, asking for a login to confirm the requester is not a bot.\n\nYour IP might have been temporarily banned by %1$s, you can wait some time or switch to a different IP (for example by turning on/off a VPN, or by switching from WiFi to mobile data).\n\nPlease see this FAQ entry for more information. This content is not available for the currently selected content country.\n\nChange your selection from \"Settings > Content > Default content country\". In August 2025, Google announced that as of September 2026, installing apps will require developer verification for all Android apps on certified devices, including those installed outside of the Play Store. Since the developers of NewPipe do not agree to this requirement, NewPipe will no longer work on certified Android devices after that time. Details