From 551b6d65ae137e38359ba6762016e7fb481eafd4 Mon Sep 17 00:00:00 2001 From: Yoni Obadia Date: Thu, 27 Aug 2020 10:15:17 +0200 Subject: [PATCH] Review: Simplify getSortedIndexFromInitialTrackGroup --- .../android/exoplayer2/ui/TrackSelectionView.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionView.java index 79fa172e18..3d33e0db02 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionView.java @@ -304,7 +304,7 @@ public class TrackSelectionView extends LinearLayout { SelectionOverride override = overrides.get(i); for (int j = 0; j < trackViews[i].length; j++) { if(override != null) { - int sortedIndex = getSortedIndexFromInitialTrackGroup(override.groupIndex, j); + int sortedIndex = getSortedIndexFromInitialTrackGroup(j); trackViews[i][j].setChecked(override.containsTrack(sortedIndex)); } else { trackViews[i][j].setChecked(false); @@ -342,7 +342,7 @@ public class TrackSelectionView extends LinearLayout { @SuppressWarnings("unchecked") Pair tag = (Pair) Assertions.checkNotNull(view.getTag()); int groupIndex = tag.first; - int trackIndex = getSortedIndexFromInitialTrackGroup(tag.first, tag.second); + int trackIndex = getSortedIndexFromInitialTrackGroup(tag.second); SelectionOverride override = overrides.get(groupIndex); Assertions.checkNotNull(mappedTrackInfo); if (override == null) { @@ -404,20 +404,14 @@ public class TrackSelectionView extends LinearLayout { * asc sorted array (only quality for this example) : [256,480,720,1080] * initial array index for 480 is 0, but for sorted array index is 1. * Initial array index is @param trackIndex, and the @return result is sorted array index - * @param groupIndex which TrackGroup you want to browse into * @param trackIndex which index of the initial array * @return index of the sorted array that correspond to the same element in the initial array */ - private int getSortedIndexFromInitialTrackGroup(int groupIndex, int trackIndex) { + private int getSortedIndexFromInitialTrackGroup(int trackIndex) { int sortedTrackIndex = trackIndex; if(sortedTrackGroups != trackGroups) { Format selectedFormat = sortedTrackGroups.get(rendererIndex).getFormat(trackIndex); - for (int formatIndex = 0; formatIndex < trackGroups.get(groupIndex).length; formatIndex++) { - if(trackGroups.get(groupIndex).getFormat(formatIndex) == selectedFormat) { - sortedTrackIndex = formatIndex; - break; - } - } + sortedTrackIndex = trackGroups.get(rendererIndex).indexOf(selectedFormat); } return sortedTrackIndex; }