From 5e50e110a4580247ac41003dfc3aa7007160d273 Mon Sep 17 00:00:00 2001 From: insun Date: Sun, 12 Jul 2020 03:49:56 +0100 Subject: [PATCH] Mark currently selected subtitle track in track list Previously, the automatically selected subtitle track has not been marked (with check mark) in subtitle track list, just like audio track. But, in subtitle track option UI, there is no 'auto' option, which is different from audio track selection menu. This CL marks the auto selected subtitle track name in the cc list. PiperOrigin-RevId: 320802575 --- .../ui/StyledPlayerControlView.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java index 17529254e7..3e320a9945 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java @@ -1982,6 +1982,18 @@ public class StyledPlayerControlView extends FrameLayout { List rendererIndices, List trackInfos, MappedTrackInfo mappedTrackInfo) { + boolean subtitleIsOn = false; + for (int i = 0; i < trackInfos.size(); i++) { + if (trackInfos.get(i).selected) { + subtitleIsOn = true; + break; + } + } + checkNotNull(subtitleButton) + .setImageDrawable(subtitleIsOn ? subtitleOnButtonDrawable : subtitleOffButtonDrawable); + checkNotNull(subtitleButton) + .setContentDescription( + subtitleIsOn ? subtitleOnContentDescription : subtitleOffContentDescription); this.rendererIndices = rendererIndices; this.tracks = trackInfos; this.mappedTrackInfo = mappedTrackInfo; @@ -2013,10 +2025,6 @@ public class StyledPlayerControlView extends FrameLayout { .setRendererDisabled(rendererIndex, true); } checkNotNull(trackSelector).setParameters(parametersBuilder); - if (showSubtitleButton) { - checkNotNull(subtitleButton).setImageDrawable(subtitleOffButtonDrawable); - checkNotNull(subtitleButton).setContentDescription(subtitleOffContentDescription); - } settingsWindow.dismiss(); } } @@ -2024,12 +2032,18 @@ public class StyledPlayerControlView extends FrameLayout { } @Override - public void onTrackSelection(String subtext) { - if (showSubtitleButton) { - checkNotNull(subtitleButton).setImageDrawable(subtitleOnButtonDrawable); - checkNotNull(subtitleButton).setContentDescription(subtitleOnContentDescription); + public void onBindViewHolder(TrackSelectionViewHolder holder, int position) { + super.onBindViewHolder(holder, position); + if (position > 0) { + TrackInfo track = tracks.get(position - 1); + holder.checkView.setVisibility(track.selected ? VISIBLE : INVISIBLE); } } + + @Override + public void onTrackSelection(String subtext) { + // No-op + } } private final class AudioTrackSelectionAdapter extends TrackSelectionAdapter { @@ -2102,8 +2116,8 @@ public class StyledPlayerControlView extends FrameLayout { SETTINGS_AUDIO_TRACK_SELECTION_POSITION, getResources().getString(R.string.exo_track_selection_auto)); } else { - for (int i = 0; i < tracks.size(); i++) { - TrackInfo track = tracks.get(i); + for (int i = 0; i < trackInfos.size(); i++) { + TrackInfo track = trackInfos.get(i); if (track.selected) { settingsAdapter.updateSubTexts( SETTINGS_AUDIO_TRACK_SELECTION_POSITION, track.trackName);