From 4863084fa2565f674a0eedcff429abdabda60185 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 18 Jun 2022 17:49:04 +0200 Subject: [PATCH] Improve code in VideoDetailFragment --- .../fragments/detail/VideoDetailFragment.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) 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 100af41cc..cbd8b05b4 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 @@ -1555,13 +1555,11 @@ public final class VideoDetailFragment binding.detailSubChannelThumbnailView.setImageDrawable(buddyDrawable); binding.detailUploaderThumbnailView.setImageDrawable(buddyDrawable); - final StreamType streamType = info.getStreamType(); - if (info.getViewCount() >= 0) { - if (streamType.equals(StreamType.AUDIO_LIVE_STREAM)) { + if (info.getStreamType().equals(StreamType.AUDIO_LIVE_STREAM)) { binding.detailViewCountView.setText(Localization.listeningCount(activity, info.getViewCount())); - } else if (streamType.equals(StreamType.LIVE_STREAM)) { + } else if (info.getStreamType().equals(StreamType.LIVE_STREAM)) { binding.detailViewCountView.setText(Localization .localizeWatchingCount(activity, info.getViewCount())); } else { @@ -1648,7 +1646,7 @@ public final class VideoDetailFragment } binding.detailControlsDownload.setVisibility( - StreamTypeUtil.isLiveStream(streamType) ? View.GONE : View.VISIBLE); + StreamTypeUtil.isLiveStream(info.getStreamType()) ? View.GONE : View.VISIBLE); binding.detailControlsBackground.setVisibility(info.getAudioStreams().isEmpty() ? View.GONE : View.VISIBLE); @@ -2151,21 +2149,24 @@ public final class VideoDetailFragment return; } - final List videoStreams = getNonUrlAndNonTorrentStreams( - currentInfo.getVideoStreams()); - final List videoOnlyStreams = getNonUrlAndNonTorrentStreams( - currentInfo.getVideoOnlyStreams()); - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.select_quality_external_players); builder.setNeutralButton(R.string.open_in_browser, (dialog, i) -> ShareUtils.openUrlInBrowser(requireActivity(), url)); + final List videoStreamsForExternalPlayers = - ListHelper.getSortedStreamVideosList(activity, videoStreams, videoOnlyStreams, - false, false); + ListHelper.getSortedStreamVideosList( + activity, + getNonUrlAndNonTorrentStreams(currentInfo.getVideoStreams()), + getNonUrlAndNonTorrentStreams(currentInfo.getVideoOnlyStreams()), + false, + false + ); + if (videoStreamsForExternalPlayers.isEmpty()) { builder.setMessage(R.string.no_video_streams_available_for_external_players); builder.setPositiveButton(R.string.ok, null); + } else { final int selectedVideoStreamIndexForExternalPlayers = ListHelper.getDefaultResolutionIndex(activity, videoStreamsForExternalPlayers);