2015-01-14 12:12:47 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Synced Synapse. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2016-12-20 21:47:24 +01:00
|
|
|
package org.xbmc.kore.ui.sections.remote;
|
2015-01-14 12:12:47 +01:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.text.TextUtils;
|
2017-10-19 10:05:45 +02:00
|
|
|
import android.text.util.Linkify;
|
2015-01-14 12:12:47 +01:00
|
|
|
import android.util.DisplayMetrics;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.widget.GridLayout;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.PopupMenu;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.ScrollView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2015-03-09 22:35:18 +01:00
|
|
|
import org.xbmc.kore.R;
|
|
|
|
import org.xbmc.kore.host.HostConnectionObserver;
|
|
|
|
import org.xbmc.kore.host.HostInfo;
|
|
|
|
import org.xbmc.kore.host.HostManager;
|
|
|
|
import org.xbmc.kore.jsonrpc.ApiCallback;
|
|
|
|
import org.xbmc.kore.jsonrpc.ApiMethod;
|
|
|
|
import org.xbmc.kore.jsonrpc.HostConnection;
|
|
|
|
import org.xbmc.kore.jsonrpc.method.Addons;
|
|
|
|
import org.xbmc.kore.jsonrpc.method.Application;
|
|
|
|
import org.xbmc.kore.jsonrpc.method.GUI;
|
|
|
|
import org.xbmc.kore.jsonrpc.method.Input;
|
|
|
|
import org.xbmc.kore.jsonrpc.method.Player;
|
|
|
|
import org.xbmc.kore.jsonrpc.type.GlobalType;
|
|
|
|
import org.xbmc.kore.jsonrpc.type.ListType;
|
|
|
|
import org.xbmc.kore.jsonrpc.type.PlayerType;
|
2015-07-29 19:37:28 +02:00
|
|
|
import org.xbmc.kore.jsonrpc.type.VideoType;
|
2016-12-20 21:47:24 +01:00
|
|
|
import org.xbmc.kore.ui.generic.GenericSelectDialog;
|
|
|
|
import org.xbmc.kore.ui.sections.video.AllCastActivity;
|
2017-06-25 11:19:41 +02:00
|
|
|
import org.xbmc.kore.ui.widgets.HighlightButton;
|
2017-06-20 20:05:27 +02:00
|
|
|
import org.xbmc.kore.ui.widgets.MediaProgressIndicator;
|
2017-06-23 12:50:17 +02:00
|
|
|
import org.xbmc.kore.ui.widgets.RepeatModeButton;
|
2017-06-25 11:19:41 +02:00
|
|
|
import org.xbmc.kore.ui.widgets.VolumeLevelIndicator;
|
2015-03-09 22:35:18 +01:00
|
|
|
import org.xbmc.kore.utils.LogUtils;
|
|
|
|
import org.xbmc.kore.utils.UIUtils;
|
|
|
|
import org.xbmc.kore.utils.Utils;
|
2015-01-14 12:12:47 +01:00
|
|
|
|
2015-07-29 19:37:28 +02:00
|
|
|
import java.util.ArrayList;
|
2015-01-14 12:12:47 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
import butterknife.InjectView;
|
|
|
|
import butterknife.OnClick;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Now playing view
|
|
|
|
*/
|
|
|
|
public class NowPlayingFragment extends Fragment
|
|
|
|
implements HostConnectionObserver.PlayerEventsObserver,
|
2016-11-30 13:20:21 +01:00
|
|
|
HostConnectionObserver.ApplicationEventsObserver,
|
2017-06-20 20:05:27 +02:00
|
|
|
GenericSelectDialog.GenericSelectDialogListener,
|
|
|
|
MediaProgressIndicator.OnProgressChangeListener {
|
2015-01-14 12:12:47 +01:00
|
|
|
private static final String TAG = LogUtils.makeLogTag(NowPlayingFragment.class);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for this fragment to communicate with the enclosing activity
|
|
|
|
*/
|
|
|
|
public interface NowPlayingListener {
|
|
|
|
public void SwitchToRemotePanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constants for the general select dialog
|
|
|
|
*/
|
|
|
|
private final static int SELECT_AUDIOSTREAM = 0;
|
|
|
|
private final static int SELECT_SUBTITLES = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Host manager from which to get info about the current XBMC
|
|
|
|
*/
|
|
|
|
private HostManager hostManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Activity to communicate potential actions that change what's playing
|
|
|
|
*/
|
|
|
|
private HostConnectionObserver hostConnectionObserver;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listener for events on this fragment
|
|
|
|
*/
|
|
|
|
private NowPlayingListener nowPlayingListener;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler on which to post RPC callbacks
|
|
|
|
*/
|
|
|
|
private Handler callbackHandler = new Handler();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current active player id
|
|
|
|
*/
|
|
|
|
private int currentActivePlayerId = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of available subtitles and audiostremas
|
|
|
|
*/
|
|
|
|
private List<PlayerType.Subtitle> availableSubtitles;
|
|
|
|
private List<PlayerType.AudioStream> availableAudioStreams;
|
|
|
|
private int currentSubtitleIndex = -1;
|
|
|
|
private int currentAudiostreamIndex = -1;
|
|
|
|
|
2017-07-13 20:10:49 +02:00
|
|
|
private ApiCallback<Integer> defaultIntActionCallback = ApiMethod.getDefaultActionCallback();
|
|
|
|
private ApiCallback<Boolean> defaultBooleanActionCallback = ApiMethod.getDefaultActionCallback();
|
|
|
|
|
2015-01-14 12:12:47 +01:00
|
|
|
/**
|
|
|
|
* Injectable views
|
|
|
|
*/
|
|
|
|
@InjectView(R.id.play) ImageButton playButton;
|
|
|
|
|
2017-06-25 11:19:41 +02:00
|
|
|
@InjectView(R.id.volume_mute) HighlightButton volumeMuteButton;
|
|
|
|
@InjectView(R.id.shuffle) HighlightButton shuffleButton;
|
2017-07-13 20:10:49 +02:00
|
|
|
@InjectView(R.id.repeat) RepeatModeButton repeatButton;
|
2015-01-14 12:12:47 +01:00
|
|
|
@InjectView(R.id.overflow) ImageButton overflowButton;
|
|
|
|
|
|
|
|
@InjectView(R.id.info_panel) RelativeLayout infoPanel;
|
|
|
|
@InjectView(R.id.media_panel) ScrollView mediaPanel;
|
|
|
|
|
|
|
|
@InjectView(R.id.info_title) TextView infoTitle;
|
|
|
|
@InjectView(R.id.info_message) TextView infoMessage;
|
|
|
|
|
|
|
|
@InjectView(R.id.art) ImageView mediaArt;
|
|
|
|
@InjectView(R.id.poster) ImageView mediaPoster;
|
|
|
|
|
|
|
|
@InjectView(R.id.media_title) TextView mediaTitle;
|
|
|
|
@InjectView(R.id.media_undertitle) TextView mediaUndertitle;
|
2017-06-20 20:05:27 +02:00
|
|
|
@InjectView(R.id.progress_info) MediaProgressIndicator mediaProgressIndicator;
|
2015-01-14 12:12:47 +01:00
|
|
|
|
2017-06-22 19:37:00 +02:00
|
|
|
@InjectView(R.id.volume_level_indicator) VolumeLevelIndicator volumeLevelIndicator;
|
2016-11-30 13:20:21 +01:00
|
|
|
|
2015-01-14 12:12:47 +01:00
|
|
|
@InjectView(R.id.rating) TextView mediaRating;
|
|
|
|
@InjectView(R.id.max_rating) TextView mediaMaxRating;
|
|
|
|
@InjectView(R.id.year) TextView mediaYear;
|
|
|
|
@InjectView(R.id.genres) TextView mediaGenreSeason;
|
|
|
|
@InjectView(R.id.rating_votes) TextView mediaRatingVotes;
|
|
|
|
|
|
|
|
@InjectView(R.id.media_description) TextView mediaDescription;
|
|
|
|
@InjectView(R.id.cast_list) GridLayout videoCastList;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
|
|
|
// Try to cast the enclosing activity to the listener interface
|
|
|
|
try {
|
|
|
|
nowPlayingListener = (NowPlayingListener)activity;
|
|
|
|
} catch (ClassCastException e) {
|
|
|
|
nowPlayingListener = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
hostManager = HostManager.getInstance(getActivity());
|
|
|
|
hostConnectionObserver = hostManager.getHostConnectionObserver();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_now_playing, container, false);
|
|
|
|
ButterKnife.inject(this, root);
|
|
|
|
|
2017-07-13 20:10:49 +02:00
|
|
|
volumeLevelIndicator.setOnVolumeChangeListener(new VolumeLevelIndicator.OnVolumeChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onVolumeChanged(int volume) {
|
|
|
|
new Application.SetVolume(volume)
|
2017-09-28 20:52:12 +02:00
|
|
|
.execute(hostManager.getConnection(), defaultIntActionCallback, callbackHandler);
|
2017-07-13 20:10:49 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mediaProgressIndicator.setOnProgressChangeListener(this);
|
|
|
|
|
2015-01-14 12:12:47 +01:00
|
|
|
// Setup dim the fanart when scroll changes
|
|
|
|
// Full dim on 4 * iconSize dp
|
|
|
|
Resources resources = getActivity().getResources();
|
|
|
|
final int pixelsToTransparent = 4 * resources.getDimensionPixelSize(R.dimen.default_icon_size);
|
|
|
|
mediaPanel.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollChanged() {
|
|
|
|
float y = mediaPanel.getScrollY();
|
|
|
|
float newAlpha = Math.min(1, Math.max(0, 1 - (y / pixelsToTransparent)));
|
|
|
|
mediaArt.setAlpha(newAlpha);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-22 19:37:00 +02:00
|
|
|
volumeLevelIndicator.setOnVolumeChangeListener(new VolumeLevelIndicator.OnVolumeChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onVolumeChanged(int volume) {
|
|
|
|
new Application.SetVolume(volume).execute(hostManager.getConnection(),
|
2017-09-28 20:52:12 +02:00
|
|
|
defaultIntActionCallback, callbackHandler);
|
2017-06-22 19:37:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-14 12:12:47 +01:00
|
|
|
// // Pad main content view to overlap with bottom system bar
|
|
|
|
// UIUtils.setPaddingForSystemBars(getActivity(), mediaPanel, false, false, true);
|
|
|
|
// mediaPanel.setClipToPadding(false);
|
|
|
|
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated (Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
setHasOptionsMenu(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2015-02-15 20:11:32 +01:00
|
|
|
hostConnectionObserver.registerPlayerObserver(this, true);
|
2016-11-30 13:20:21 +01:00
|
|
|
hostConnectionObserver.registerApplicationObserver(this, true);
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
stopNowPlayingInfo();
|
|
|
|
hostConnectionObserver.unregisterPlayerObserver(this);
|
2016-11-30 13:20:21 +01:00
|
|
|
hostConnectionObserver.unregisterApplicationObserver(this);
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default callback for methods that don't return anything
|
|
|
|
*/
|
|
|
|
private ApiCallback<String> defaultStringActionCallback = ApiMethod.getDefaultActionCallback();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for methods that change the play speed
|
|
|
|
*/
|
|
|
|
private ApiCallback<Integer> defaultPlaySpeedChangedCallback = new ApiCallback<Integer>() {
|
|
|
|
@Override
|
2015-03-16 19:33:40 +01:00
|
|
|
public void onSuccess(Integer result) {
|
2015-01-22 23:19:28 +01:00
|
|
|
if (!isAdded()) return;
|
2017-07-13 20:10:49 +02:00
|
|
|
UIUtils.setPlayPauseButtonIcon(getActivity(), playButton, result == 1);
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int errorCode, String description) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callbacks for bottom button bar
|
|
|
|
*/
|
|
|
|
@OnClick(R.id.play)
|
|
|
|
public void onPlayClicked(View v) {
|
|
|
|
Player.PlayPause action = new Player.PlayPause(currentActivePlayerId);
|
|
|
|
action.execute(hostManager.getConnection(), defaultPlaySpeedChangedCallback, callbackHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnClick(R.id.stop)
|
|
|
|
public void onStopClicked(View v) {
|
|
|
|
Player.Stop action = new Player.Stop(currentActivePlayerId);
|
|
|
|
action.execute(hostManager.getConnection(), defaultStringActionCallback, callbackHandler);
|
2017-07-13 20:10:49 +02:00
|
|
|
UIUtils.setPlayPauseButtonIcon(getActivity(), playButton, false);
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@OnClick(R.id.fast_forward)
|
|
|
|
public void onFastForwardClicked(View v) {
|
|
|
|
Player.SetSpeed action = new Player.SetSpeed(currentActivePlayerId, GlobalType.IncrementDecrement.INCREMENT);
|
|
|
|
action.execute(hostManager.getConnection(), defaultPlaySpeedChangedCallback, callbackHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnClick(R.id.rewind)
|
|
|
|
public void onRewindClicked(View v) {
|
|
|
|
Player.SetSpeed action = new Player.SetSpeed(currentActivePlayerId, GlobalType.IncrementDecrement.DECREMENT);
|
|
|
|
action.execute(hostManager.getConnection(), defaultPlaySpeedChangedCallback, callbackHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnClick(R.id.previous)
|
|
|
|
public void onPreviousClicked(View v) {
|
|
|
|
Player.GoTo action = new Player.GoTo(currentActivePlayerId, Player.GoTo.PREVIOUS);
|
|
|
|
action.execute(hostManager.getConnection(), defaultStringActionCallback, callbackHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnClick(R.id.next)
|
|
|
|
public void onNextClicked(View v) {
|
|
|
|
Player.GoTo action = new Player.GoTo(currentActivePlayerId, Player.GoTo.NEXT);
|
|
|
|
action.execute(hostManager.getConnection(), defaultStringActionCallback, callbackHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnClick(R.id.volume_mute)
|
|
|
|
public void onVolumeMuteClicked(View v) {
|
|
|
|
Application.SetMute action = new Application.SetMute();
|
2017-09-28 20:52:12 +02:00
|
|
|
action.execute(hostManager.getConnection(), defaultBooleanActionCallback, callbackHandler);
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@OnClick(R.id.shuffle)
|
|
|
|
public void onShuffleClicked(View v) {
|
|
|
|
Player.SetShuffle action = new Player.SetShuffle(currentActivePlayerId);
|
|
|
|
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
|
|
|
@Override
|
2015-03-16 19:33:40 +01:00
|
|
|
public void onSuccess(String result) {
|
2015-01-22 23:19:28 +01:00
|
|
|
if (!isAdded()) return;
|
2015-01-14 12:12:47 +01:00
|
|
|
// Force a refresh
|
|
|
|
hostConnectionObserver.forceRefreshResults();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int errorCode, String description) { }
|
|
|
|
}, callbackHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnClick(R.id.repeat)
|
|
|
|
public void onRepeatClicked(View v) {
|
|
|
|
Player.SetRepeat action = new Player.SetRepeat(currentActivePlayerId, PlayerType.Repeat.CYCLE);
|
|
|
|
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
|
|
|
@Override
|
2015-03-16 19:33:40 +01:00
|
|
|
public void onSuccess(String result) {
|
2015-01-22 23:19:28 +01:00
|
|
|
if (!isAdded()) return;
|
2015-01-14 12:12:47 +01:00
|
|
|
hostConnectionObserver.forceRefreshResults();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int errorCode, String description) { }
|
|
|
|
}, callbackHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnClick(R.id.overflow)
|
|
|
|
public void onOverflowClicked(View v) {
|
|
|
|
PopupMenu popup = new PopupMenu(getActivity(), v);
|
|
|
|
popup.inflate(R.menu.video_overflow);
|
|
|
|
popup.setOnMenuItemClickListener(overflowMenuClickListener);
|
|
|
|
popup.show();
|
|
|
|
}
|
|
|
|
|
2015-03-15 20:52:30 +01:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2015-01-14 12:12:47 +01:00
|
|
|
/**
|
|
|
|
* Overflow menu
|
|
|
|
*/
|
|
|
|
private PopupMenu.OnMenuItemClickListener overflowMenuClickListener = new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
2015-02-19 00:21:59 +01:00
|
|
|
int selectedItem = -1;
|
2015-01-14 12:12:47 +01:00
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.audiostreams:
|
|
|
|
// Setup audiostream select dialog
|
2015-02-19 00:21:59 +01:00
|
|
|
String[] audiostreams = new String[(availableAudioStreams != null) ?
|
2016-11-30 13:20:21 +01:00
|
|
|
availableAudioStreams.size() + ADDED_AUDIO_OPTIONS : ADDED_AUDIO_OPTIONS];
|
2015-02-19 00:21:59 +01:00
|
|
|
|
|
|
|
audiostreams[0] = getString(R.string.audio_sync);
|
2015-01-14 12:12:47 +01:00
|
|
|
|
2015-02-19 00:21:59 +01:00
|
|
|
if (availableAudioStreams != null) {
|
2015-01-14 12:12:47 +01:00
|
|
|
for (int i = 0; i < availableAudioStreams.size(); i++) {
|
|
|
|
PlayerType.AudioStream current = availableAudioStreams.get(i);
|
2015-03-15 20:52:30 +01:00
|
|
|
audiostreams[i + ADDED_AUDIO_OPTIONS] = TextUtils.isEmpty(current.language) ?
|
2016-11-30 13:20:21 +01:00
|
|
|
current.name : current.language + " | " + current.name;
|
2015-01-14 12:12:47 +01:00
|
|
|
if (current.index == currentAudiostreamIndex) {
|
2015-03-15 20:52:30 +01:00
|
|
|
selectedItem = i + ADDED_AUDIO_OPTIONS;
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GenericSelectDialog dialog = GenericSelectDialog.newInstance(NowPlayingFragment.this,
|
2016-11-30 13:20:21 +01:00
|
|
|
SELECT_AUDIOSTREAM, getString(R.string.audiostreams), audiostreams, selectedItem);
|
2015-01-14 12:12:47 +01:00
|
|
|
dialog.show(NowPlayingFragment.this.getFragmentManager(), null);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.subtitles:
|
|
|
|
// Setup subtitles select dialog
|
2015-02-19 00:21:59 +01:00
|
|
|
String[] subtitles = new String[(availableSubtitles != null) ?
|
2016-11-30 13:20:21 +01:00
|
|
|
availableSubtitles.size() + ADDED_SUBTITLE_OPTIONS : ADDED_SUBTITLE_OPTIONS];
|
2015-01-14 12:12:47 +01:00
|
|
|
|
|
|
|
subtitles[0] = getString(R.string.download_subtitle);
|
2015-02-19 00:21:59 +01:00
|
|
|
subtitles[1] = getString(R.string.subtitle_sync);
|
|
|
|
subtitles[2] = getString(R.string.none);
|
2015-01-14 12:12:47 +01:00
|
|
|
|
|
|
|
if (availableSubtitles != null) {
|
|
|
|
for (int i = 0; i < availableSubtitles.size(); i++) {
|
|
|
|
PlayerType.Subtitle current = availableSubtitles.get(i);
|
2015-03-15 20:52:30 +01:00
|
|
|
subtitles[i + ADDED_SUBTITLE_OPTIONS] = TextUtils.isEmpty(current.language) ?
|
2016-11-30 13:20:21 +01:00
|
|
|
current.name : current.language + " | " + current.name;
|
2015-01-14 12:12:47 +01:00
|
|
|
if (current.index == currentSubtitleIndex) {
|
2015-03-15 20:52:30 +01:00
|
|
|
selectedItem = i + ADDED_SUBTITLE_OPTIONS;
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GenericSelectDialog dialog = GenericSelectDialog.newInstance(NowPlayingFragment.this,
|
2016-11-30 13:20:21 +01:00
|
|
|
SELECT_SUBTITLES, getString(R.string.subtitles), subtitles, selectedItem);
|
2015-01-14 12:12:47 +01:00
|
|
|
dialog.show(NowPlayingFragment.this.getFragmentManager(), null);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic dialog select listener
|
|
|
|
* @param token
|
|
|
|
* @param which
|
|
|
|
*/
|
|
|
|
public void onDialogSelect(int token, int which) {
|
|
|
|
switch (token) {
|
|
|
|
case SELECT_AUDIOSTREAM:
|
2015-02-19 00:21:59 +01:00
|
|
|
// 0 is to sync audio, other is for a specific audiostream
|
|
|
|
switch (which) {
|
|
|
|
case 0:
|
|
|
|
Input.ExecuteAction syncAudioAction = new Input.ExecuteAction(Input.ExecuteAction.AUDIODELAY);
|
|
|
|
syncAudioAction.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
|
|
|
@Override
|
2015-03-16 19:33:40 +01:00
|
|
|
public void onSuccess(String result) {
|
2015-02-19 00:21:59 +01:00
|
|
|
if (!isAdded()) return;
|
|
|
|
// Notify enclosing activity to switch panels
|
|
|
|
nowPlayingListener.SwitchToRemotePanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int errorCode, String description) { }
|
|
|
|
}, callbackHandler);
|
|
|
|
break;
|
|
|
|
default:
|
2015-03-15 20:52:30 +01:00
|
|
|
Player.SetAudioStream setAudioStream = new Player.SetAudioStream(currentActivePlayerId, which - ADDED_AUDIO_OPTIONS);
|
2015-02-19 00:21:59 +01:00
|
|
|
setAudioStream.execute(hostManager.getConnection(), defaultStringActionCallback, callbackHandler);
|
|
|
|
break;
|
|
|
|
}
|
2015-01-14 12:12:47 +01:00
|
|
|
break;
|
|
|
|
case SELECT_SUBTITLES:
|
|
|
|
Player.SetSubtitle setSubtitle;
|
2015-02-19 00:21:59 +01:00
|
|
|
// 0 is to download subtitles, 1 is for sync, 2 is for none, other is for a specific subtitle index
|
2015-01-14 12:12:47 +01:00
|
|
|
switch (which) {
|
|
|
|
case 0:
|
|
|
|
// Download subtitles. First check host version to see which method to call
|
2016-11-15 20:18:16 +01:00
|
|
|
HostInfo hostInfo = hostManager.getHostInfo();
|
|
|
|
if (hostInfo.getKodiVersionMajor() < 13) {
|
|
|
|
showDownloadSubtitlesPreGotham();
|
|
|
|
} else {
|
|
|
|
showDownloadSubtitlesPostGotham();
|
|
|
|
}
|
2015-01-14 12:12:47 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2015-02-19 00:21:59 +01:00
|
|
|
Input.ExecuteAction syncSubtitleAction = new Input.ExecuteAction(Input.ExecuteAction.SUBTITLEDELAY);
|
|
|
|
syncSubtitleAction.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
|
|
|
@Override
|
2015-03-16 19:33:40 +01:00
|
|
|
public void onSuccess(String result) {
|
2015-02-19 00:21:59 +01:00
|
|
|
if (!isAdded()) return;
|
|
|
|
// Notify enclosing activity to switch panels
|
|
|
|
nowPlayingListener.SwitchToRemotePanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int errorCode, String description) { }
|
|
|
|
}, callbackHandler);
|
|
|
|
break;
|
|
|
|
case 2:
|
2015-01-14 12:12:47 +01:00
|
|
|
setSubtitle = new Player.SetSubtitle(currentActivePlayerId, Player.SetSubtitle.OFF, true);
|
|
|
|
setSubtitle.execute(hostManager.getConnection(), defaultStringActionCallback, callbackHandler);
|
|
|
|
break;
|
|
|
|
default:
|
2015-03-15 20:52:30 +01:00
|
|
|
setSubtitle = new Player.SetSubtitle(currentActivePlayerId, which - ADDED_SUBTITLE_OPTIONS, true);
|
2015-01-14 12:12:47 +01:00
|
|
|
setSubtitle.execute(hostManager.getConnection(), defaultStringActionCallback, callbackHandler);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showDownloadSubtitlesPreGotham() {
|
|
|
|
// Pre-Gotham
|
|
|
|
Addons.ExecuteAddon action = new Addons.ExecuteAddon(Addons.ExecuteAddon.ADDON_SUBTITLES);
|
|
|
|
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
|
|
|
@Override
|
2015-03-16 19:33:40 +01:00
|
|
|
public void onSuccess(String result) {
|
2015-01-22 23:19:28 +01:00
|
|
|
if (!isAdded()) return;
|
2015-01-14 12:12:47 +01:00
|
|
|
// Notify enclosing activity to switch panels
|
|
|
|
nowPlayingListener.SwitchToRemotePanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int errorCode, String description) {
|
2015-01-22 23:19:28 +01:00
|
|
|
if (!isAdded()) return;
|
2015-01-14 12:12:47 +01:00
|
|
|
Toast.makeText(getActivity(),
|
2016-11-30 13:20:21 +01:00
|
|
|
String.format(getString(R.string.error_executing_subtitles), description),
|
|
|
|
Toast.LENGTH_SHORT).show();
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
}, callbackHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showDownloadSubtitlesPostGotham() {
|
|
|
|
// Post-Gotham - HACK, HACK
|
|
|
|
// Apparently Gui.ActivateWindow with subtitlesearch blocks the TCP listener thread on XBMC
|
|
|
|
// While the subtitles windows is showing, i get no response to any call. See:
|
|
|
|
// http://forum.xbmc.org/showthread.php?tid=198156
|
|
|
|
// Forcing this call through HTTP works, as it doesn't block the TCP listener thread on XBMC
|
|
|
|
HostInfo currentHostInfo = hostManager.getHostInfo();
|
|
|
|
HostConnection httpHostConnection = new HostConnection(currentHostInfo);
|
|
|
|
httpHostConnection.setProtocol(HostConnection.PROTOCOL_HTTP);
|
|
|
|
|
|
|
|
GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.SUBTITLESEARCH);
|
|
|
|
|
|
|
|
LogUtils.LOGD(TAG, "Activating subtitles window.");
|
|
|
|
action.execute(httpHostConnection, new ApiCallback<String>() {
|
|
|
|
@Override
|
2015-03-16 19:33:40 +01:00
|
|
|
public void onSuccess(String result) {
|
2015-01-14 12:12:47 +01:00
|
|
|
LogUtils.LOGD(TAG, "Sucessfully activated subtitles window.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int errorCode, String description) {
|
|
|
|
LogUtils.LOGD(TAG, "Got an error activating subtitles window. Error: " + description);
|
|
|
|
}
|
|
|
|
}, callbackHandler);
|
|
|
|
// Notify enclosing activity to switch panels
|
|
|
|
nowPlayingListener.SwitchToRemotePanel();
|
|
|
|
}
|
|
|
|
|
2017-06-20 20:05:27 +02:00
|
|
|
@Override
|
2017-07-13 20:10:49 +02:00
|
|
|
public void playerOnPropertyChanged(org.xbmc.kore.jsonrpc.notification.Player.NotificationsData notificationsData) {
|
|
|
|
if (notificationsData.property.shuffled != null)
|
|
|
|
shuffleButton.setHighlight(notificationsData.property.shuffled);
|
2017-06-20 20:05:27 +02:00
|
|
|
|
2017-07-13 20:10:49 +02:00
|
|
|
if (notificationsData.property.repeatMode != null)
|
|
|
|
UIUtils.setRepeatButton(repeatButton, notificationsData.property.repeatMode);
|
2017-06-20 20:05:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-14 12:12:47 +01:00
|
|
|
/**
|
|
|
|
* HostConnectionObserver.PlayerEventsObserver interface callbacks
|
|
|
|
*/
|
|
|
|
public void playerOnPlay(PlayerType.GetActivePlayersReturnType getActivePlayerResult,
|
|
|
|
PlayerType.PropertyValue getPropertiesResult,
|
|
|
|
ListType.ItemsAll getItemResult) {
|
2017-07-13 20:10:49 +02:00
|
|
|
setNowPlayingInfo(getActivePlayerResult, getPropertiesResult, getItemResult);
|
2015-01-14 12:12:47 +01:00
|
|
|
currentActivePlayerId = getActivePlayerResult.playerid;
|
|
|
|
// Switch icon
|
2017-07-13 20:10:49 +02:00
|
|
|
UIUtils.setPlayPauseButtonIcon(getActivity(), playButton, getPropertiesResult.speed == 1);
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void playerOnPause(PlayerType.GetActivePlayersReturnType getActivePlayerResult,
|
|
|
|
PlayerType.PropertyValue getPropertiesResult,
|
|
|
|
ListType.ItemsAll getItemResult) {
|
2017-07-13 20:10:49 +02:00
|
|
|
setNowPlayingInfo(getActivePlayerResult, getPropertiesResult, getItemResult);
|
2015-01-14 12:12:47 +01:00
|
|
|
currentActivePlayerId = getActivePlayerResult.playerid;
|
|
|
|
// Switch icon
|
2017-07-13 20:10:49 +02:00
|
|
|
UIUtils.setPlayPauseButtonIcon(getActivity(), playButton, getPropertiesResult.speed == 1);
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void playerOnStop() {
|
|
|
|
HostInfo hostInfo = hostManager.getHostInfo();
|
|
|
|
|
|
|
|
stopNowPlayingInfo();
|
|
|
|
switchToPanel(R.id.info_panel);
|
|
|
|
infoTitle.setText(R.string.nothing_playing);
|
|
|
|
infoMessage.setText(String.format(getString(R.string.connected_to), hostInfo.getName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void playerOnConnectionError(int errorCode, String description) {
|
|
|
|
HostInfo hostInfo = hostManager.getHostInfo();
|
|
|
|
|
|
|
|
stopNowPlayingInfo();
|
|
|
|
switchToPanel(R.id.info_panel);
|
|
|
|
if (hostInfo != null) {
|
|
|
|
infoTitle.setText(R.string.connecting);
|
|
|
|
// TODO: check error code
|
|
|
|
infoMessage.setText(String.format(getString(R.string.connecting_to), hostInfo.getName(), hostInfo.getAddress()));
|
|
|
|
} else {
|
|
|
|
infoTitle.setText(R.string.no_xbmc_configured);
|
|
|
|
infoMessage.setText(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void playerNoResultsYet() {
|
|
|
|
// Initialize info panel
|
|
|
|
switchToPanel(R.id.info_panel);
|
|
|
|
HostInfo hostInfo = hostManager.getHostInfo();
|
|
|
|
if (hostInfo != null) {
|
|
|
|
infoTitle.setText(R.string.connecting);
|
|
|
|
} else {
|
|
|
|
infoTitle.setText(R.string.no_xbmc_configured);
|
|
|
|
}
|
|
|
|
infoMessage.setText(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void systemOnQuit() {
|
|
|
|
playerNoResultsYet();
|
|
|
|
}
|
|
|
|
|
2016-11-30 13:20:21 +01:00
|
|
|
@Override
|
|
|
|
public void applicationOnVolumeChanged(int volume, boolean muted) {
|
2017-06-22 19:37:00 +02:00
|
|
|
volumeLevelIndicator.setVolume(muted, volume);
|
2017-07-13 20:10:49 +02:00
|
|
|
volumeMuteButton.setHighlight(muted);
|
2016-11-30 13:20:21 +01:00
|
|
|
}
|
|
|
|
|
2015-01-14 12:12:47 +01:00
|
|
|
// Ignore this
|
|
|
|
public void inputOnInputRequested(String title, String type, String value) {}
|
2015-02-15 20:11:32 +01:00
|
|
|
public void observerOnStopObserving() {}
|
2015-01-14 12:12:47 +01:00
|
|
|
|
2017-07-13 20:10:49 +02:00
|
|
|
@Override
|
|
|
|
public void onProgressChanged(int progress) {
|
|
|
|
PlayerType.PositionTime positionTime = new PlayerType.PositionTime(progress);
|
|
|
|
Player.Seek seekAction = new Player.Seek(currentActivePlayerId, positionTime);
|
|
|
|
seekAction.execute(HostManager.getInstance(getContext()).getConnection(), new ApiCallback<PlayerType.SeekReturnType>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(PlayerType.SeekReturnType result) {
|
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int errorCode, String description) {
|
|
|
|
LogUtils.LOGD("MediaSeekBar", "Got an error calling Player.Seek. Error code: " + errorCode + ", description: " + description);
|
|
|
|
}
|
2017-09-28 20:52:12 +02:00
|
|
|
}, callbackHandler);
|
2017-07-13 20:10:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-14 12:12:47 +01:00
|
|
|
/**
|
|
|
|
* Sets whats playing information
|
2015-03-09 22:35:18 +01:00
|
|
|
* @param getItemResult Return from method {@link org.xbmc.kore.jsonrpc.method.Player.GetItem}
|
2015-01-14 12:12:47 +01:00
|
|
|
*/
|
2017-07-13 20:10:49 +02:00
|
|
|
private void setNowPlayingInfo(PlayerType.GetActivePlayersReturnType getActivePlayerResult,
|
|
|
|
PlayerType.PropertyValue getPropertiesResult,
|
2015-07-29 19:37:28 +02:00
|
|
|
final ListType.ItemsAll getItemResult) {
|
|
|
|
final String title, underTitle, art, poster, genreSeason, year,
|
2015-01-14 12:12:47 +01:00
|
|
|
descriptionPlot, votes, maxRating;
|
|
|
|
double rating;
|
|
|
|
|
2015-02-16 12:36:21 +01:00
|
|
|
switch (getItemResult.type) {
|
|
|
|
case ListType.ItemsAll.TYPE_MOVIE:
|
|
|
|
switchToPanel(R.id.media_panel);
|
|
|
|
|
|
|
|
title = getItemResult.title;
|
|
|
|
underTitle = getItemResult.tagline;
|
|
|
|
art = getItemResult.fanart;
|
|
|
|
poster = getItemResult.thumbnail;
|
|
|
|
|
|
|
|
genreSeason = Utils.listStringConcat(getItemResult.genre, ", ");
|
2015-04-15 23:13:01 +02:00
|
|
|
year = (getItemResult.year > 0)? String.format("%d", getItemResult.year) : null;
|
2015-02-16 12:36:21 +01:00
|
|
|
descriptionPlot = getItemResult.plot;
|
|
|
|
rating = getItemResult.rating;
|
|
|
|
maxRating = getString(R.string.max_rating_video);
|
|
|
|
votes = (TextUtils.isEmpty(getItemResult.votes)) ? "" : String.format(getString(R.string.votes), getItemResult.votes);
|
|
|
|
break;
|
|
|
|
case ListType.ItemsAll.TYPE_EPISODE:
|
|
|
|
switchToPanel(R.id.media_panel);
|
|
|
|
|
|
|
|
title = getItemResult.title;
|
|
|
|
underTitle = getItemResult.showtitle;
|
|
|
|
art = getItemResult.thumbnail;
|
|
|
|
poster = getItemResult.art.poster;
|
|
|
|
|
|
|
|
genreSeason = String.format(getString(R.string.season_episode), getItemResult.season, getItemResult.episode);
|
|
|
|
year = getItemResult.premiered;
|
|
|
|
descriptionPlot = getItemResult.plot;
|
|
|
|
rating = getItemResult.rating;
|
|
|
|
maxRating = getString(R.string.max_rating_video);
|
|
|
|
votes = (TextUtils.isEmpty(getItemResult.votes)) ? "" : String.format(getString(R.string.votes), getItemResult.votes);
|
|
|
|
break;
|
|
|
|
case ListType.ItemsAll.TYPE_SONG:
|
|
|
|
switchToPanel(R.id.media_panel);
|
|
|
|
|
|
|
|
title = getItemResult.title;
|
|
|
|
underTitle = getItemResult.displayartist + " | " + getItemResult.album;
|
|
|
|
art = getItemResult.fanart;
|
|
|
|
poster = getItemResult.thumbnail;
|
|
|
|
|
|
|
|
genreSeason = Utils.listStringConcat(getItemResult.genre, ", ");
|
2015-04-15 23:13:01 +02:00
|
|
|
year = (getItemResult.year > 0)? String.format("%d", getItemResult.year) : null;
|
2015-02-16 12:36:21 +01:00
|
|
|
descriptionPlot = getItemResult.description;
|
|
|
|
rating = getItemResult.rating;
|
|
|
|
maxRating = getString(R.string.max_rating_music);
|
|
|
|
votes = (TextUtils.isEmpty(getItemResult.votes)) ? "" : String.format(getString(R.string.votes), getItemResult.votes);
|
|
|
|
break;
|
|
|
|
case ListType.ItemsAll.TYPE_MUSIC_VIDEO:
|
|
|
|
switchToPanel(R.id.media_panel);
|
|
|
|
|
|
|
|
title = getItemResult.title;
|
|
|
|
underTitle = Utils.listStringConcat(getItemResult.artist, ", ")
|
2016-11-30 13:20:21 +01:00
|
|
|
+ " | " + getItemResult.album;
|
2015-02-16 12:36:21 +01:00
|
|
|
art = getItemResult.fanart;
|
|
|
|
poster = getItemResult.thumbnail;
|
|
|
|
|
|
|
|
genreSeason = Utils.listStringConcat(getItemResult.genre, ", ");
|
2015-04-15 23:13:01 +02:00
|
|
|
year = (getItemResult.year > 0)? String.format("%d", getItemResult.year) : null;
|
2015-02-16 12:36:21 +01:00
|
|
|
descriptionPlot = getItemResult.plot;
|
|
|
|
rating = 0;
|
|
|
|
maxRating = null;
|
|
|
|
votes = null;
|
|
|
|
break;
|
2015-11-10 00:40:48 +01:00
|
|
|
case ListType.ItemsAll.TYPE_CHANNEL:
|
|
|
|
switchToPanel(R.id.media_panel);
|
|
|
|
|
|
|
|
title = getItemResult.label;
|
|
|
|
underTitle = getItemResult.title;
|
|
|
|
art = getItemResult.fanart;
|
|
|
|
poster = getItemResult.thumbnail;
|
|
|
|
|
|
|
|
genreSeason = Utils.listStringConcat(getItemResult.genre, ", ");
|
|
|
|
year = getItemResult.premiered;
|
|
|
|
descriptionPlot = getItemResult.plot;
|
|
|
|
rating = getItemResult.rating;
|
|
|
|
maxRating = null;
|
|
|
|
votes = null;
|
|
|
|
break;
|
2015-02-16 12:36:21 +01:00
|
|
|
default:
|
|
|
|
// Other type, just present basic info
|
|
|
|
switchToPanel(R.id.media_panel);
|
|
|
|
|
|
|
|
title = getItemResult.label;
|
|
|
|
underTitle = "";
|
|
|
|
art = getItemResult.fanart;
|
|
|
|
poster = getItemResult.thumbnail;
|
|
|
|
|
|
|
|
genreSeason = null;
|
2015-04-08 23:28:19 +02:00
|
|
|
year = getItemResult.premiered;
|
|
|
|
descriptionPlot = removeYouTubeMarkup(getItemResult.plot);
|
2015-02-16 12:36:21 +01:00
|
|
|
rating = 0;
|
|
|
|
maxRating = null;
|
|
|
|
votes = null;
|
|
|
|
break;
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mediaTitle.setText(title);
|
|
|
|
mediaUndertitle.setText(underTitle);
|
|
|
|
|
2017-06-20 20:05:27 +02:00
|
|
|
mediaProgressIndicator.setOnProgressChangeListener(this);
|
|
|
|
mediaProgressIndicator.setMaxProgress(getPropertiesResult.totaltime.ToSeconds());
|
|
|
|
mediaProgressIndicator.setProgress(getPropertiesResult.time.ToSeconds());
|
|
|
|
|
|
|
|
int speed = getPropertiesResult.speed;
|
|
|
|
//TODO: check if following is still necessary for PVR playback
|
|
|
|
if (getItemResult.type.equals(ListType.ItemsAll.TYPE_CHANNEL))
|
|
|
|
speed = 1;
|
|
|
|
mediaProgressIndicator.setSpeed(speed);
|
2015-01-14 12:12:47 +01:00
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(year) || !TextUtils.isEmpty(genreSeason)) {
|
|
|
|
mediaYear.setVisibility(View.VISIBLE);
|
|
|
|
mediaGenreSeason.setVisibility(View.VISIBLE);
|
|
|
|
mediaYear.setText(year);
|
|
|
|
mediaGenreSeason.setText(genreSeason);
|
|
|
|
} else {
|
|
|
|
mediaYear.setVisibility(View.GONE);
|
|
|
|
mediaGenreSeason.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0 rating will not be shown
|
|
|
|
if (rating > 0) {
|
|
|
|
mediaRating.setVisibility(View.VISIBLE);
|
|
|
|
mediaMaxRating.setVisibility(View.VISIBLE);
|
|
|
|
mediaRatingVotes.setVisibility(View.VISIBLE);
|
|
|
|
mediaRating.setText(String.format("%01.01f", rating));
|
|
|
|
mediaMaxRating.setText(maxRating);
|
|
|
|
mediaRatingVotes.setText(votes);
|
|
|
|
} else {
|
|
|
|
mediaRating.setVisibility(View.GONE);
|
|
|
|
mediaMaxRating.setVisibility(View.GONE);
|
|
|
|
mediaRatingVotes.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(descriptionPlot)) {
|
|
|
|
mediaDescription.setVisibility(View.VISIBLE);
|
2017-10-19 10:05:45 +02:00
|
|
|
mediaDescription.setText(UIUtils.applyMarkup(getContext(), descriptionPlot));
|
2015-01-14 12:12:47 +01:00
|
|
|
} else {
|
|
|
|
mediaDescription.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2017-06-23 12:50:17 +02:00
|
|
|
UIUtils.setRepeatButton(repeatButton, getPropertiesResult.repeat);
|
2017-06-25 11:19:41 +02:00
|
|
|
shuffleButton.setHighlight(getPropertiesResult.shuffled);
|
2015-01-14 12:12:47 +01:00
|
|
|
|
|
|
|
Resources resources = getActivity().getResources();
|
|
|
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
|
|
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
|
|
|
|
|
|
|
int artHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_art_height),
|
|
|
|
artWidth = displayMetrics.widthPixels;
|
|
|
|
if (!TextUtils.isEmpty(art)) {
|
|
|
|
mediaPoster.setVisibility(View.VISIBLE);
|
|
|
|
int posterWidth = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_width);
|
|
|
|
int posterHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_height);
|
2015-02-16 12:36:21 +01:00
|
|
|
|
|
|
|
// If not video, change aspect ration of poster to a square
|
|
|
|
boolean isVideo = (getItemResult.type.equals(ListType.ItemsAll.TYPE_MOVIE)) ||
|
2016-11-30 13:20:21 +01:00
|
|
|
(getItemResult.type.equals(ListType.ItemsAll.TYPE_EPISODE));
|
2015-02-16 12:36:21 +01:00
|
|
|
if (!isVideo) {
|
|
|
|
ViewGroup.LayoutParams layoutParams = mediaPoster.getLayoutParams();
|
|
|
|
layoutParams.height = layoutParams.width;
|
|
|
|
mediaPoster.setLayoutParams(layoutParams);
|
|
|
|
posterHeight = posterWidth;
|
|
|
|
}
|
|
|
|
|
2015-01-24 12:14:40 +01:00
|
|
|
UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager,
|
2016-11-30 13:20:21 +01:00
|
|
|
poster, title,
|
|
|
|
mediaPoster, posterWidth, posterHeight);
|
2015-01-14 12:12:47 +01:00
|
|
|
UIUtils.loadImageIntoImageview(hostManager, art, mediaArt, displayMetrics.widthPixels, artHeight);
|
|
|
|
|
|
|
|
// Reset padding
|
|
|
|
int paddingLeft = resources.getDimensionPixelOffset(R.dimen.poster_width_plus_padding),
|
|
|
|
paddingRight = mediaTitle.getPaddingRight(),
|
|
|
|
paddingTop = mediaTitle.getPaddingTop(),
|
|
|
|
paddingBottom = mediaTitle.getPaddingBottom();
|
|
|
|
mediaTitle.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
|
|
|
|
mediaUndertitle.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
|
|
|
|
} else {
|
|
|
|
// No fanart, just present the poster
|
|
|
|
mediaPoster.setVisibility(View.GONE);
|
2015-11-10 00:40:48 +01:00
|
|
|
UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, poster, title, mediaArt, artWidth, artHeight);
|
2015-01-14 12:12:47 +01:00
|
|
|
// Reset padding
|
|
|
|
int paddingLeft = mediaTitle.getPaddingRight(),
|
|
|
|
paddingRight = mediaTitle.getPaddingRight(),
|
|
|
|
paddingTop = mediaTitle.getPaddingTop(),
|
|
|
|
paddingBottom = mediaTitle.getPaddingBottom();
|
|
|
|
mediaTitle.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
|
|
|
|
mediaUndertitle.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
// UIUtils.loadImageIntoImageview(hostManager, poster, mediaPoster);
|
|
|
|
// UIUtils.loadImageIntoImageview(hostManager, art, mediaArt);
|
|
|
|
|
|
|
|
// Continue for videos
|
2015-03-06 19:31:21 +01:00
|
|
|
// if (getItemResult.type.equals(ListType.ItemsAll.TYPE_EPISODE) ||
|
|
|
|
// getItemResult.type.equals(ListType.ItemsAll.TYPE_MOVIE)) {
|
|
|
|
// TODO: change this check to the commeted out one when jsonrpc returns the correct type
|
|
|
|
// if (getPropertiesResult.type.equals(PlayerType.PropertyValue.TYPE_VIDEO)) {
|
|
|
|
if ((getPropertiesResult.audiostreams != null) &&
|
2016-11-30 13:20:21 +01:00
|
|
|
(getPropertiesResult.audiostreams.size() > 0)) {
|
2015-01-14 12:12:47 +01:00
|
|
|
overflowButton.setVisibility(View.VISIBLE);
|
|
|
|
videoCastList.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
// Save subtitles and audiostreams list
|
|
|
|
availableAudioStreams = getPropertiesResult.audiostreams;
|
|
|
|
availableSubtitles = getPropertiesResult.subtitles;
|
|
|
|
currentAudiostreamIndex = getPropertiesResult.currentaudiostream.index;
|
|
|
|
currentSubtitleIndex = getPropertiesResult.currentsubtitle.index;
|
|
|
|
|
|
|
|
// Cast list
|
2015-07-30 20:27:58 +02:00
|
|
|
UIUtils.setupCastInfo(getActivity(), getItemResult.cast, videoCastList,
|
|
|
|
AllCastActivity.buildLaunchIntent(getActivity(), title,
|
|
|
|
(ArrayList<VideoType.Cast>)getItemResult.cast));
|
2015-01-14 12:12:47 +01:00
|
|
|
} else {
|
|
|
|
overflowButton.setVisibility(View.GONE);
|
|
|
|
videoCastList.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleans up anything left when stop playing
|
|
|
|
*/
|
|
|
|
private void stopNowPlayingInfo() {
|
|
|
|
// Just stop the seek bar handler callbacks
|
2017-06-20 20:05:27 +02:00
|
|
|
mediaProgressIndicator.setSpeed(0);
|
|
|
|
|
2015-01-14 12:12:47 +01:00
|
|
|
availableSubtitles = null;
|
|
|
|
availableAudioStreams = null;
|
|
|
|
currentSubtitleIndex = -1;
|
|
|
|
currentAudiostreamIndex = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switches the info panel shown (they are exclusive)
|
|
|
|
* @param panelResId The panel to show
|
|
|
|
*/
|
|
|
|
private void switchToPanel(int panelResId) {
|
|
|
|
switch (panelResId) {
|
|
|
|
case R.id.info_panel:
|
|
|
|
mediaPanel.setVisibility(View.GONE);
|
|
|
|
mediaArt.setVisibility(View.GONE);
|
|
|
|
infoPanel.setVisibility(View.VISIBLE);
|
|
|
|
break;
|
|
|
|
case R.id.media_panel:
|
|
|
|
infoPanel.setVisibility(View.GONE);
|
|
|
|
mediaPanel.setVisibility(View.VISIBLE);
|
|
|
|
mediaArt.setVisibility(View.VISIBLE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 23:28:19 +02:00
|
|
|
/**
|
|
|
|
* Removes some markup that appears on the plot for youtube videos
|
|
|
|
*
|
|
|
|
* @param plot Plot as returned by youtube plugin
|
|
|
|
* @return Plot without markup
|
|
|
|
*/
|
|
|
|
private String removeYouTubeMarkup(String plot) {
|
|
|
|
if (plot == null) return null;
|
|
|
|
return plot.replaceAll("\\[.*\\]", "");
|
|
|
|
}
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|