2017-04-09 19:34:00 +02:00
|
|
|
package org.schabi.newpipe.fragments.detail;
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
2017-04-09 19:34:00 +02:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.content.DialogInterface;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.content.Intent;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.content.SharedPreferences;
|
2016-02-01 09:59:28 +01:00
|
|
|
import android.media.AudioManager;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.os.Bundle;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.preference.PreferenceManager;
|
2017-04-09 19:34:00 +02:00
|
|
|
import android.support.v4.app.Fragment;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.support.v4.content.ContextCompat;
|
2017-04-09 19:34:00 +02:00
|
|
|
import android.support.v7.app.ActionBar;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2017-02-27 12:55:15 +01:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.text.Html;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
2015-11-29 13:06:27 +01:00
|
|
|
import android.util.Log;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.util.TypedValue;
|
2017-04-09 19:34:00 +02:00
|
|
|
import android.view.LayoutInflater;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.view.Menu;
|
2017-04-09 19:34:00 +02:00
|
|
|
import android.view.MenuInflater;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.view.MenuItem;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.ProgressBar;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
import com.nirhart.parallaxscroll.views.ParallaxScrollView;
|
|
|
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
|
|
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
|
import com.nostra13.universalimageloader.core.assist.FailReason;
|
|
|
|
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
|
|
|
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.ImageErrorLoadingListener;
|
|
|
|
import org.schabi.newpipe.Localization;
|
2016-08-02 21:17:54 +02:00
|
|
|
import org.schabi.newpipe.R;
|
2017-03-31 20:15:26 +02:00
|
|
|
import org.schabi.newpipe.ReCaptchaActivity;
|
|
|
|
import org.schabi.newpipe.download.DownloadDialog;
|
|
|
|
import org.schabi.newpipe.extractor.InfoItem;
|
|
|
|
import org.schabi.newpipe.extractor.MediaFormat;
|
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
|
|
|
import org.schabi.newpipe.extractor.stream_info.AudioStream;
|
|
|
|
import org.schabi.newpipe.extractor.stream_info.StreamInfo;
|
|
|
|
import org.schabi.newpipe.extractor.stream_info.VideoStream;
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.fragments.OnItemSelectedListener;
|
2017-03-31 20:15:26 +02:00
|
|
|
import org.schabi.newpipe.info_list.InfoItemBuilder;
|
2017-04-17 06:19:53 +02:00
|
|
|
import org.schabi.newpipe.player.MainVideoPlayer;
|
2017-03-31 20:15:26 +02:00
|
|
|
import org.schabi.newpipe.player.PlayVideoActivity;
|
|
|
|
import org.schabi.newpipe.player.PopupVideoPlayer;
|
2017-02-18 21:59:48 +01:00
|
|
|
import org.schabi.newpipe.report.ErrorActivity;
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.util.NavigationHelper;
|
2017-03-31 20:15:26 +02:00
|
|
|
import org.schabi.newpipe.util.PermissionHelper;
|
2017-04-09 19:34:00 +02:00
|
|
|
import org.schabi.newpipe.util.Utils;
|
|
|
|
import org.schabi.newpipe.workers.StreamExtractorWorker;
|
2015-11-17 00:32:00 +01:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
import java.io.Serializable;
|
2017-03-31 20:15:26 +02:00
|
|
|
import java.util.ArrayList;
|
2017-04-09 19:34:00 +02:00
|
|
|
import java.util.Stack;
|
2017-03-31 20:15:26 +02:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
|
|
@SuppressWarnings("FieldCanBeLocal")
|
2017-04-09 19:34:00 +02:00
|
|
|
public class VideoDetailFragment extends Fragment implements StreamExtractorWorker.OnStreamInfoReceivedListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
|
|
|
|
|
|
|
private final String TAG = "VideoDetailFragment@" + Integer.toHexString(hashCode());
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
private static final String KORE_PACKET = "org.xbmc.kore";
|
2017-04-09 19:34:00 +02:00
|
|
|
private static final String SERVICE_ID_KEY = "service_id_key";
|
|
|
|
private static final String VIDEO_URL_KEY = "video_url_key";
|
|
|
|
private static final String VIDEO_TITLE_KEY = "video_title_key";
|
|
|
|
private static final String STACK_KEY = "stack_key";
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
public static final String AUTO_PLAY = "auto_play";
|
2015-10-29 17:56:35 +01:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
private AppCompatActivity activity;
|
|
|
|
private OnItemSelectedListener onItemSelectedListener;
|
2017-04-12 08:07:15 +02:00
|
|
|
private ArrayList<VideoStream> sortedStreamVideosList;
|
2017-03-31 20:15:26 +02:00
|
|
|
private ActionBarHandler actionBarHandler;
|
|
|
|
|
|
|
|
private InfoItemBuilder infoItemBuilder = null;
|
|
|
|
private StreamInfo currentStreamInfo = null;
|
2017-04-09 19:34:00 +02:00
|
|
|
private StreamExtractorWorker curExtractorWorker;
|
|
|
|
|
|
|
|
private String videoTitle;
|
2015-09-04 02:15:03 +02:00
|
|
|
private String videoUrl;
|
2017-03-31 20:15:26 +02:00
|
|
|
private int serviceId = -1;
|
|
|
|
|
2017-04-12 08:07:15 +02:00
|
|
|
private AtomicBoolean wasLoading = new AtomicBoolean(false);
|
2017-03-31 20:15:26 +02:00
|
|
|
private AtomicBoolean isLoading = new AtomicBoolean(false);
|
2017-04-12 08:07:15 +02:00
|
|
|
private static final int RELATED_STREAMS_UPDATE_FLAG = 0x1;
|
|
|
|
private static final int RESOLUTIONS_MENU_UPDATE_FLAG = 0x2;
|
|
|
|
private int updateFlags = 0;
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
private boolean autoPlayEnabled;
|
|
|
|
private boolean showRelatedStreams;
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
private static final ImageLoader imageLoader = ImageLoader.getInstance();
|
|
|
|
private static final DisplayImageOptions displayImageOptions =
|
|
|
|
new DisplayImageOptions.Builder().displayer(new FadeInBitmapDisplayer(400)).cacheInMemory(false).build();
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Views
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
private ProgressBar loadingProgressBar;
|
|
|
|
|
|
|
|
private ParallaxScrollView parallaxScrollRootView;
|
|
|
|
private RelativeLayout contentRootLayout;
|
|
|
|
|
|
|
|
private Button thumbnailBackgroundButton;
|
|
|
|
private ImageView thumbnailImageView;
|
|
|
|
private ImageView thumbnailPlayButton;
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
private View videoTitleRoot;
|
|
|
|
private TextView videoTitleTextView;
|
|
|
|
private ImageView videoTitleToggleArrow;
|
|
|
|
private TextView videoCountView;
|
|
|
|
|
|
|
|
private RelativeLayout videoDescriptionRootLayout;
|
|
|
|
private TextView videoUploadDateView;
|
|
|
|
private TextView videoDescriptionView;
|
|
|
|
|
|
|
|
private Button uploaderButton;
|
|
|
|
private TextView uploaderTextView;
|
|
|
|
private ImageView uploaderThumb;
|
|
|
|
|
|
|
|
private TextView thumbsUpTextView;
|
|
|
|
private ImageView thumbsUpImageView;
|
|
|
|
private TextView thumbsDownTextView;
|
|
|
|
private ImageView thumbsDownImageView;
|
|
|
|
private TextView thumbsDisabledTextView;
|
|
|
|
|
|
|
|
private TextView nextStreamTitle;
|
|
|
|
private RelativeLayout relatedStreamRootLayout;
|
|
|
|
private LinearLayout relatedStreamsView;
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
/*////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
public static VideoDetailFragment getInstance(int serviceId, String url) {
|
|
|
|
return getInstance(serviceId, url, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static VideoDetailFragment getInstance(int serviceId, String videoUrl, String videoTitle) {
|
|
|
|
VideoDetailFragment instance = getInstance();
|
|
|
|
instance.selectVideo(serviceId, videoUrl, videoTitle);
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static VideoDetailFragment getInstance() {
|
|
|
|
return new VideoDetailFragment();
|
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
2017-04-09 19:34:00 +02:00
|
|
|
// Fragment's Lifecycle
|
2017-03-31 20:15:26 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
@Override
|
|
|
|
public void onAttach(Context context) {
|
|
|
|
super.onAttach(context);
|
|
|
|
activity = (AppCompatActivity) context;
|
|
|
|
onItemSelectedListener = (OnItemSelectedListener) context;
|
|
|
|
}
|
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2015-09-04 02:15:03 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2017-04-09 19:34:00 +02:00
|
|
|
if (savedInstanceState != null) {
|
|
|
|
videoTitle = savedInstanceState.getString(VIDEO_TITLE_KEY);
|
|
|
|
videoUrl = savedInstanceState.getString(VIDEO_URL_KEY);
|
|
|
|
serviceId = savedInstanceState.getInt(SERVICE_ID_KEY);
|
|
|
|
Serializable serializable = savedInstanceState.getSerializable(STACK_KEY);
|
|
|
|
if (serializable instanceof Stack) {
|
|
|
|
//noinspection unchecked
|
|
|
|
Stack<StackItem> list = (Stack<StackItem>) serializable;
|
|
|
|
stack.clear();
|
|
|
|
stack.addAll(list);
|
|
|
|
}
|
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
showRelatedStreams = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(getString(R.string.show_next_video_key), true);
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(activity).registerOnSharedPreferenceChangeListener(this);
|
|
|
|
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
|
|
|
isLoading.set(false);
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
}
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
return inflater.inflate(R.layout.fragment_video_detail, container, false);
|
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
@Override
|
|
|
|
public void onViewCreated(View rootView, Bundle savedInstanceState) {
|
|
|
|
initViews(rootView);
|
2017-03-31 20:15:26 +02:00
|
|
|
initListeners();
|
2017-04-12 08:07:15 +02:00
|
|
|
selectAndLoadVideo(serviceId, videoUrl, videoTitle);
|
|
|
|
wasLoading.set(false);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-09 19:34:00 +02:00
|
|
|
public void onDestroyView() {
|
|
|
|
super.onDestroyView();
|
|
|
|
thumbnailImageView.setImageBitmap(null);
|
|
|
|
relatedStreamsView.removeAllViews();
|
|
|
|
|
|
|
|
loadingProgressBar = null;
|
|
|
|
|
|
|
|
parallaxScrollRootView = null;
|
|
|
|
contentRootLayout = null;
|
|
|
|
|
|
|
|
thumbnailBackgroundButton = null;
|
|
|
|
thumbnailImageView = null;
|
|
|
|
thumbnailPlayButton = null;
|
|
|
|
|
|
|
|
videoTitleRoot = null;
|
|
|
|
videoTitleTextView = null;
|
|
|
|
videoTitleToggleArrow = null;
|
|
|
|
videoCountView = null;
|
|
|
|
|
|
|
|
videoDescriptionRootLayout = null;
|
|
|
|
videoUploadDateView = null;
|
|
|
|
videoDescriptionView = null;
|
|
|
|
|
|
|
|
uploaderButton = null;
|
|
|
|
uploaderTextView = null;
|
|
|
|
uploaderThumb = null;
|
|
|
|
|
|
|
|
thumbsUpTextView = null;
|
|
|
|
thumbsUpImageView = null;
|
|
|
|
thumbsDownTextView = null;
|
|
|
|
thumbsDownImageView = null;
|
|
|
|
thumbsDisabledTextView = null;
|
|
|
|
|
|
|
|
nextStreamTitle = null;
|
|
|
|
relatedStreamRootLayout = null;
|
|
|
|
relatedStreamsView = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2017-03-31 20:15:26 +02:00
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
// Currently only used for enable/disable related videos
|
2017-04-09 19:34:00 +02:00
|
|
|
// but can be extended for other live settings changes
|
2017-04-12 08:07:15 +02:00
|
|
|
if (updateFlags != 0) {
|
|
|
|
if (!isLoading.get()) {
|
|
|
|
if ((updateFlags & RELATED_STREAMS_UPDATE_FLAG) != 0) initRelatedVideos(currentStreamInfo);
|
|
|
|
if ((updateFlags & RESOLUTIONS_MENU_UPDATE_FLAG) != 0) setupActionBarHandler(currentStreamInfo);
|
|
|
|
}
|
|
|
|
updateFlags = 0;
|
2016-09-28 06:09:42 +02:00
|
|
|
}
|
2017-04-09 19:34:00 +02:00
|
|
|
|
|
|
|
// Check if it was loading when the activity was stopped/paused,
|
|
|
|
// because when this happen, the curExtractorWorker is cancelled
|
2017-04-12 08:07:15 +02:00
|
|
|
if (wasLoading.getAndSet(false)) selectAndLoadVideo(serviceId, videoUrl, videoTitle);
|
2016-09-28 06:09:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-09 19:34:00 +02:00
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
2017-04-12 08:07:15 +02:00
|
|
|
wasLoading.set(curExtractorWorker.isRunning());
|
2017-04-09 19:34:00 +02:00
|
|
|
if (curExtractorWorker != null && curExtractorWorker.isRunning()) curExtractorWorker.cancel();
|
2016-09-28 06:09:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
@Override
|
2017-04-09 19:34:00 +02:00
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(activity).unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
imageLoader.clearMemoryCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
outState.putString(VIDEO_URL_KEY, videoUrl);
|
|
|
|
outState.putString(VIDEO_TITLE_KEY, videoTitle);
|
|
|
|
outState.putInt(SERVICE_ID_KEY, serviceId);
|
|
|
|
outState.putSerializable(STACK_KEY, stack);
|
2016-09-28 06:09:42 +02:00
|
|
|
}
|
2015-10-29 17:56:35 +01:00
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
switch (requestCode) {
|
|
|
|
case ReCaptchaActivity.RECAPTCHA_REQUEST:
|
2017-04-09 19:34:00 +02:00
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
NavigationHelper.openVideoDetail(onItemSelectedListener, serviceId, videoUrl, videoTitle);
|
2017-03-31 20:15:26 +02:00
|
|
|
} else Log.e(TAG, "ReCaptcha failed");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Log.e(TAG, "Request code from activity not supported [" + requestCode + "]");
|
|
|
|
break;
|
|
|
|
}
|
2015-10-29 17:56:35 +01:00
|
|
|
}
|
|
|
|
|
2016-01-01 23:04:29 +01:00
|
|
|
@Override
|
2017-03-31 20:15:26 +02:00
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
|
|
if (key.equals(getString(R.string.show_next_video_key))) {
|
|
|
|
showRelatedStreams = sharedPreferences.getBoolean(key, true);
|
2017-04-12 08:07:15 +02:00
|
|
|
updateFlags |= RELATED_STREAMS_UPDATE_FLAG;
|
|
|
|
} else if (key.equals(getString(R.string.preferred_video_format_key))
|
|
|
|
|| key.equals(getString(R.string.default_resolution_key))
|
|
|
|
|| key.equals(getString(R.string.show_higher_resolutions_key))) {
|
|
|
|
updateFlags |= RESOLUTIONS_MENU_UPDATE_FLAG;
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Init
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
private void initViews(View rootView) {
|
|
|
|
loadingProgressBar = (ProgressBar) rootView.findViewById(R.id.detail_loading_progress_bar);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
parallaxScrollRootView = (ParallaxScrollView) rootView.findViewById(R.id.detail_main_content);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
//thumbnailRootLayout = (RelativeLayout) rootView.findViewById(R.id.detail_thumbnail_root_layout);
|
|
|
|
thumbnailBackgroundButton = (Button) rootView.findViewById(R.id.detail_stream_thumbnail_background_button);
|
|
|
|
thumbnailImageView = (ImageView) rootView.findViewById(R.id.detail_thumbnail_image_view);
|
|
|
|
thumbnailPlayButton = (ImageView) rootView.findViewById(R.id.detail_thumbnail_play_button);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
contentRootLayout = (RelativeLayout) rootView.findViewById(R.id.detail_content_root_layout);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
videoTitleRoot = rootView.findViewById(R.id.detail_title_root_layout);
|
|
|
|
videoTitleTextView = (TextView) rootView.findViewById(R.id.detail_video_title_view);
|
|
|
|
videoTitleToggleArrow = (ImageView) rootView.findViewById(R.id.detail_toggle_description_view);
|
|
|
|
videoCountView = (TextView) rootView.findViewById(R.id.detail_view_count_view);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
videoDescriptionRootLayout = (RelativeLayout) rootView.findViewById(R.id.detail_description_root_layout);
|
|
|
|
videoUploadDateView = (TextView) rootView.findViewById(R.id.detail_upload_date_view);
|
|
|
|
videoDescriptionView = (TextView) rootView.findViewById(R.id.detail_description_view);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
//thumbsRootLayout = (LinearLayout) rootView.findViewById(R.id.detail_thumbs_root_layout);
|
|
|
|
thumbsUpTextView = (TextView) rootView.findViewById(R.id.detail_thumbs_up_count_view);
|
|
|
|
thumbsUpImageView = (ImageView) rootView.findViewById(R.id.detail_thumbs_up_img_view);
|
|
|
|
thumbsDownTextView = (TextView) rootView.findViewById(R.id.detail_thumbs_down_count_view);
|
|
|
|
thumbsDownImageView = (ImageView) rootView.findViewById(R.id.detail_thumbs_down_img_view);
|
|
|
|
thumbsDisabledTextView = (TextView) rootView.findViewById(R.id.detail_thumbs_disabled_view);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
//uploaderRootLayout = (FrameLayout) rootView.findViewById(R.id.detail_uploader_root_layout);
|
|
|
|
uploaderButton = (Button) rootView.findViewById(R.id.detail_uploader_button);
|
|
|
|
uploaderTextView = (TextView) rootView.findViewById(R.id.detail_uploader_text_view);
|
|
|
|
uploaderThumb = (ImageView) rootView.findViewById(R.id.detail_uploader_thumbnail_view);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
relatedStreamRootLayout = (RelativeLayout) rootView.findViewById(R.id.detail_related_streams_root_layout);
|
|
|
|
nextStreamTitle = (TextView) rootView.findViewById(R.id.detail_next_stream_title);
|
|
|
|
relatedStreamsView = (LinearLayout) rootView.findViewById(R.id.detail_related_streams_view);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
actionBarHandler = new ActionBarHandler(activity);
|
2017-03-31 20:15:26 +02:00
|
|
|
videoDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
infoItemBuilder = new InfoItemBuilder(activity, rootView.findViewById(android.R.id.content));
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
setHeightThumbnail();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initListeners() {
|
|
|
|
videoTitleRoot.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (videoDescriptionRootLayout.getVisibility() == View.VISIBLE) {
|
|
|
|
videoTitleTextView.setMaxLines(1);
|
|
|
|
videoDescriptionRootLayout.setVisibility(View.GONE);
|
|
|
|
videoTitleToggleArrow.setImageResource(R.drawable.arrow_down);
|
|
|
|
} else {
|
|
|
|
videoTitleTextView.setMaxLines(10);
|
|
|
|
videoDescriptionRootLayout.setVisibility(View.VISIBLE);
|
|
|
|
videoTitleToggleArrow.setImageResource(R.drawable.arrow_up);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
thumbnailBackgroundButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (!isLoading.get() && currentStreamInfo != null) playVideo(currentStreamInfo);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
infoItemBuilder.setOnStreamInfoItemSelectedListener(new InfoItemBuilder.OnInfoItemSelectedListener() {
|
|
|
|
@Override
|
2017-04-09 19:34:00 +02:00
|
|
|
public void selected(int serviceId, String url, String title) {
|
|
|
|
//NavigationHelper.openVideoDetail(activity, url, serviceId);
|
|
|
|
selectAndLoadVideo(serviceId, url, title);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
uploaderButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2017-04-09 19:34:00 +02:00
|
|
|
NavigationHelper.openChannel(onItemSelectedListener, currentStreamInfo.service_id, currentStreamInfo.channel_url, currentStreamInfo.uploader);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initThumbnailViews(StreamInfo info) {
|
|
|
|
if (info.thumbnail_url != null && !info.thumbnail_url.isEmpty()) {
|
|
|
|
imageLoader.displayImage(info.thumbnail_url, thumbnailImageView,
|
|
|
|
displayImageOptions, new SimpleImageLoadingListener() {
|
|
|
|
@Override
|
|
|
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
2017-04-09 19:34:00 +02:00
|
|
|
ErrorActivity.reportError(activity,
|
|
|
|
failReason.getCause(), null, activity.findViewById(android.R.id.content),
|
2017-03-31 20:15:26 +02:00
|
|
|
ErrorActivity.ErrorInfo.make(ErrorActivity.LOAD_IMAGE,
|
|
|
|
NewPipe.getNameOfService(currentStreamInfo.service_id), imageUri,
|
|
|
|
R.string.could_not_load_thumbnails));
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
} else thumbnailImageView.setImageResource(R.drawable.dummy_thumbnail_dark);
|
|
|
|
|
|
|
|
if (info.uploader_thumbnail_url != null && !info.uploader_thumbnail_url.isEmpty()) {
|
|
|
|
imageLoader.displayImage(info.uploader_thumbnail_url,
|
|
|
|
uploaderThumb, displayImageOptions,
|
2017-04-09 19:34:00 +02:00
|
|
|
new ImageErrorLoadingListener(activity, activity.findViewById(android.R.id.content), info.service_id));
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
2016-01-01 23:04:29 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
private void initRelatedVideos(StreamInfo info) {
|
|
|
|
if (relatedStreamsView.getChildCount() > 0) relatedStreamsView.removeAllViews();
|
|
|
|
|
|
|
|
if (info.next_video != null && showRelatedStreams) {
|
|
|
|
nextStreamTitle.setVisibility(View.VISIBLE);
|
|
|
|
relatedStreamsView.addView(infoItemBuilder.buildView(relatedStreamsView, info.next_video));
|
|
|
|
relatedStreamsView.addView(getSeparatorView());
|
2017-04-09 19:34:00 +02:00
|
|
|
relatedStreamRootLayout.setVisibility(View.VISIBLE);
|
2017-03-31 20:15:26 +02:00
|
|
|
} else nextStreamTitle.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
if (info.related_streams != null && !info.related_streams.isEmpty() && showRelatedStreams) {
|
|
|
|
for (InfoItem item : info.related_streams) {
|
|
|
|
relatedStreamsView.addView(infoItemBuilder.buildView(relatedStreamsView, item));
|
|
|
|
}
|
2017-04-09 19:34:00 +02:00
|
|
|
relatedStreamRootLayout.setVisibility(View.VISIBLE);
|
|
|
|
} else if (info.next_video == null) relatedStreamRootLayout.setVisibility(View.GONE);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Menu
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2015-10-29 17:56:35 +01:00
|
|
|
@Override
|
2017-04-09 19:34:00 +02:00
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
actionBarHandler.setupMenu(menu, inflater);
|
|
|
|
actionBarHandler.setupNavMenu(activity);
|
|
|
|
ActionBar supportActionBar = activity.getSupportActionBar();
|
|
|
|
if (supportActionBar != null) {
|
|
|
|
supportActionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
supportActionBar.setDisplayShowTitleEnabled(false);
|
|
|
|
//noinspection deprecation
|
|
|
|
supportActionBar.setNavigationMode(0);
|
|
|
|
}
|
2015-09-04 02:15:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2017-03-31 20:15:26 +02:00
|
|
|
return actionBarHandler.onItemSelected(item) || super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setupActionBarHandler(final StreamInfo info) {
|
2017-04-09 19:34:00 +02:00
|
|
|
if (activity.getSupportActionBar() != null) {
|
|
|
|
//noinspection deprecation
|
|
|
|
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
|
|
|
|
}
|
|
|
|
|
2017-04-12 08:07:15 +02:00
|
|
|
sortedStreamVideosList = Utils.getSortedStreamVideosList(activity, info.video_streams, info.video_only_streams, false);
|
|
|
|
actionBarHandler.setupStreamList(sortedStreamVideosList);
|
2017-03-31 20:15:26 +02:00
|
|
|
actionBarHandler.setOnShareListener(new ActionBarHandler.OnActionListener() {
|
|
|
|
@Override
|
|
|
|
public void onActionSelected(int selectedStreamId) {
|
|
|
|
if (isLoading.get()) return;
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(Intent.ACTION_SEND);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info.webpage_url);
|
|
|
|
intent.setType("text/plain");
|
2017-04-09 19:34:00 +02:00
|
|
|
startActivity(Intent.createChooser(intent, activity.getString(R.string.share_dialog_title)));
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
actionBarHandler.setOnOpenInBrowserListener(new ActionBarHandler.OnActionListener() {
|
|
|
|
@Override
|
|
|
|
public void onActionSelected(int selectedStreamId) {
|
|
|
|
if (isLoading.get()) return;
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse(info.webpage_url));
|
2017-04-09 19:34:00 +02:00
|
|
|
startActivity(Intent.createChooser(intent, activity.getString(R.string.choose_browser)));
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
actionBarHandler.setOnOpenInPopupListener(new ActionBarHandler.OnActionListener() {
|
|
|
|
@Override
|
|
|
|
public void onActionSelected(int selectedStreamId) {
|
|
|
|
if (isLoading.get()) return;
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !PermissionHelper.checkSystemAlertWindowPermission(activity)) {
|
|
|
|
Toast.makeText(activity, R.string.msg_popup_permission, Toast.LENGTH_LONG).show();
|
2017-03-31 20:15:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
Toast.makeText(activity, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show();
|
2017-04-17 06:19:53 +02:00
|
|
|
Intent mIntent = NavigationHelper.getOpenVideoPlayerIntent(activity, PopupVideoPlayer.class, info, selectedStreamId);
|
2017-04-12 08:07:15 +02:00
|
|
|
activity.startService(mIntent);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
actionBarHandler.setOnPlayWithKodiListener(new ActionBarHandler.OnActionListener() {
|
|
|
|
@Override
|
|
|
|
public void onActionSelected(int selectedStreamId) {
|
|
|
|
if (isLoading.get()) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setPackage(KORE_PACKET);
|
|
|
|
intent.setData(Uri.parse(info.webpage_url.replace("https", "http")));
|
2017-04-09 19:34:00 +02:00
|
|
|
activity.startActivity(intent);
|
2017-03-31 20:15:26 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2017-04-09 19:34:00 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
2017-03-31 20:15:26 +02:00
|
|
|
builder.setMessage(R.string.kore_not_found)
|
|
|
|
.setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
2017-04-09 19:34:00 +02:00
|
|
|
intent.setData(Uri.parse(activity.getString(R.string.fdroid_kore_url)));
|
|
|
|
activity.startActivity(intent);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
actionBarHandler.setOnDownloadListener(new ActionBarHandler.OnActionListener() {
|
|
|
|
@Override
|
|
|
|
public void onActionSelected(int selectedStreamId) {
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (isLoading.get() || !PermissionHelper.checkStoragePermissions(activity)) {
|
2017-03-31 20:15:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
|
|
|
// Sometimes it may be that some information is not available due to changes fo the
|
|
|
|
// website which was crawled. Then the ui has to understand this and act right.
|
|
|
|
|
|
|
|
if (info.audio_streams != null) {
|
|
|
|
AudioStream audioStream =
|
2017-04-09 19:34:00 +02:00
|
|
|
info.audio_streams.get(Utils.getPreferredAudioFormat(activity, info.audio_streams));
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
|
|
|
|
args.putString(DownloadDialog.AUDIO_URL, audioStream.url);
|
|
|
|
args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix);
|
|
|
|
}
|
|
|
|
|
2017-04-12 08:07:15 +02:00
|
|
|
if (sortedStreamVideosList != null) {
|
|
|
|
VideoStream selectedStreamItem = sortedStreamVideosList.get(selectedStreamId);
|
2017-03-31 20:15:26 +02:00
|
|
|
String videoSuffix = "." + MediaFormat.getSuffixById(selectedStreamItem.format);
|
|
|
|
args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix);
|
|
|
|
args.putString(DownloadDialog.VIDEO_URL, selectedStreamItem.url);
|
|
|
|
}
|
|
|
|
|
|
|
|
args.putString(DownloadDialog.TITLE, info.title);
|
|
|
|
DownloadDialog downloadDialog = DownloadDialog.newInstance(args);
|
2017-04-09 19:34:00 +02:00
|
|
|
downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
|
2017-03-31 20:15:26 +02:00
|
|
|
} catch (Exception e) {
|
2017-04-09 19:34:00 +02:00
|
|
|
Toast.makeText(activity,
|
2017-03-31 20:15:26 +02:00
|
|
|
R.string.could_not_setup_download_menu, Toast.LENGTH_LONG).show();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (info.audio_streams == null) {
|
|
|
|
actionBarHandler.showAudioAction(false);
|
|
|
|
} else {
|
|
|
|
actionBarHandler.setOnPlayAudioListener(new ActionBarHandler.OnActionListener() {
|
|
|
|
@Override
|
|
|
|
public void onActionSelected(int selectedStreamId) {
|
|
|
|
if (isLoading.get()) return;
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
boolean useExternalAudioPlayer = PreferenceManager.getDefaultSharedPreferences(activity)
|
|
|
|
.getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
|
2017-03-31 20:15:26 +02:00
|
|
|
Intent intent;
|
2017-04-17 06:19:53 +02:00
|
|
|
AudioStream audioStream = info.audio_streams.get(Utils.getPreferredAudioFormat(activity, info.audio_streams));
|
|
|
|
if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) {
|
|
|
|
activity.startService(NavigationHelper.getOpenBackgroundPlayerIntent(activity, info, audioStream));
|
|
|
|
Toast.makeText(activity, R.string.background_player_playing_toast, Toast.LENGTH_SHORT).show();
|
2017-03-31 20:15:26 +02:00
|
|
|
} else {
|
|
|
|
intent = new Intent();
|
|
|
|
try {
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.setDataAndType(Uri.parse(audioStream.url),
|
|
|
|
MediaFormat.getMimeById(audioStream.format));
|
|
|
|
intent.putExtra(Intent.EXTRA_TITLE, info.title);
|
|
|
|
intent.putExtra("title", info.title);
|
|
|
|
// HERE !!!
|
2017-04-09 19:34:00 +02:00
|
|
|
activity.startActivity(intent);
|
2017-03-31 20:15:26 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2017-04-09 19:34:00 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
2017-03-31 20:15:26 +02:00
|
|
|
builder.setMessage(R.string.no_player_found)
|
|
|
|
.setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
2017-04-09 19:34:00 +02:00
|
|
|
intent.setData(Uri.parse(activity.getString(R.string.fdroid_vlc_url)));
|
|
|
|
activity.startActivity(intent);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
Log.i(TAG, "You unlocked a secret unicorn.");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
Log.e(TAG, "Either no Streaming player for audio was installed, or something important crashed:");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OwnStack
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stack that contains the "navigation history".<br>
|
|
|
|
* The peek is the current video.
|
|
|
|
*/
|
|
|
|
private final Stack<StackItem> stack = new Stack<>();
|
|
|
|
|
|
|
|
public void clearHistory() {
|
|
|
|
stack.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void pushToStack(String videoUrl, String videoTitle) {
|
|
|
|
|
|
|
|
if (stack.size() > 0 && stack.peek().getUrl().equals(videoUrl)) return;
|
|
|
|
stack.push(new StackItem(videoUrl, videoTitle));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTitleToUrl(String videoUrl, String videoTitle) {
|
|
|
|
if (videoTitle != null && !videoTitle.isEmpty()) {
|
|
|
|
for (StackItem stackItem : stack) {
|
|
|
|
if (stackItem.getUrl().equals(videoUrl)) stackItem.setTitle(videoTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onActivityBackPressed() {
|
|
|
|
// That means that we are on the start of the stack,
|
|
|
|
// return false to let the MainActivity handle the onBack
|
|
|
|
if (stack.size() == 1) return false;
|
|
|
|
// Remove top
|
|
|
|
stack.pop();
|
|
|
|
// Get url from the new top
|
|
|
|
StackItem peek = stack.peek();
|
|
|
|
selectAndLoadVideo(0, peek.getUrl(),
|
|
|
|
peek.getTitle() != null && !peek.getTitle().isEmpty() ? peek.getTitle() : ""
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utils
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
public void setAutoplay(boolean autoplay) {
|
|
|
|
this.autoPlayEnabled = autoplay;
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
public void selectVideo(int serviceId, String videoUrl, String videoTitle) {
|
|
|
|
this.videoUrl = videoUrl;
|
|
|
|
this.videoTitle = videoTitle;
|
|
|
|
this.serviceId = serviceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void selectAndLoadVideo(int serviceId, String videoUrl, String videoTitle) {
|
|
|
|
selectVideo(serviceId, videoUrl, videoTitle);
|
|
|
|
loadSelectedVideo();
|
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
public void loadSelectedVideo() {
|
2017-04-12 08:07:15 +02:00
|
|
|
isLoading.set(true);
|
2017-04-09 19:34:00 +02:00
|
|
|
pushToStack(videoUrl, videoTitle);
|
|
|
|
|
|
|
|
if (curExtractorWorker != null && curExtractorWorker.isRunning()) curExtractorWorker.cancel();
|
|
|
|
|
|
|
|
if (activity.getSupportActionBar() != null) {
|
|
|
|
//noinspection deprecation
|
|
|
|
activity.getSupportActionBar().setNavigationMode(0);
|
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
animateView(contentRootLayout, false, 50, null);
|
|
|
|
|
|
|
|
videoTitleTextView.setMaxLines(1);
|
|
|
|
int scrollY = parallaxScrollRootView.getScrollY();
|
|
|
|
if (scrollY < 30) animateView(videoTitleTextView, false, 200, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2017-04-12 08:07:15 +02:00
|
|
|
if (videoTitleTextView == null) return;
|
2017-04-09 19:34:00 +02:00
|
|
|
videoTitleTextView.setText(videoTitle != null ? videoTitle : "");
|
|
|
|
animateView(videoTitleTextView, true, 400, null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
else videoTitleTextView.setText(videoTitle != null ? videoTitle : "");
|
|
|
|
//videoTitleTextView.setText(videoTitle != null ? videoTitle : "");
|
|
|
|
videoDescriptionRootLayout.setVisibility(View.GONE);
|
|
|
|
videoTitleToggleArrow.setImageResource(R.drawable.arrow_down);
|
|
|
|
videoTitleToggleArrow.setVisibility(View.GONE);
|
|
|
|
videoTitleRoot.setClickable(false);
|
|
|
|
|
|
|
|
//thumbnailPlayButton.setVisibility(View.GONE);
|
|
|
|
animateView(thumbnailPlayButton, false, 50, null);
|
2017-03-31 20:15:26 +02:00
|
|
|
loadingProgressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
imageLoader.cancelDisplayTask(thumbnailImageView);
|
|
|
|
imageLoader.cancelDisplayTask(uploaderThumb);
|
2017-04-09 19:34:00 +02:00
|
|
|
thumbnailImageView.setImageBitmap(null);
|
|
|
|
uploaderThumb.setImageBitmap(null);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
curExtractorWorker = new StreamExtractorWorker(activity, serviceId, videoUrl, this);
|
|
|
|
curExtractorWorker.start();
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void playVideo(StreamInfo info) {
|
|
|
|
// ----------- THE MAGIC MOMENT ---------------
|
2017-04-12 08:07:15 +02:00
|
|
|
VideoStream selectedVideoStream = sortedStreamVideosList.get(actionBarHandler.getSelectedVideoStream());
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(this.getString(R.string.use_external_video_player_key), false)) {
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
// External Player
|
|
|
|
Intent intent = new Intent();
|
|
|
|
try {
|
|
|
|
intent.setAction(Intent.ACTION_VIEW)
|
|
|
|
.setDataAndType(Uri.parse(selectedVideoStream.url), MediaFormat.getMimeById(selectedVideoStream.format))
|
|
|
|
.putExtra(Intent.EXTRA_TITLE, info.title)
|
|
|
|
.putExtra("title", info.title);
|
|
|
|
this.startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2017-04-09 19:34:00 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
2017-03-31 20:15:26 +02:00
|
|
|
builder.setMessage(R.string.no_player_found)
|
|
|
|
.setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
Intent intent = new Intent()
|
|
|
|
.setAction(Intent.ACTION_VIEW)
|
|
|
|
.setData(Uri.parse(getString(R.string.fdroid_vlc_url)));
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
} else {
|
2017-04-12 08:07:15 +02:00
|
|
|
Intent mIntent;
|
2017-04-09 19:34:00 +02:00
|
|
|
boolean useOldPlayer = PreferenceManager.getDefaultSharedPreferences(activity)
|
2017-03-31 20:15:26 +02:00
|
|
|
.getBoolean(getString(R.string.use_old_player_key), false)
|
|
|
|
|| (Build.VERSION.SDK_INT < 16);
|
|
|
|
if (!useOldPlayer) {
|
|
|
|
// ExoPlayer
|
2017-04-17 06:19:53 +02:00
|
|
|
mIntent = NavigationHelper.getOpenVideoPlayerIntent(activity, MainVideoPlayer.class, info, actionBarHandler.getSelectedVideoStream());
|
2017-03-31 20:15:26 +02:00
|
|
|
} else {
|
|
|
|
// Internal Player
|
2017-04-12 08:07:15 +02:00
|
|
|
mIntent = new Intent(activity, PlayVideoActivity.class)
|
2017-03-31 20:15:26 +02:00
|
|
|
.putExtra(PlayVideoActivity.VIDEO_TITLE, info.title)
|
|
|
|
.putExtra(PlayVideoActivity.STREAM_URL, selectedVideoStream.url)
|
|
|
|
.putExtra(PlayVideoActivity.VIDEO_URL, info.webpage_url)
|
|
|
|
.putExtra(PlayVideoActivity.START_POSITION, info.start_position);
|
|
|
|
}
|
2017-04-12 08:07:15 +02:00
|
|
|
startActivity(mIntent);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private View getSeparatorView() {
|
2017-04-09 19:34:00 +02:00
|
|
|
View separator = new View(activity);
|
2017-03-31 20:15:26 +02:00
|
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
|
|
|
|
int m8 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
|
|
|
|
int m5 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics());
|
|
|
|
params.setMargins(m8, m5, m8, m5);
|
|
|
|
separator.setLayoutParams(params);
|
|
|
|
|
|
|
|
TypedValue typedValue = new TypedValue();
|
2017-04-09 19:34:00 +02:00
|
|
|
activity.getTheme().resolveAttribute(R.attr.separatorColor, typedValue, true);
|
2017-03-31 20:15:26 +02:00
|
|
|
separator.setBackgroundColor(typedValue.data);
|
|
|
|
return separator;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setHeightThumbnail() {
|
|
|
|
boolean isPortrait = getResources().getDisplayMetrics().heightPixels > getResources().getDisplayMetrics().widthPixels;
|
|
|
|
int height = isPortrait ? (int) (getResources().getDisplayMetrics().widthPixels / (16.0f / 9.0f))
|
|
|
|
: (int) (getResources().getDisplayMetrics().heightPixels / 2f);
|
|
|
|
thumbnailImageView.setScaleType(isPortrait ? ImageView.ScaleType.CENTER_CROP : ImageView.ScaleType.FIT_CENTER);
|
|
|
|
thumbnailImageView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, height));
|
|
|
|
thumbnailImageView.setMinimumHeight(height);
|
|
|
|
thumbnailBackgroundButton.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, height));
|
|
|
|
thumbnailBackgroundButton.setMinimumHeight(height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Animate the view
|
|
|
|
*
|
|
|
|
* @param view view that will be animated
|
|
|
|
* @param enterOrExit true to enter, false to exit
|
|
|
|
* @param duration how long the animation will take, in milliseconds
|
|
|
|
* @param execOnEnd runnable that will be executed when the animation ends
|
|
|
|
*/
|
|
|
|
public void animateView(final View view, final boolean enterOrExit, long duration, final Runnable execOnEnd) {
|
|
|
|
if (view.getVisibility() == View.VISIBLE && enterOrExit) {
|
|
|
|
view.animate().setListener(null).cancel();
|
|
|
|
view.setVisibility(View.VISIBLE);
|
|
|
|
view.setAlpha(1f);
|
|
|
|
if (execOnEnd != null) execOnEnd.run();
|
|
|
|
return;
|
|
|
|
} else if ((view.getVisibility() == View.GONE || view.getVisibility() == View.INVISIBLE) && !enterOrExit) {
|
|
|
|
view.animate().setListener(null).cancel();
|
|
|
|
view.setVisibility(View.GONE);
|
|
|
|
view.setAlpha(0f);
|
|
|
|
if (execOnEnd != null) execOnEnd.run();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
view.animate().setListener(null).cancel();
|
|
|
|
view.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
if (enterOrExit) {
|
|
|
|
view.animate().alpha(1f).setDuration(duration)
|
|
|
|
.setListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (execOnEnd != null) execOnEnd.run();
|
|
|
|
}
|
|
|
|
}).start();
|
2015-09-04 02:15:03 +02:00
|
|
|
} else {
|
2017-03-31 20:15:26 +02:00
|
|
|
view.animate().alpha(0f)
|
|
|
|
.setDuration(duration)
|
|
|
|
.setListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
view.setVisibility(View.GONE);
|
|
|
|
if (execOnEnd != null) execOnEnd.run();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.start();
|
2015-09-04 02:15:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OnStreamInfoReceivedListener callbacks
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2017-02-18 21:59:48 +01:00
|
|
|
@Override
|
2017-03-31 20:15:26 +02:00
|
|
|
public void onReceive(StreamInfo info) {
|
2017-04-09 19:34:00 +02:00
|
|
|
if (info == null || isRemoving() || !isVisible()) return;
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
currentStreamInfo = info;
|
2017-03-31 20:15:26 +02:00
|
|
|
loadingProgressBar.setVisibility(View.GONE);
|
2017-04-09 19:34:00 +02:00
|
|
|
animateView(thumbnailPlayButton, true, 200, null);
|
2017-03-31 20:15:26 +02:00
|
|
|
parallaxScrollRootView.scrollTo(0, 0);
|
|
|
|
|
|
|
|
// Since newpipe is designed to work even if certain information is not available,
|
|
|
|
// the UI has to react on missing information.
|
2017-04-12 08:07:15 +02:00
|
|
|
videoTitle = info.title;
|
2017-03-31 20:15:26 +02:00
|
|
|
videoTitleTextView.setText(info.title);
|
|
|
|
if (!info.uploader.isEmpty()) uploaderTextView.setText(info.uploader);
|
|
|
|
uploaderTextView.setVisibility(!info.uploader.isEmpty() ? View.VISIBLE : View.GONE);
|
|
|
|
uploaderButton.setVisibility(!info.channel_url.isEmpty() ? View.VISIBLE : View.GONE);
|
2017-04-09 19:34:00 +02:00
|
|
|
uploaderThumb.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.buddy));
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (info.view_count >= 0) videoCountView.setText(Localization.localizeViewCount(info.view_count, activity));
|
2017-03-31 20:15:26 +02:00
|
|
|
videoCountView.setVisibility(info.view_count >= 0 ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
if (info.dislike_count == -1 && info.like_count == -1) {
|
|
|
|
thumbsDownImageView.setVisibility(View.VISIBLE);
|
|
|
|
thumbsUpImageView.setVisibility(View.VISIBLE);
|
|
|
|
thumbsUpTextView.setVisibility(View.GONE);
|
|
|
|
thumbsDownTextView.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
thumbsDisabledTextView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
thumbsDisabledTextView.setVisibility(View.GONE);
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (info.dislike_count >= 0) thumbsDownTextView.setText(Localization.localizeNumber(info.dislike_count, activity));
|
2017-03-31 20:15:26 +02:00
|
|
|
thumbsDownTextView.setVisibility(info.dislike_count >= 0 ? View.VISIBLE : View.GONE);
|
|
|
|
thumbsDownImageView.setVisibility(info.dislike_count >= 0 ? View.VISIBLE : View.GONE);
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (info.like_count >= 0) thumbsUpTextView.setText(Localization.localizeNumber(info.like_count, activity));
|
2017-03-31 20:15:26 +02:00
|
|
|
thumbsUpTextView.setVisibility(info.like_count >= 0 ? View.VISIBLE : View.GONE);
|
|
|
|
thumbsUpImageView.setVisibility(info.like_count >= 0 ? View.VISIBLE : View.GONE);
|
2017-02-18 21:59:48 +01:00
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (!info.upload_date.isEmpty()) videoUploadDateView.setText(Localization.localizeDate(info.upload_date, activity));
|
2017-03-31 20:15:26 +02:00
|
|
|
videoUploadDateView.setVisibility(!info.upload_date.isEmpty() ? View.VISIBLE : View.GONE);
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (!info.description.isEmpty()) { //noinspection deprecation
|
|
|
|
videoDescriptionView.setText(Build.VERSION.SDK_INT >= 24 ? Html.fromHtml(info.description, 0) : Html.fromHtml(info.description));
|
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
videoDescriptionView.setVisibility(!info.description.isEmpty() ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
videoDescriptionRootLayout.setVisibility(View.GONE);
|
|
|
|
videoTitleToggleArrow.setImageResource(R.drawable.arrow_down);
|
2017-04-09 19:34:00 +02:00
|
|
|
videoTitleToggleArrow.setVisibility(View.VISIBLE);
|
|
|
|
videoTitleRoot.setClickable(true);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
setupActionBarHandler(info);
|
|
|
|
initRelatedVideos(info);
|
|
|
|
initThumbnailViews(info);
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
setTitleToUrl(info.webpage_url, info.title);
|
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
animateView(contentRootLayout, true, 200, null);
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (autoPlayEnabled) {
|
|
|
|
playVideo(info);
|
|
|
|
// Only auto play in the first open
|
|
|
|
autoPlayEnabled = false;
|
|
|
|
}
|
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
isLoading.set(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int messageId) {
|
2017-04-09 19:34:00 +02:00
|
|
|
Toast.makeText(activity, messageId, Toast.LENGTH_LONG).show();
|
2017-03-31 20:15:26 +02:00
|
|
|
loadingProgressBar.setVisibility(View.GONE);
|
2017-04-09 19:34:00 +02:00
|
|
|
videoTitleTextView.setText(getString(messageId));
|
|
|
|
thumbnailImageView.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.not_available_monkey));
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReCaptchaException() {
|
2017-04-09 19:34:00 +02:00
|
|
|
Toast.makeText(activity, R.string.recaptcha_request_toast, Toast.LENGTH_LONG).show();
|
2017-03-31 20:15:26 +02:00
|
|
|
// Starting ReCaptcha Challenge Activity
|
2017-04-09 19:34:00 +02:00
|
|
|
startActivityForResult(new Intent(activity, ReCaptchaActivity.class), ReCaptchaActivity.RECAPTCHA_REQUEST);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockedByGemaError() {
|
|
|
|
loadingProgressBar.setVisibility(View.GONE);
|
2017-04-09 19:34:00 +02:00
|
|
|
thumbnailImageView.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.gruese_die_gema));
|
2017-03-31 20:15:26 +02:00
|
|
|
thumbnailBackgroundButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse(getString(R.string.c3s_url)));
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
Toast.makeText(activity, R.string.blocked_by_gema, Toast.LENGTH_LONG).show();
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContentErrorWithMessage(int messageId) {
|
|
|
|
loadingProgressBar.setVisibility(View.GONE);
|
2017-04-09 19:34:00 +02:00
|
|
|
thumbnailImageView.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.not_available_monkey));
|
|
|
|
Toast.makeText(activity, messageId, Toast.LENGTH_LONG).show();
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContentError() {
|
|
|
|
loadingProgressBar.setVisibility(View.GONE);
|
2017-04-09 19:34:00 +02:00
|
|
|
thumbnailImageView.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.not_available_monkey));
|
|
|
|
Toast.makeText(activity, R.string.content_not_available, Toast.LENGTH_LONG).show();
|
2017-02-18 21:59:48 +01:00
|
|
|
}
|
2017-04-12 08:07:15 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUnrecoverableError(Exception exception) {
|
|
|
|
activity.finish();
|
|
|
|
}
|
2015-09-04 02:15:03 +02:00
|
|
|
}
|