Commit 899a78fc by olly Committed by Oliver Woodman

StyledPlayerControlView: Some cleanup

PiperOrigin-RevId: 322317638
parent 63ca2b00
...@@ -640,23 +640,29 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -640,23 +640,29 @@ public class StyledPlayerControlView extends FrameLayout {
} }
// Related to Settings List View // Related to Settings List View
List<String> settingsMainTextsList = String[] settingTexts = new String[2];
Arrays.asList(resources.getStringArray(R.array.exo_settings_main_texts)); Drawable[] settingIcons = new Drawable[2];
TypedArray settingsIconTypedArray = resources.obtainTypedArray(R.array.exo_settings_icon_ids); settingTexts[SETTINGS_PLAYBACK_SPEED_POSITION] =
resources.getString(R.string.exo_controls_playback_speed);
settingIcons[SETTINGS_PLAYBACK_SPEED_POSITION] =
resources.getDrawable(R.drawable.exo_styled_controls_speed);
settingTexts[SETTINGS_AUDIO_TRACK_SELECTION_POSITION] =
resources.getString(R.string.exo_track_selection_title_audio);
settingIcons[SETTINGS_AUDIO_TRACK_SELECTION_POSITION] =
resources.getDrawable(R.drawable.exo_styled_controls_audiotrack);
settingsAdapter = new SettingsAdapter(settingTexts, settingIcons);
playbackSpeedTextList = playbackSpeedTextList =
new ArrayList<>(Arrays.asList(resources.getStringArray(R.array.exo_playback_speeds))); new ArrayList<>(Arrays.asList(resources.getStringArray(R.array.exo_playback_speeds)));
String normalSpeed = resources.getString(R.string.exo_controls_playback_speed_normal);
selectedPlaybackSpeedIndex = playbackSpeedTextList.indexOf(normalSpeed);
playbackSpeedMultBy100List = new ArrayList<>(); playbackSpeedMultBy100List = new ArrayList<>();
int[] speeds = resources.getIntArray(R.array.exo_speed_multiplied_by_100); int[] speeds = resources.getIntArray(R.array.exo_speed_multiplied_by_100);
for (int speed : speeds) { for (int speed : speeds) {
playbackSpeedMultBy100List.add(speed); playbackSpeedMultBy100List.add(speed);
} }
selectedPlaybackSpeedIndex = playbackSpeedMultBy100List.indexOf(100);
customPlaybackSpeedIndex = UNDEFINED_POSITION; customPlaybackSpeedIndex = UNDEFINED_POSITION;
settingsWindowMargin = resources.getDimensionPixelSize(R.dimen.exo_settings_offset); settingsWindowMargin = resources.getDimensionPixelSize(R.dimen.exo_settings_offset);
settingsAdapter = new SettingsAdapter(settingsMainTextsList, settingsIconTypedArray);
subSettingsAdapter = new SubSettingsAdapter(); subSettingsAdapter = new SubSettingsAdapter();
subSettingsAdapter.setCheckPosition(UNDEFINED_POSITION); subSettingsAdapter.setCheckPosition(UNDEFINED_POSITION);
settingsView = settingsView =
...@@ -1431,7 +1437,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1431,7 +1437,7 @@ public class StyledPlayerControlView extends FrameLayout {
} }
selectedPlaybackSpeedIndex = indexForCurrentSpeed; selectedPlaybackSpeedIndex = indexForCurrentSpeed;
settingsAdapter.updateSubTexts( settingsAdapter.setSubTextAtPosition(
SETTINGS_PLAYBACK_SPEED_POSITION, playbackSpeedTextList.get(indexForCurrentSpeed)); SETTINGS_PLAYBACK_SPEED_POSITION, playbackSpeedTextList.get(indexForCurrentSpeed));
} }
...@@ -1538,6 +1544,30 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1538,6 +1544,30 @@ public class StyledPlayerControlView extends FrameLayout {
} }
} }
private void onSettingViewClicked(int position) {
if (position == SETTINGS_PLAYBACK_SPEED_POSITION) {
subSettingsAdapter.setTexts(playbackSpeedTextList);
subSettingsAdapter.setCheckPosition(selectedPlaybackSpeedIndex);
selectedMainSettingsPosition = SETTINGS_PLAYBACK_SPEED_POSITION;
displaySettingsWindow(subSettingsAdapter);
} else if (position == SETTINGS_AUDIO_TRACK_SELECTION_POSITION) {
selectedMainSettingsPosition = SETTINGS_AUDIO_TRACK_SELECTION_POSITION;
displaySettingsWindow(audioTrackSelectionAdapter);
} else {
settingsWindow.dismiss();
}
}
private void onSubSettingViewClicked(int position) {
if (selectedMainSettingsPosition == SETTINGS_PLAYBACK_SPEED_POSITION) {
if (position != selectedPlaybackSpeedIndex) {
float speed = playbackSpeedMultBy100List.get(position) / 100.0f;
setPlaybackSpeed(speed);
}
}
settingsWindow.dismiss();
}
private void onLayoutChange( private void onLayoutChange(
View v, View v,
int left, int left,
...@@ -1796,38 +1826,38 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1796,38 +1826,38 @@ public class StyledPlayerControlView extends FrameLayout {
} }
} }
private class SettingsAdapter extends RecyclerView.Adapter<SettingsAdapter.SettingsViewHolder> { private class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolder> {
private List<String> mainTexts; private final String[] mainTexts;
@Nullable private List<String> subTexts; private final String[] subTexts;
@Nullable private TypedArray iconIds; private final Drawable[] iconIds;
public SettingsAdapter(List<String> mainTexts, @Nullable TypedArray iconIds) { public SettingsAdapter(String[] mainTexts, Drawable[] iconIds) {
this.mainTexts = mainTexts; this.mainTexts = mainTexts;
this.subTexts = Arrays.asList(new String[mainTexts.size()]); this.subTexts = new String[mainTexts.length];
this.iconIds = iconIds; this.iconIds = iconIds;
} }
@Override @Override
public SettingsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { public SettingViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = View v =
LayoutInflater.from(getContext()).inflate(R.layout.exo_styled_settings_list_item, null); LayoutInflater.from(getContext()).inflate(R.layout.exo_styled_settings_list_item, null);
return new SettingsViewHolder(v); return new SettingViewHolder(v);
} }
@Override @Override
public void onBindViewHolder(SettingsViewHolder holder, int position) { public void onBindViewHolder(SettingViewHolder holder, int position) {
holder.mainTextView.setText(mainTexts.get(position)); holder.mainTextView.setText(mainTexts[position]);
if (subTexts == null || subTexts.get(position) == null) { if (subTexts[position] == null) {
holder.subTextView.setVisibility(GONE); holder.subTextView.setVisibility(GONE);
} else { } else {
holder.subTextView.setText(subTexts.get(position)); holder.subTextView.setText(subTexts[position]);
} }
if (iconIds == null || iconIds.getDrawable(position) == null) { if (iconIds[position] == null) {
holder.iconView.setVisibility(GONE); holder.iconView.setVisibility(GONE);
} else { } else {
holder.iconView.setImageDrawable(iconIds.getDrawable(position)); holder.iconView.setImageDrawable(iconIds[position]);
} }
} }
...@@ -1838,65 +1868,43 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1838,65 +1868,43 @@ public class StyledPlayerControlView extends FrameLayout {
@Override @Override
public int getItemCount() { public int getItemCount() {
return mainTexts.size(); return mainTexts.length;
} }
public void updateSubTexts(int position, String subText) { public void setSubTextAtPosition(int position, String subText) {
if (this.subTexts != null) { this.subTexts[position] = subText;
this.subTexts.set(position, subText);
}
} }
}
private class SettingsViewHolder extends RecyclerView.ViewHolder { private class SettingViewHolder extends RecyclerView.ViewHolder {
TextView mainTextView; private final TextView mainTextView;
TextView subTextView; private final TextView subTextView;
ImageView iconView; private final ImageView iconView;
SettingsViewHolder(View itemView) {
super(itemView);
mainTextView = itemView.findViewById(R.id.exo_main_text);
subTextView = itemView.findViewById(R.id.exo_sub_text);
iconView = itemView.findViewById(R.id.exo_icon);
itemView.setOnClickListener(
v -> {
int position = SettingsViewHolder.this.getAdapterPosition();
if (position == RecyclerView.NO_POSITION) {
return;
}
if (position == SETTINGS_PLAYBACK_SPEED_POSITION) { public SettingViewHolder(View itemView) {
subSettingsAdapter.setTexts(playbackSpeedTextList); super(itemView);
subSettingsAdapter.setCheckPosition(selectedPlaybackSpeedIndex); mainTextView = itemView.findViewById(R.id.exo_main_text);
selectedMainSettingsPosition = SETTINGS_PLAYBACK_SPEED_POSITION; subTextView = itemView.findViewById(R.id.exo_sub_text);
displaySettingsWindow(subSettingsAdapter); iconView = itemView.findViewById(R.id.exo_icon);
} else if (position == SETTINGS_AUDIO_TRACK_SELECTION_POSITION) { itemView.setOnClickListener(
selectedMainSettingsPosition = SETTINGS_AUDIO_TRACK_SELECTION_POSITION; v -> onSettingViewClicked(SettingViewHolder.this.getAdapterPosition()));
displaySettingsWindow(audioTrackSelectionAdapter);
} else {
settingsWindow.dismiss();
}
});
}
} }
} }
private class SubSettingsAdapter private class SubSettingsAdapter extends RecyclerView.Adapter<SubSettingViewHolder> {
extends RecyclerView.Adapter<SubSettingsAdapter.SubSettingsViewHolder> {
@Nullable private List<String> texts; @Nullable private List<String> texts;
private int checkPosition; private int checkPosition;
@Override @Override
public SubSettingsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public SubSettingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = View v =
LayoutInflater.from(getContext()) LayoutInflater.from(getContext())
.inflate(R.layout.exo_styled_sub_settings_list_item, null); .inflate(R.layout.exo_styled_sub_settings_list_item, null);
return new SubSettingsViewHolder(v); return new SubSettingViewHolder(v);
} }
@Override @Override
public void onBindViewHolder(SubSettingsViewHolder holder, int position) { public void onBindViewHolder(SubSettingViewHolder holder, int position) {
if (texts != null) { if (texts != null) {
holder.textView.setText(texts.get(position)); holder.textView.setText(texts.get(position));
} }
...@@ -1915,33 +1923,18 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1915,33 +1923,18 @@ public class StyledPlayerControlView extends FrameLayout {
public void setCheckPosition(int checkPosition) { public void setCheckPosition(int checkPosition) {
this.checkPosition = checkPosition; this.checkPosition = checkPosition;
} }
}
private class SubSettingsViewHolder extends RecyclerView.ViewHolder { private class SubSettingViewHolder extends RecyclerView.ViewHolder {
TextView textView; private final TextView textView;
View checkView; private final View checkView;
SubSettingsViewHolder(View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.exo_text);
checkView = itemView.findViewById(R.id.exo_check);
itemView.setOnClickListener(
v -> {
int position = SubSettingsViewHolder.this.getAdapterPosition();
if (position == RecyclerView.NO_POSITION) {
return;
}
if (selectedMainSettingsPosition == SETTINGS_PLAYBACK_SPEED_POSITION) { public SubSettingViewHolder(View itemView) {
if (position != selectedPlaybackSpeedIndex) { super(itemView);
float speed = playbackSpeedMultBy100List.get(position) / 100.0f; textView = itemView.findViewById(R.id.exo_text);
setPlaybackSpeed(speed); checkView = itemView.findViewById(R.id.exo_check);
} itemView.setOnClickListener(
} v -> onSubSettingViewClicked(SubSettingViewHolder.this.getAdapterPosition()));
settingsWindow.dismiss();
});
}
} }
} }
...@@ -2057,7 +2050,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -2057,7 +2050,7 @@ public class StyledPlayerControlView extends FrameLayout {
} }
checkNotNull(trackSelector).setParameters(parametersBuilder); checkNotNull(trackSelector).setParameters(parametersBuilder);
} }
settingsAdapter.updateSubTexts( settingsAdapter.setSubTextAtPosition(
SETTINGS_AUDIO_TRACK_SELECTION_POSITION, SETTINGS_AUDIO_TRACK_SELECTION_POSITION,
getResources().getString(R.string.exo_track_selection_auto)); getResources().getString(R.string.exo_track_selection_auto));
settingsWindow.dismiss(); settingsWindow.dismiss();
...@@ -2066,7 +2059,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -2066,7 +2059,7 @@ public class StyledPlayerControlView extends FrameLayout {
@Override @Override
public void onTrackSelection(String subtext) { public void onTrackSelection(String subtext) {
settingsAdapter.updateSubTexts(SETTINGS_AUDIO_TRACK_SELECTION_POSITION, subtext); settingsAdapter.setSubTextAtPosition(SETTINGS_AUDIO_TRACK_SELECTION_POSITION, subtext);
} }
@Override @Override
...@@ -2086,20 +2079,20 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -2086,20 +2079,20 @@ public class StyledPlayerControlView extends FrameLayout {
} }
} }
if (trackInfos.isEmpty()) { if (trackInfos.isEmpty()) {
settingsAdapter.updateSubTexts( settingsAdapter.setSubTextAtPosition(
SETTINGS_AUDIO_TRACK_SELECTION_POSITION, SETTINGS_AUDIO_TRACK_SELECTION_POSITION,
getResources().getString(R.string.exo_track_selection_none)); getResources().getString(R.string.exo_track_selection_none));
// TODO(insun) : Make the audio item in main settings (settingsAdapater) // TODO(insun) : Make the audio item in main settings (settingsAdapater)
// to be non-clickable. // to be non-clickable.
} else if (!hasSelectionOverride) { } else if (!hasSelectionOverride) {
settingsAdapter.updateSubTexts( settingsAdapter.setSubTextAtPosition(
SETTINGS_AUDIO_TRACK_SELECTION_POSITION, SETTINGS_AUDIO_TRACK_SELECTION_POSITION,
getResources().getString(R.string.exo_track_selection_auto)); getResources().getString(R.string.exo_track_selection_auto));
} else { } else {
for (int i = 0; i < trackInfos.size(); i++) { for (int i = 0; i < trackInfos.size(); i++) {
TrackInfo track = trackInfos.get(i); TrackInfo track = trackInfos.get(i);
if (track.selected) { if (track.selected) {
settingsAdapter.updateSubTexts( settingsAdapter.setSubTextAtPosition(
SETTINGS_AUDIO_TRACK_SELECTION_POSITION, track.trackName); SETTINGS_AUDIO_TRACK_SELECTION_POSITION, track.trackName);
break; break;
} }
......
...@@ -34,14 +34,4 @@ ...@@ -34,14 +34,4 @@
<item>1.5x</item> <item>1.5x</item>
<item>2x</item> <item>2x</item>
</string-array> </string-array>
<string-array translatable="false" name="exo_settings_main_texts">
<item>@string/exo_controls_playback_speed</item>
<item>@string/exo_controls_audio_track</item>
</string-array>
<array name="exo_settings_icon_ids">
<item>@drawable/exo_styled_controls_speed</item>
<item>@drawable/exo_styled_controls_audiotrack</item>
</array>
</resources> </resources>
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
<string name="exo_controls_shuffle_off_description">Shuffle off</string> <string name="exo_controls_shuffle_off_description">Shuffle off</string>
<!-- Description for a media control button that toggles whether a video playback is in VR mode. [CHAR LIMIT=30] --> <!-- Description for a media control button that toggles whether a video playback is in VR mode. [CHAR LIMIT=30] -->
<string name="exo_controls_vr_description">VR mode</string> <string name="exo_controls_vr_description">VR mode</string>
<!-- Description for a button that downloads a piece of media content onto the device. [CHAR LIMIT=20] --> <!-- Description for a button that downloads a piece of media content onto the device. [CHAR LIMIT=20] -->
<string name="exo_download_description">Download</string> <string name="exo_download_description">Download</string>
<!-- Default name for a notification channel corresponding to media downloads. [CHAR LIMIT=40] --> <!-- Default name for a notification channel corresponding to media downloads. [CHAR LIMIT=40] -->
...@@ -56,6 +57,7 @@ ...@@ -56,6 +57,7 @@
<string name="exo_download_failed">Download failed</string> <string name="exo_download_failed">Download failed</string>
<!-- Shown in a notification or UI component to indicate downloads are being removed from the device. [CHAR LIMIT=40] --> <!-- Shown in a notification or UI component to indicate downloads are being removed from the device. [CHAR LIMIT=40] -->
<string name="exo_download_removing">Removing downloads</string> <string name="exo_download_removing">Removing downloads</string>
<!-- The title of a track selection view for video tracks. [CHAR LIMIT=20] --> <!-- The title of a track selection view for video tracks. [CHAR LIMIT=20] -->
<string name="exo_track_selection_title_video">Video</string> <string name="exo_track_selection_title_video">Video</string>
<!-- The title of a track selection view for audio tracks. [CHAR LIMIT=20] --> <!-- The title of a track selection view for audio tracks. [CHAR LIMIT=20] -->
...@@ -90,13 +92,10 @@ ...@@ -90,13 +92,10 @@
<string name="exo_track_role_closed_captions">CC</string> <string name="exo_track_role_closed_captions">CC</string>
<!-- Describes the bitrate of a media track in Megabits (https://en.wikipedia.org/wiki/Megabit) per second. [CHAR LIMIT=20] --> <!-- Describes the bitrate of a media track in Megabits (https://en.wikipedia.org/wiki/Megabit) per second. [CHAR LIMIT=20] -->
<string name="exo_track_bitrate"><xliff:g id="bitrate" example="5.2">%1$.2f</xliff:g> Mbps</string> <string name="exo_track_bitrate"><xliff:g id="bitrate" example="5.2">%1$.2f</xliff:g> Mbps</string>
<!-- Defines a way of appending an item to a list of items. For example appending "banana" to "apple, pear" to get "apple, pear, banana". Note: the command separator will appear between all consecutive list items, so do not use an equivalent of 'and'. [CHAR LIMIT=40] --> <!-- Defines a way of appending an item to a list of items. For example appending "banana" to "apple, pear" to get "apple, pear, banana". Note: the command separator will appear between all consecutive list items, so do not use an equivalent of 'and'. [CHAR LIMIT=40] -->
<string name="exo_item_list"><xliff:g id="list" example="apple, pear">%1$s</xliff:g>, <xliff:g id="item" example="banana">%2$s</xliff:g></string> <string name="exo_item_list"><xliff:g id="list" example="apple, pear">%1$s</xliff:g>, <xliff:g id="item" example="banana">%2$s</xliff:g></string>
<!-- The title of audio track selection. It is shown with the currently selected audio track's
information (such as language). If a user clicks it, the list of possible audio tracks
will be shown. [CHAR_LIMIT=20] -->
<string name="exo_controls_audio_track">Audio track</string>
<!-- The title of playback speed selection. It is shown with the current playback speed. <!-- The title of playback speed selection. It is shown with the current playback speed.
If a user clicks it, the list of possible playback speeds will be shown. If a user clicks it, the list of possible playback speeds will be shown.
[CHAR_LIMIT=32] --> [CHAR_LIMIT=32] -->
...@@ -104,9 +103,8 @@ ...@@ -104,9 +103,8 @@
<!-- It implies that the playback speed is normal (1.0x). [CHAR_LIMIT=16] --> <!-- It implies that the playback speed is normal (1.0x). [CHAR_LIMIT=16] -->
<string name="exo_controls_playback_speed_normal">Normal</string> <string name="exo_controls_playback_speed_normal">Normal</string>
<!-- Text for displaying custom playback speed. [CHAR_LIMIT=16] --> <!-- Text for displaying custom playback speed. [CHAR_LIMIT=16] -->
<string translatable="false" name="exo_controls_custom_playback_speed"> <string translatable="false" name="exo_controls_custom_playback_speed"><xliff:g id="playback_speed" example="1.05">%1$.2f</xliff:g>x</string>
<xliff:g id="playback_speed" example="1.05">%1$.2f</xliff:g>x
</string>
<!-- Placeholder text for displaying time. Used to calculate which size layout to use. --> <!-- Placeholder text for displaying time. Used to calculate which size layout to use. -->
<string translatable="false" name="exo_controls_time_placeholder">00:00:00</string> <string translatable="false" name="exo_controls_time_placeholder">00:00:00</string>
<!-- Content description of the left arrow button to navigate a list of buttons. <!-- Content description of the left arrow button to navigate a list of buttons.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment