Skip to content

Commit

Permalink
Merge pull request #8192 from GGAutomaton/fix-6696
Browse files Browse the repository at this point in the history
Fix crash when rotating device on unsupported channels
  • Loading branch information
Stypox authored May 6, 2022
2 parents a1435bd + 71e46d1 commit 5b435c5
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class ChannelFragment extends BaseListInfoFragment<StreamInfoItem, Channe
private final CompositeDisposable disposables = new CompositeDisposable();
private Disposable subscribeButtonMonitor;

private boolean channelContentNotSupported = false;

/*//////////////////////////////////////////////////////////////////////////
// Views
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -130,6 +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);
showContentNotSupportedIfNeeded();
}

@Override
Expand Down Expand Up @@ -524,9 +527,12 @@ public void handleResult(@NonNull final ChannelInfo result) {
playlistControlBinding.getRoot().setVisibility(View.GONE);
}

channelContentNotSupported = false;
for (final Throwable throwable : result.getErrors()) {
if (throwable instanceof ContentNotSupportedException) {
showContentNotSupported();
channelContentNotSupported = true;
showContentNotSupportedIfNeeded();
break;
}
}

Expand Down Expand Up @@ -558,7 +564,13 @@ public void handleResult(@NonNull final ChannelInfo result) {
});
}

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);
Expand Down

0 comments on commit 5b435c5

Please sign in to comment.