From 6d84d195204873535f64912cbb78ab259f3289cc Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Sun, 23 Oct 2022 15:37:40 +0200 Subject: [PATCH] fix: handle unsupported content --- .../list/channel/ChannelFragment.java | 41 +++++++++++++------ .../list/channel/ChannelVideosFragment.java | 4 +- app/src/main/res/layout/fragment_channel.xml | 32 +++++++++++++++ 3 files changed, 63 insertions(+), 14 deletions(-) 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 4938d1c00..4cd8313fc 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 @@ -21,6 +21,7 @@ import org.schabi.newpipe.databinding.FragmentChannelBinding; import org.schabi.newpipe.error.ErrorInfo; import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.extractor.channel.ChannelInfo; +import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; import org.schabi.newpipe.extractor.linkhandler.ChannelTabHandler; import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.fragments.detail.TabAdapter; @@ -247,20 +248,36 @@ public class ChannelFragment extends BaseStateFragment { // Init //////////////////////////////////////////////////////////////////////////*/ + private boolean isContentUnsupported() { + for (final Throwable throwable : currentInfo.getErrors()) { + if (throwable instanceof ContentNotSupportedException) { + return true; + } + } + return false; + } + private void updateTabs() { tabAdapter.clearAllItems(); if (currentInfo != null) { - tabAdapter.addFragment(ChannelVideosFragment.getInstance(currentInfo), "Videos"); - - for (final ChannelTabHandler tab : currentInfo.getTabs()) { + if (isContentUnsupported()) { + showEmptyState(); + binding.errorContentNotSupported.setVisibility(View.VISIBLE); + } else { tabAdapter.addFragment( - ChannelTabFragment.getInstance(serviceId, tab), tab.getTab().name()); - } + ChannelVideosFragment.getInstance(currentInfo), "Videos"); - final String description = currentInfo.getDescription(); - if (!description.isEmpty()) { - tabAdapter.addFragment(ChannelInfoFragment.getInstance(description), "Info"); + for (final ChannelTabHandler tab : currentInfo.getTabs()) { + tabAdapter.addFragment( + ChannelTabFragment.getInstance(serviceId, tab), tab.getTab().name()); + } + + final String description = currentInfo.getDescription(); + if (description != null && !description.isEmpty()) { + tabAdapter.addFragment( + ChannelInfoFragment.getInstance(description), "Info"); + } } } @@ -296,11 +313,11 @@ public class ChannelFragment extends BaseStateFragment { } @Override - public void handleResult(@NonNull final ChannelInfo info) { - super.handleResult(info); + public void handleResult(@NonNull final ChannelInfo result) { + super.handleResult(result); + currentInfo = result; + setInitialData(result.getServiceId(), result.getOriginalUrl(), result.getName()); - currentInfo = info; - setInitialData(info.getServiceId(), info.getOriginalUrl(), info.getName()); updateTabs(); updateRssButton(); monitorSubscription(); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelVideosFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelVideosFragment.java index f147e4f9d..23655dee2 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelVideosFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelVideosFragment.java @@ -132,13 +132,13 @@ public class ChannelVideosFragment extends BaseListInfoFragment + + + + + + + +