From b4cabe23e3f6cadf0e2cee6887319b3959c8ea28 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Thu, 26 Mar 2020 23:58:01 -0300 Subject: [PATCH] Handle content not available exception more comprehensively --- .../newpipe/fragments/BaseStateFragment.java | 4 ++++ .../fragments/detail/VideoDetailFragment.java | 21 ++++++------------- .../list/channel/ChannelFragment.java | 16 ++++++-------- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index 8e328266e..f9852b7b0 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -17,6 +17,7 @@ import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.ReCaptchaActivity; +import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; @@ -181,6 +182,9 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC if (exception instanceof ReCaptchaException) { onReCaptchaException((ReCaptchaException) exception); return true; + } else if (exception instanceof ContentNotAvailableException) { + showError(getString(R.string.content_not_available), false); + return true; } else if (exception instanceof IOException) { showError(getString(R.string.network_error), true); return true; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 86198650c..ebec8db0a 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -51,7 +51,6 @@ import org.schabi.newpipe.download.DownloadDialog; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ServiceList; -import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; @@ -1220,20 +1219,12 @@ public class VideoDetailFragment protected boolean onError(Throwable exception) { if (super.onError(exception)) return true; - else if (exception instanceof ContentNotAvailableException) { - showError(getString(R.string.content_not_available), false); - } else { - int errorId = exception instanceof YoutubeStreamExtractor.DecryptException - ? R.string.youtube_signature_decryption_error - : exception instanceof ParsingException - ? R.string.parsing_error - : R.string.general_error; - onUnrecoverableError(exception, - UserAction.REQUESTED_STREAM, - NewPipe.getNameOfService(serviceId), - url, - errorId); - } + int errorId = exception instanceof YoutubeStreamExtractor.DecryptException ? R.string.youtube_signature_decryption_error + : exception instanceof ExtractionException ? R.string.parsing_error + : R.string.general_error; + + onUnrecoverableError(exception, UserAction.REQUESTED_STREAM, + NewPipe.getNameOfService(serviceId), url, errorId); return true; } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 3615b0922..40df990f9 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -440,16 +440,12 @@ public class ChannelFragment extends BaseListInfoFragment { protected boolean onError(Throwable exception) { if (super.onError(exception)) return true; - if (exception instanceof ContentNotAvailableException) { - showError(getString(R.string.content_not_available), false); - } else { - int errorId = exception instanceof ExtractionException ? R.string.parsing_error : R.string.general_error; - onUnrecoverableError(exception, - UserAction.REQUESTED_CHANNEL, - NewPipe.getNameOfService(serviceId), - url, - errorId); - } + int errorId = exception instanceof ExtractionException + ? R.string.parsing_error : R.string.general_error; + + onUnrecoverableError(exception, UserAction.REQUESTED_CHANNEL, + NewPipe.getNameOfService(serviceId), url, errorId); + return true; }