mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
fix: handle unsupported content
This commit is contained in:
parent
8627efd0a1
commit
6d84d19520
@ -21,6 +21,7 @@ import org.schabi.newpipe.databinding.FragmentChannelBinding;
|
|||||||
import org.schabi.newpipe.error.ErrorInfo;
|
import org.schabi.newpipe.error.ErrorInfo;
|
||||||
import org.schabi.newpipe.error.UserAction;
|
import org.schabi.newpipe.error.UserAction;
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelInfo;
|
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.extractor.linkhandler.ChannelTabHandler;
|
||||||
import org.schabi.newpipe.fragments.BaseStateFragment;
|
import org.schabi.newpipe.fragments.BaseStateFragment;
|
||||||
import org.schabi.newpipe.fragments.detail.TabAdapter;
|
import org.schabi.newpipe.fragments.detail.TabAdapter;
|
||||||
@ -247,20 +248,36 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo> {
|
|||||||
// Init
|
// Init
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
private boolean isContentUnsupported() {
|
||||||
|
for (final Throwable throwable : currentInfo.getErrors()) {
|
||||||
|
if (throwable instanceof ContentNotSupportedException) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateTabs() {
|
private void updateTabs() {
|
||||||
tabAdapter.clearAllItems();
|
tabAdapter.clearAllItems();
|
||||||
|
|
||||||
if (currentInfo != null) {
|
if (currentInfo != null) {
|
||||||
tabAdapter.addFragment(ChannelVideosFragment.getInstance(currentInfo), "Videos");
|
if (isContentUnsupported()) {
|
||||||
|
showEmptyState();
|
||||||
for (final ChannelTabHandler tab : currentInfo.getTabs()) {
|
binding.errorContentNotSupported.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
tabAdapter.addFragment(
|
tabAdapter.addFragment(
|
||||||
ChannelTabFragment.getInstance(serviceId, tab), tab.getTab().name());
|
ChannelVideosFragment.getInstance(currentInfo), "Videos");
|
||||||
}
|
|
||||||
|
|
||||||
final String description = currentInfo.getDescription();
|
for (final ChannelTabHandler tab : currentInfo.getTabs()) {
|
||||||
if (!description.isEmpty()) {
|
tabAdapter.addFragment(
|
||||||
tabAdapter.addFragment(ChannelInfoFragment.getInstance(description), "Info");
|
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<ChannelInfo> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleResult(@NonNull final ChannelInfo info) {
|
public void handleResult(@NonNull final ChannelInfo result) {
|
||||||
super.handleResult(info);
|
super.handleResult(result);
|
||||||
|
currentInfo = result;
|
||||||
|
setInitialData(result.getServiceId(), result.getOriginalUrl(), result.getName());
|
||||||
|
|
||||||
currentInfo = info;
|
|
||||||
setInitialData(info.getServiceId(), info.getOriginalUrl(), info.getName());
|
|
||||||
updateTabs();
|
updateTabs();
|
||||||
updateRssButton();
|
updateRssButton();
|
||||||
monitorSubscription();
|
monitorSubscription();
|
||||||
|
@ -132,13 +132,13 @@ public class ChannelVideosFragment extends BaseListInfoFragment<StreamInfoItem,
|
|||||||
public View onCreateView(@NonNull final LayoutInflater inflater,
|
public View onCreateView(@NonNull final LayoutInflater inflater,
|
||||||
@Nullable final ViewGroup container,
|
@Nullable final ViewGroup container,
|
||||||
@Nullable final Bundle savedInstanceState) {
|
@Nullable final Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.fragment_channel_videos, container, false);
|
channelBinding = FragmentChannelVideosBinding.inflate(inflater, container, false);
|
||||||
|
return channelBinding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull final View rootView, final Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull final View rootView, final Bundle savedInstanceState) {
|
||||||
super.onViewCreated(rootView, savedInstanceState);
|
super.onViewCreated(rootView, savedInstanceState);
|
||||||
channelBinding = FragmentChannelVideosBinding.bind(rootView);
|
|
||||||
showContentNotSupportedIfNeeded();
|
showContentNotSupportedIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,38 @@
|
|||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/empty_state_view"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingTop="90dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
<org.schabi.newpipe.views.NewPipeTextView
|
||||||
|
android:id="@+id/channel_kaomoji"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:fontFamily="monospace"
|
||||||
|
android:text="(︶︹︺)"
|
||||||
|
android:textSize="35sp"
|
||||||
|
tools:ignore="HardcodedText,UnusedAttribute" />
|
||||||
|
|
||||||
|
<org.schabi.newpipe.views.NewPipeTextView
|
||||||
|
android:id="@+id/error_content_not_supported"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:text="@string/content_not_supported"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<!--ERROR PANEL-->
|
<!--ERROR PANEL-->
|
||||||
<include
|
<include
|
||||||
android:id="@+id/error_panel"
|
android:id="@+id/error_panel"
|
||||||
|
Loading…
Reference in New Issue
Block a user