From 2e771cd65ab1eff2cb090351a4083d1d129fe53a Mon Sep 17 00:00:00 2001 From: GGAutomaton <32899400+GGAutomaton@users.noreply.github.com> Date: Mon, 4 Apr 2022 23:58:39 +0800 Subject: [PATCH 1/4] Fix crash when rotating device on unsupported channels --- .../fragments/list/channel/ChannelFragment.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 869503b5bed..6ad81132002 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 @@ -77,6 +77,8 @@ public class ChannelFragment extends BaseListInfoFragment Date: Wed, 4 May 2022 23:34:07 +0800 Subject: [PATCH 2/4] Show "content not supported" if needed --- .../list/channel/ChannelFragment.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 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 6ad81132002..0f268410b22 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 @@ -132,9 +132,7 @@ public View onCreateView(@NonNull final LayoutInflater inflater, public void onViewCreated(@NonNull final View rootView, final Bundle savedInstanceState) { super.onViewCreated(rootView, savedInstanceState); channelBinding = FragmentChannelBinding.bind(rootView); - if (channelContentNotSupported) { - showContentNotSupported(); - } + showContentNotSupportedIfNeeded(); } @Override @@ -532,12 +530,8 @@ public void handleResult(@NonNull final ChannelInfo result) { channelContentNotSupported = false; for (final Throwable throwable : result.getErrors()) { if (throwable instanceof ContentNotSupportedException) { - /* - channelBinding might not be initialized when handleResult() is called - (e.g. after rotating the screen, https://github.com/TeamNewPipe/NewPipe/issues/6696) - showContentNotSupported() will be called later - */ channelContentNotSupported = true; + showContentNotSupportedIfNeeded(); } } @@ -569,7 +563,13 @@ channelBinding might not be initialized when handleResult() is called }); } - private void showContentNotSupported() { + private void showContentNotSupportedIfNeeded() { + // channelBinding might not be initialized when handleResult() is called + // (e.g. after rotating the screen, #6696) + if (!channelContentNotSupported || channelBinding == null) { + return; + } + channelBinding.errorContentNotSupported.setVisibility(View.VISIBLE); channelBinding.channelKaomoji.setText("(︶︹︺)"); channelBinding.channelKaomoji.setTextSize(TypedValue.COMPLEX_UNIT_SP, 45f); From 238aff7c31549717753b7f42d14f2ab0d5b650ff Mon Sep 17 00:00:00 2001 From: Stypox Date: Fri, 6 May 2022 10:38:47 +0200 Subject: [PATCH 3/4] channelContentNotSupported false by default --- .../schabi/newpipe/fragments/list/channel/ChannelFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0f268410b22..4f70df6f4f3 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 @@ -77,7 +77,7 @@ public class ChannelFragment extends BaseListInfoFragment Date: Fri, 6 May 2022 10:40:08 +0200 Subject: [PATCH 4/4] Do not call showContentNotSupportedIfNeeded multiple times --- .../schabi/newpipe/fragments/list/channel/ChannelFragment.java | 1 + 1 file changed, 1 insertion(+) 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 4f70df6f4f3..fa8f5fdbd96 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 @@ -532,6 +532,7 @@ public void handleResult(@NonNull final ChannelInfo result) { if (throwable instanceof ContentNotSupportedException) { channelContentNotSupported = true; showContentNotSupportedIfNeeded(); + break; } }