1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 00:20:32 +00:00

fix: sonarcloud lint

This commit is contained in:
ThetaDev 2023-03-19 22:55:37 +01:00
parent 61a14765f3
commit dbd6e4d11f
3 changed files with 21 additions and 18 deletions

View File

@ -657,13 +657,10 @@ public final class PlayQueueActivity extends AppCompatActivity
* @param itemId index of the selected item * @param itemId index of the selected item
*/ */
private void onAudioTrackClick(final int itemId) { private void onAudioTrackClick(final int itemId) {
@Nullable final MediaItemTag currentMetadata = player.getCurrentMetadata(); if (player.getCurrentMetadata() == null) {
if (currentMetadata == null || currentMetadata.getMaybeAudioTrack().isEmpty()) {
return; return;
} }
player.getCurrentMetadata().getMaybeAudioTrack().ifPresent(audioTrack -> {
final MediaItemTag.AudioTrack audioTrack =
currentMetadata.getMaybeAudioTrack().get();
final List<AudioStream> availableStreams = audioTrack.getAudioStreams(); final List<AudioStream> availableStreams = audioTrack.getAudioStreams();
final int selectedStreamIndex = audioTrack.getSelectedAudioStreamIndex(); final int selectedStreamIndex = audioTrack.getSelectedAudioStreamIndex();
if (selectedStreamIndex == itemId || availableStreams.size() <= itemId) { if (selectedStreamIndex == itemId || availableStreams.size() <= itemId) {
@ -675,5 +672,6 @@ public final class PlayQueueActivity extends AppCompatActivity
player.setRecovery(); player.setRecovery();
player.setAudioTrack(newAudioTrack); player.setAudioTrack(newAudioTrack);
player.reloadPlayQueueManager(); player.reloadPlayQueueManager();
});
} }
} }

View File

@ -239,13 +239,12 @@ public final class ListHelper {
} }
// Filter unknown audio tracks if there are multiple tracks // Filter unknown audio tracks if there are multiple tracks
java.util.stream.Stream<AudioStream> cs = collectedStreams.values().stream();
if (collectedStreams.size() > 1) { if (collectedStreams.size() > 1) {
cs = cs.filter(s -> s.getAudioTrackId() != null); collectedStreams.remove("");
} }
// Sort collected streams by name // Sort collected streams by name
return cs.sorted(Comparator.comparing(audioStream -> return collectedStreams.values().stream().sorted(Comparator.comparing(audioStream ->
Localization.audioTrackName(context, audioStream))).collect(Collectors.toList()); Localization.audioTrackName(context, audioStream))).collect(Collectors.toList());
} }

View File

@ -390,6 +390,12 @@ public class ListHelperTest {
stream = AUDIO_TRACKS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank( stream = AUDIO_TRACKS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
null, AUDIO_TRACKS_TEST_LIST, cmp)); null, AUDIO_TRACKS_TEST_LIST, cmp));
assertEquals("en.ds", stream.getId()); assertEquals("en.ds", stream.getId());
// Japanese language, fall back to original
cmp = ListHelper.getAudioStreamComparator(Locale.JAPANESE, true, false, false);
stream = AUDIO_TRACKS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
null, AUDIO_TRACKS_TEST_LIST, cmp));
assertEquals("en.or", stream.getId());
} }
@Test @Test