Skip to content

Commit

Permalink
Fix subtitle selection on Now Playing screen
Browse files Browse the repository at this point in the history
  • Loading branch information
SyncedSynapse committed Mar 15, 2015
1 parent ef63e38 commit 776f6b6
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/src/main/java/org/xbmc/kore/ui/NowPlayingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ public void onOverflowClicked(View v) {
popup.show();
}


// Number of explicitly added options for audio and subtitles (to subtract from the
// number of audiostreams and subtitles returned by Kodi)
static final int ADDED_AUDIO_OPTIONS = 1;
static final int ADDED_SUBTITLE_OPTIONS = 3;

/**
* Overflow menu
*/
Expand All @@ -376,20 +382,19 @@ public boolean onMenuItemClick(MenuItem item) {
int selectedItem = -1;
switch (item.getItemId()) {
case R.id.audiostreams:
final int MIN_AUDIO_OPTIONS = 1;
// Setup audiostream select dialog
String[] audiostreams = new String[(availableAudioStreams != null) ?
availableAudioStreams.size() + MIN_AUDIO_OPTIONS : MIN_AUDIO_OPTIONS];
availableAudioStreams.size() + ADDED_AUDIO_OPTIONS : ADDED_AUDIO_OPTIONS];

audiostreams[0] = getString(R.string.audio_sync);

if (availableAudioStreams != null) {
for (int i = 0; i < availableAudioStreams.size(); i++) {
PlayerType.AudioStream current = availableAudioStreams.get(i);
audiostreams[i + MIN_AUDIO_OPTIONS] = TextUtils.isEmpty(current.language) ?
audiostreams[i + ADDED_AUDIO_OPTIONS] = TextUtils.isEmpty(current.language) ?
current.name : current.language + " | " + current.name;
if (current.index == currentAudiostreamIndex) {
selectedItem = i + MIN_AUDIO_OPTIONS;
selectedItem = i + ADDED_AUDIO_OPTIONS;
}
}

Expand All @@ -400,9 +405,8 @@ public boolean onMenuItemClick(MenuItem item) {
return true;
case R.id.subtitles:
// Setup subtitles select dialog
final int MIN_SUBTITLE_OPTIONS = 3;
String[] subtitles = new String[(availableSubtitles != null) ?
availableSubtitles.size() + MIN_SUBTITLE_OPTIONS : MIN_SUBTITLE_OPTIONS];
availableSubtitles.size() + ADDED_SUBTITLE_OPTIONS : ADDED_SUBTITLE_OPTIONS];

subtitles[0] = getString(R.string.download_subtitle);
subtitles[1] = getString(R.string.subtitle_sync);
Expand All @@ -411,10 +415,10 @@ public boolean onMenuItemClick(MenuItem item) {
if (availableSubtitles != null) {
for (int i = 0; i < availableSubtitles.size(); i++) {
PlayerType.Subtitle current = availableSubtitles.get(i);
subtitles[i + MIN_SUBTITLE_OPTIONS] = TextUtils.isEmpty(current.language) ?
subtitles[i + ADDED_SUBTITLE_OPTIONS] = TextUtils.isEmpty(current.language) ?
current.name : current.language + " | " + current.name;
if (current.index == currentSubtitleIndex) {
selectedItem = i + MIN_SUBTITLE_OPTIONS;
selectedItem = i + ADDED_SUBTITLE_OPTIONS;
}
}
}
Expand Down Expand Up @@ -453,7 +457,7 @@ public void onError(int errorCode, String description) { }
}, callbackHandler);
break;
default:
Player.SetAudioStream setAudioStream = new Player.SetAudioStream(currentActivePlayerId, which - 1);
Player.SetAudioStream setAudioStream = new Player.SetAudioStream(currentActivePlayerId, which - ADDED_AUDIO_OPTIONS);
setAudioStream.execute(hostManager.getConnection(), defaultStringActionCallback, callbackHandler);
break;
}
Expand Down Expand Up @@ -506,7 +510,7 @@ public void onError(int errorCode, String description) { }
setSubtitle.execute(hostManager.getConnection(), defaultStringActionCallback, callbackHandler);
break;
default:
setSubtitle = new Player.SetSubtitle(currentActivePlayerId, which - 2, true);
setSubtitle = new Player.SetSubtitle(currentActivePlayerId, which - ADDED_SUBTITLE_OPTIONS, true);
setSubtitle.execute(hostManager.getConnection(), defaultStringActionCallback, callbackHandler);
break;
}
Expand Down

0 comments on commit 776f6b6

Please sign in to comment.