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 * @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 List<AudioStream> availableStreams = audioTrack.getAudioStreams();
final int selectedStreamIndex = audioTrack.getSelectedAudioStreamIndex();
if (selectedStreamIndex == itemId || availableStreams.size() <= itemId) {
return;
}
final MediaItemTag.AudioTrack audioTrack = player.saveStreamProgressState();
currentMetadata.getMaybeAudioTrack().get(); final String newAudioTrack = availableStreams.get(itemId).getAudioTrackId();
final List<AudioStream> availableStreams = audioTrack.getAudioStreams(); player.setRecovery();
final int selectedStreamIndex = audioTrack.getSelectedAudioStreamIndex(); player.setAudioTrack(newAudioTrack);
if (selectedStreamIndex == itemId || availableStreams.size() <= itemId) { player.reloadPlayQueueManager();
return; });
}
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 // 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