From e23392a4fe8e5fea44790c60e79c817a2f4d66e7 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Wed, 16 May 2018 10:34:38 -0700 Subject: [PATCH] Update views when a new track name provider is set Also update TrackSelectionView with nullness annotations. Issue: #4263 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=196849706 --- .../exoplayer2/ui/TrackSelectionView.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 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 45ccd783e7..be0babf5a8 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 @@ -21,6 +21,8 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.res.TypedArray; +import android.support.annotation.AttrRes; +import android.support.annotation.Nullable; import android.util.AttributeSet; import android.util.Pair; import android.view.LayoutInflater; @@ -54,7 +56,7 @@ public class TrackSelectionView extends LinearLayout { private int rendererIndex; private TrackGroupArray trackGroups; private boolean isDisabled; - private SelectionOverride override; + private @Nullable SelectionOverride override; /** * Gets a pair consisting of a dialog and the {@link TrackSelectionView} that will be shown by it. @@ -100,11 +102,13 @@ public class TrackSelectionView extends LinearLayout { this(context, null); } - public TrackSelectionView(Context context, AttributeSet attrs) { + public TrackSelectionView(Context context, @Nullable AttributeSet attrs) { this(context, attrs, 0); } - public TrackSelectionView(Context context, AttributeSet attrs, int defStyleAttr) { + @SuppressWarnings("nullness") + public TrackSelectionView( + Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray attributeArray = context @@ -152,7 +156,7 @@ public class TrackSelectionView extends LinearLayout { * @param allowAdaptiveSelections Whether adaptive selection is enabled. */ public void setAllowAdaptiveSelections(boolean allowAdaptiveSelections) { - if (!this.allowAdaptiveSelections == allowAdaptiveSelections) { + if (this.allowAdaptiveSelections != allowAdaptiveSelections) { this.allowAdaptiveSelections = allowAdaptiveSelections; updateViews(); } @@ -168,12 +172,14 @@ public class TrackSelectionView extends LinearLayout { } /** - * Sets the {@link TrackNameProvider} used to generate the user visible name of each track. + * Sets the {@link TrackNameProvider} used to generate the user visible name of each track and + * updates the view with track names queried from the specified provider. * * @param trackNameProvider The {@link TrackNameProvider} to use. */ public void setTrackNameProvider(TrackNameProvider trackNameProvider) { this.trackNameProvider = Assertions.checkNotNull(trackNameProvider); + updateViews(); } /** @@ -306,20 +312,20 @@ public class TrackSelectionView extends LinearLayout { override = new SelectionOverride(groupIndex, trackIndex); } else { // An existing override is being modified. - boolean isEnabled = ((CheckedTextView) view).isChecked(); int overrideLength = override.length; - if (isEnabled) { + int[] overrideTracks = override.tracks; + if (((CheckedTextView) view).isChecked()) { // Remove the track from the override. if (overrideLength == 1) { // The last track is being removed, so the override becomes empty. override = null; isDisabled = true; } else { - int[] tracks = getTracksRemoving(override.tracks, trackIndex); + int[] tracks = getTracksRemoving(overrideTracks, trackIndex); override = new SelectionOverride(groupIndex, tracks); } } else { - int[] tracks = getTracksAdding(override.tracks, trackIndex); + int[] tracks = getTracksAdding(overrideTracks, trackIndex); override = new SelectionOverride(groupIndex, tracks); } }