1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-22 16:10:31 +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,23 +657,21 @@ public final class PlayQueueActivity extends AppCompatActivity
* @param itemId index of the selected item
*/
private void onAudioTrackClick(final int itemId) {
@Nullable final MediaItemTag currentMetadata = player.getCurrentMetadata();
if (currentMetadata == null || currentMetadata.getMaybeAudioTrack().isEmpty()) {
if (player.getCurrentMetadata() == null) {
return;
}
player.getCurrentMetadata().getMaybeAudioTrack().ifPresent(audioTrack -> {
final List<AudioStream> availableStreams = audioTrack.getAudioStreams();
final int selectedStreamIndex = audioTrack.getSelectedAudioStreamIndex();
if (selectedStreamIndex == itemId || availableStreams.size() <= itemId) {
return;
}
final MediaItemTag.AudioTrack audioTrack =
currentMetadata.getMaybeAudioTrack().get();
final List<AudioStream> availableStreams = audioTrack.getAudioStreams();
final int selectedStreamIndex = audioTrack.getSelectedAudioStreamIndex();
if (selectedStreamIndex == itemId || availableStreams.size() <= itemId) {
return;
}
player.saveStreamProgressState();
final String newAudioTrack = availableStreams.get(itemId).getAudioTrackId();
player.setRecovery();
player.setAudioTrack(newAudioTrack);
player.reloadPlayQueueManager();
player.saveStreamProgressState();
final String newAudioTrack = availableStreams.get(itemId).getAudioTrackId();
player.setRecovery();
player.setAudioTrack(newAudioTrack);
player.reloadPlayQueueManager();
});
}
}

View File

@ -239,13 +239,12 @@ public final class ListHelper {
}
// Filter unknown audio tracks if there are multiple tracks
java.util.stream.Stream<AudioStream> cs = collectedStreams.values().stream();
if (collectedStreams.size() > 1) {
cs = cs.filter(s -> s.getAudioTrackId() != null);
collectedStreams.remove("");
}
// 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());
}

View File

@ -390,6 +390,12 @@ public class ListHelperTest {
stream = AUDIO_TRACKS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
null, AUDIO_TRACKS_TEST_LIST, cmp));
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