2017-04-09 19:34:00 +02:00
|
|
|
package org.schabi.newpipe.fragments.detail;
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
import android.app.Activity;
|
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;
|
|
|
|
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-28 05:58:50 +02:00
|
|
|
import android.support.annotation.FloatRange;
|
2017-04-26 21:32:04 +02:00
|
|
|
import android.support.annotation.NonNull;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.support.v4.content.ContextCompat;
|
2017-04-28 05:58:50 +02:00
|
|
|
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
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;
|
|
|
|
import android.text.Html;
|
2017-04-26 21:32:04 +02:00
|
|
|
import android.text.TextUtils;
|
2017-03-31 20:15:26 +02:00
|
|
|
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-05-01 07:23:50 +02:00
|
|
|
import android.view.Gravity;
|
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;
|
2017-04-26 21:32:04 +02:00
|
|
|
import android.widget.ImageButton;
|
2017-03-31 20:15:26 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.RelativeLayout;
|
2017-04-26 21:32:04 +02:00
|
|
|
import android.widget.Spinner;
|
2017-03-31 20:15:26 +02:00
|
|
|
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.assist.FailReason;
|
|
|
|
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.ImageErrorLoadingListener;
|
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-26 21:32:04 +02:00
|
|
|
import org.schabi.newpipe.fragments.BaseFragment;
|
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-05-08 15:33:26 +02:00
|
|
|
import org.schabi.newpipe.util.Constants;
|
|
|
|
import org.schabi.newpipe.util.Localization;
|
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-05-08 15:33:26 +02:00
|
|
|
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
public class VideoDetailFragment extends BaseFragment implements StreamExtractorWorker.OnStreamInfoReceivedListener, SharedPreferences.OnSharedPreferenceChangeListener, View.OnClickListener {
|
2017-04-09 19:34:00 +02:00
|
|
|
private final String TAG = "VideoDetailFragment@" + Integer.toHexString(hashCode());
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
// Amount of videos to show on start
|
|
|
|
private static final int INITIAL_RELATED_VIDEOS = 8;
|
|
|
|
|
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 STACK_KEY = "stack_key";
|
2017-04-26 21:32:04 +02:00
|
|
|
private static final String INFO_KEY = "info_key";
|
|
|
|
private static final String WAS_RELATED_EXPANDED_KEY = "was_related_expanded_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-26 21:32:04 +02:00
|
|
|
private String thousand;
|
|
|
|
private String million;
|
|
|
|
private String billion;
|
|
|
|
|
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 static final int RELATED_STREAMS_UPDATE_FLAG = 0x1;
|
|
|
|
private static final int RESOLUTIONS_MENU_UPDATE_FLAG = 0x2;
|
2017-05-09 03:23:27 +02:00
|
|
|
private static final int TOOLBAR_ITEMS_UPDATE_FLAG = 0x4;
|
2017-04-12 08:07:15 +02:00
|
|
|
private int updateFlags = 0;
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
private boolean autoPlayEnabled;
|
|
|
|
private boolean showRelatedStreams;
|
2017-04-26 21:32:04 +02:00
|
|
|
private boolean wasRelatedStreamsExpanded = false;
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Views
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
private Spinner spinnerToolbar;
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
private ParallaxScrollView parallaxScrollRootView;
|
2017-04-26 21:32:04 +02:00
|
|
|
private RelativeLayout contentRootLayoutHiding;
|
2017-03-31 20:15:26 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
private TextView detailControlsBackground;
|
|
|
|
private TextView detailControlsPopup;
|
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
private RelativeLayout videoDescriptionRootLayout;
|
|
|
|
private TextView videoUploadDateView;
|
|
|
|
private TextView videoDescriptionView;
|
|
|
|
|
2017-04-28 05:58:50 +02:00
|
|
|
private View uploaderRootLayout;
|
2017-03-31 20:15:26 +02:00
|
|
|
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-26 21:32:04 +02:00
|
|
|
private ImageButton relatedStreamExpandButton;
|
2017-03-31 20:15:26 +02:00
|
|
|
|
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-04-26 21:32:04 +02:00
|
|
|
|
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
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2015-09-04 02:15:03 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2017-04-26 21:32:04 +02:00
|
|
|
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (savedInstanceState != null) {
|
2017-05-08 15:33:26 +02:00
|
|
|
videoTitle = savedInstanceState.getString(Constants.KEY_TITLE);
|
|
|
|
videoUrl = savedInstanceState.getString(Constants.KEY_URL);
|
|
|
|
serviceId = savedInstanceState.getInt(Constants.KEY_SERVICE_ID, 0);
|
2017-04-26 21:32:04 +02:00
|
|
|
wasRelatedStreamsExpanded = savedInstanceState.getBoolean(WAS_RELATED_EXPANDED_KEY, false);
|
2017-04-09 19:34:00 +02:00
|
|
|
Serializable serializable = savedInstanceState.getSerializable(STACK_KEY);
|
|
|
|
if (serializable instanceof Stack) {
|
|
|
|
//noinspection unchecked
|
|
|
|
Stack<StackItem> list = (Stack<StackItem>) serializable;
|
|
|
|
stack.clear();
|
|
|
|
stack.addAll(list);
|
|
|
|
}
|
2017-04-26 21:32:04 +02:00
|
|
|
|
|
|
|
Serializable serial = savedInstanceState.getSerializable(INFO_KEY);
|
|
|
|
if (serial instanceof StreamInfo) currentStreamInfo = (StreamInfo) serial;
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
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);
|
2017-04-26 21:32:04 +02:00
|
|
|
|
|
|
|
thousand = getString(R.string.short_thousand);
|
|
|
|
million = getString(R.string.short_million);
|
|
|
|
billion = getString(R.string.short_billion);
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
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) {
|
2017-04-26 21:32:04 +02:00
|
|
|
if (DEBUG) Log.d(TAG, "onCreateView() called with: inflater = [" + inflater + "], container = [" + container + "], savedInstanceState = [" + savedInstanceState + "]");
|
2017-04-09 19:34:00 +02:00
|
|
|
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) {
|
2017-04-26 21:32:04 +02:00
|
|
|
super.onViewCreated(rootView, savedInstanceState);
|
|
|
|
if (currentStreamInfo == null) selectAndLoadVideo(serviceId, videoUrl, videoTitle);
|
2017-04-28 05:58:50 +02:00
|
|
|
else prepareAndLoad(currentStreamInfo, false);
|
2017-04-26 21:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
// Currently only used for enable/disable related videos
|
|
|
|
// but can be extended for other live settings changes
|
|
|
|
if (updateFlags != 0) {
|
2017-04-28 06:07:54 +02:00
|
|
|
if (!isLoading.get() && currentStreamInfo != null) {
|
2017-04-26 21:32:04 +02:00
|
|
|
if ((updateFlags & RELATED_STREAMS_UPDATE_FLAG) != 0) initRelatedVideos(currentStreamInfo);
|
|
|
|
if ((updateFlags & RESOLUTIONS_MENU_UPDATE_FLAG) != 0) setupActionBarHandler(currentStreamInfo);
|
|
|
|
}
|
2017-05-09 03:23:27 +02:00
|
|
|
|
|
|
|
if ((updateFlags & TOOLBAR_ITEMS_UPDATE_FLAG) != 0 && actionBarHandler != null) actionBarHandler.updateItemsVisibility();
|
2017-04-26 21:32:04 +02:00
|
|
|
updateFlags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if it was loading when the activity was stopped/paused,
|
|
|
|
// because when this happen, the curExtractorWorker is cancelled
|
|
|
|
if (wasLoading.getAndSet(false)) selectAndLoadVideo(serviceId, videoUrl, videoTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
wasLoading.set(curExtractorWorker != null && curExtractorWorker.isRunning());
|
|
|
|
if (curExtractorWorker != null && curExtractorWorker.isRunning()) curExtractorWorker.cancel();
|
|
|
|
StreamInfoCache.getInstance().removeOldEntries();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(activity).unregisterOnSharedPreferenceChangeListener(this);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-09 19:34:00 +02:00
|
|
|
public void onDestroyView() {
|
2017-04-26 21:32:04 +02:00
|
|
|
if (DEBUG) Log.d(TAG, "onDestroyView() called");
|
2017-04-09 19:34:00 +02:00
|
|
|
thumbnailImageView.setImageBitmap(null);
|
|
|
|
relatedStreamsView.removeAllViews();
|
2017-04-26 21:32:04 +02:00
|
|
|
spinnerToolbar.setOnItemSelectedListener(null);
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
spinnerToolbar = null;
|
2017-04-09 19:34:00 +02:00
|
|
|
|
|
|
|
parallaxScrollRootView = null;
|
2017-04-26 21:32:04 +02:00
|
|
|
contentRootLayoutHiding = null;
|
2017-04-09 19:34:00 +02:00
|
|
|
|
|
|
|
thumbnailBackgroundButton = null;
|
|
|
|
thumbnailImageView = null;
|
|
|
|
thumbnailPlayButton = null;
|
|
|
|
|
|
|
|
videoTitleRoot = null;
|
|
|
|
videoTitleTextView = null;
|
|
|
|
videoTitleToggleArrow = null;
|
|
|
|
videoCountView = null;
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
detailControlsBackground = null;
|
|
|
|
detailControlsPopup = null;
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
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;
|
2017-04-26 21:32:04 +02:00
|
|
|
relatedStreamExpandButton = null;
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
super.onDestroyView();
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
2017-04-26 21:32:04 +02:00
|
|
|
if (DEBUG) Log.d(TAG, "onSaveInstanceState() called with: outState = [" + outState + "]");
|
2017-05-08 15:33:26 +02:00
|
|
|
outState.putString(Constants.KEY_URL, videoUrl);
|
|
|
|
outState.putString(Constants.KEY_TITLE, videoTitle);
|
|
|
|
outState.putInt(Constants.KEY_SERVICE_ID, serviceId);
|
2017-04-09 19:34:00 +02:00
|
|
|
outState.putSerializable(STACK_KEY, stack);
|
2017-04-26 21:32:04 +02:00
|
|
|
|
|
|
|
int nextCount = currentStreamInfo != null && currentStreamInfo.next_video != null ? 2 : 0;
|
|
|
|
if (relatedStreamsView != null && relatedStreamsView.getChildCount() > INITIAL_RELATED_VIDEOS + nextCount) {
|
|
|
|
outState.putSerializable(WAS_RELATED_EXPANDED_KEY, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isLoading.get() && (curExtractorWorker == null || !curExtractorWorker.isRunning())) {
|
|
|
|
outState.putSerializable(INFO_KEY, currentStreamInfo);
|
|
|
|
}
|
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))
|
2017-05-15 05:57:57 +02:00
|
|
|
|| key.equals(getString(R.string.show_higher_resolutions_key))
|
|
|
|
|| key.equals(getString(R.string.use_external_video_player_key))) {
|
2017-04-12 08:07:15 +02:00
|
|
|
updateFlags |= RESOLUTIONS_MENU_UPDATE_FLAG;
|
2017-05-09 03:23:27 +02:00
|
|
|
} else if (key.equals(getString(R.string.show_play_with_kodi_key))) {
|
|
|
|
updateFlags |= TOOLBAR_ITEMS_UPDATE_FLAG;
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OnClick
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (isLoading.get() || currentStreamInfo == null) return;
|
|
|
|
|
|
|
|
switch (v.getId()) {
|
|
|
|
case R.id.detail_controls_background:
|
|
|
|
openInBackground();
|
|
|
|
break;
|
|
|
|
case R.id.detail_controls_popup:
|
|
|
|
openInPopup();
|
|
|
|
break;
|
|
|
|
case R.id.detail_uploader_button:
|
|
|
|
NavigationHelper.openChannel(onItemSelectedListener, currentStreamInfo.service_id, currentStreamInfo.channel_url, currentStreamInfo.uploader);
|
|
|
|
break;
|
|
|
|
case R.id.detail_thumbnail_background_button:
|
|
|
|
playVideo(currentStreamInfo);
|
|
|
|
break;
|
|
|
|
case R.id.detail_title_root_layout:
|
|
|
|
toggleTitleAndDescription();
|
|
|
|
break;
|
|
|
|
case R.id.detail_related_streams_expand:
|
|
|
|
toggleExpandRelatedVideos(currentStreamInfo);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void reloadContent() {
|
|
|
|
if (DEBUG) Log.d(TAG, "reloadContent() called");
|
|
|
|
if (currentStreamInfo != null) StreamInfoCache.getInstance().removeInfo(currentStreamInfo);
|
|
|
|
currentStreamInfo = null;
|
|
|
|
for (StackItem stackItem : stack) if (stackItem.getUrl().equals(videoUrl)) stackItem.setInfo(null);
|
2017-04-28 05:58:50 +02:00
|
|
|
prepareAndLoad(null, true);
|
2017-04-26 21:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void openInBackground() {
|
|
|
|
if (isLoading.get()) return;
|
|
|
|
|
|
|
|
boolean useExternalAudioPlayer = PreferenceManager.getDefaultSharedPreferences(activity)
|
|
|
|
.getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
|
|
|
|
Intent intent;
|
|
|
|
AudioStream audioStream = currentStreamInfo.audio_streams.get(Utils.getPreferredAudioFormat(activity, currentStreamInfo.audio_streams));
|
|
|
|
if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) {
|
|
|
|
activity.startService(NavigationHelper.getOpenBackgroundPlayerIntent(activity, currentStreamInfo, audioStream));
|
|
|
|
Toast.makeText(activity, R.string.background_player_playing_toast, Toast.LENGTH_SHORT).show();
|
|
|
|
} 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, currentStreamInfo.title);
|
|
|
|
intent.putExtra("title", currentStreamInfo.title);
|
|
|
|
// HERE !!!
|
|
|
|
activity.startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
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);
|
|
|
|
intent.setData(Uri.parse(activity.getString(R.string.fdroid_vlc_url)));
|
|
|
|
activity.startActivity(intent);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openInPopup() {
|
|
|
|
if (isLoading.get()) return;
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !PermissionHelper.checkSystemAlertWindowPermission(activity)) {
|
2017-05-01 07:23:50 +02:00
|
|
|
Toast toast = Toast.makeText(activity, R.string.msg_popup_permission, Toast.LENGTH_LONG);
|
|
|
|
TextView messageView = (TextView) toast.getView().findViewById(android.R.id.message);
|
|
|
|
if (messageView != null) messageView.setGravity(Gravity.CENTER);
|
|
|
|
toast.show();
|
2017-04-26 21:32:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Toast.makeText(activity, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show();
|
|
|
|
Intent mIntent = NavigationHelper.getOpenVideoPlayerIntent(activity, PopupVideoPlayer.class, currentStreamInfo, actionBarHandler.getSelectedVideoStream());
|
|
|
|
activity.startService(mIntent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void toggleTitleAndDescription() {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void toggleExpandRelatedVideos(StreamInfo info) {
|
|
|
|
if (DEBUG) Log.d(TAG, "toggleExpandRelatedVideos() called with: info = [" + info + "]");
|
|
|
|
if (!showRelatedStreams) return;
|
|
|
|
|
|
|
|
int nextCount = info.next_video != null ? 2 : 0;
|
|
|
|
int initialCount = INITIAL_RELATED_VIDEOS + nextCount;
|
|
|
|
|
|
|
|
if (relatedStreamsView.getChildCount() > initialCount) {
|
|
|
|
relatedStreamsView.removeViews(initialCount, relatedStreamsView.getChildCount() - (initialCount));
|
|
|
|
relatedStreamExpandButton.setImageDrawable(ContextCompat.getDrawable(activity, getResourceIdFromAttr(R.attr.expand)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Log.d(TAG, "toggleExpandRelatedVideos() called with: info = [" + info + "], from = [" + INITIAL_RELATED_VIDEOS + "]");
|
|
|
|
for (int i = INITIAL_RELATED_VIDEOS; i < info.related_streams.size(); i++) {
|
|
|
|
InfoItem item = info.related_streams.get(i);
|
|
|
|
//Log.d(TAG, "i = " + i);
|
|
|
|
relatedStreamsView.addView(infoItemBuilder.buildView(relatedStreamsView, item));
|
|
|
|
}
|
|
|
|
relatedStreamExpandButton.setImageDrawable(ContextCompat.getDrawable(activity, getResourceIdFromAttr(R.attr.collapse)));
|
|
|
|
}
|
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Init
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
protected void initViews(View rootView, Bundle savedInstanceState) {
|
|
|
|
super.initViews(rootView, savedInstanceState);
|
|
|
|
|
|
|
|
spinnerToolbar = (Spinner) toolbar.findViewById(R.id.toolbar_spinner);
|
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);
|
2017-04-26 21:32:04 +02:00
|
|
|
thumbnailBackgroundButton = (Button) rootView.findViewById(R.id.detail_thumbnail_background_button);
|
2017-04-09 19:34:00 +02:00
|
|
|
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-26 21:32:04 +02:00
|
|
|
contentRootLayoutHiding = (RelativeLayout) rootView.findViewById(R.id.detail_content_root_hiding);
|
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-26 21:32:04 +02:00
|
|
|
detailControlsBackground = (TextView) rootView.findViewById(R.id.detail_controls_background);
|
|
|
|
detailControlsPopup = (TextView) rootView.findViewById(R.id.detail_controls_popup);
|
|
|
|
|
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-28 05:58:50 +02:00
|
|
|
uploaderRootLayout = rootView.findViewById(R.id.detail_uploader_root_layout);
|
2017-04-09 19:34:00 +02:00
|
|
|
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-04-26 21:32:04 +02:00
|
|
|
relatedStreamExpandButton = ((ImageButton) rootView.findViewById(R.id.detail_related_streams_expand));
|
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();
|
|
|
|
}
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
protected void initListeners() {
|
|
|
|
super.initListeners();
|
2017-03-31 20:15:26 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
videoTitleRoot.setOnClickListener(this);
|
|
|
|
uploaderButton.setOnClickListener(this);
|
|
|
|
thumbnailBackgroundButton.setOnClickListener(this);
|
|
|
|
detailControlsBackground.setOnClickListener(this);
|
|
|
|
detailControlsPopup.setOnClickListener(this);
|
|
|
|
relatedStreamExpandButton.setOnClickListener(this);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initThumbnailViews(StreamInfo info) {
|
|
|
|
if (info.thumbnail_url != null && !info.thumbnail_url.isEmpty()) {
|
2017-04-26 21:32:04 +02:00
|
|
|
imageLoader.displayImage(info.thumbnail_url, thumbnailImageView, displayImageOptions, new SimpleImageLoadingListener() {
|
|
|
|
@Override
|
|
|
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
|
|
|
ErrorActivity.reportError(activity, failReason.getCause(), null, activity.findViewById(android.R.id.content), ErrorActivity.ErrorInfo.make(ErrorActivity.LOAD_IMAGE, NewPipe.getNameOfService(currentStreamInfo.service_id), imageUri, R.string.could_not_load_thumbnails));
|
|
|
|
}
|
|
|
|
});
|
2017-03-31 20:15:26 +02:00
|
|
|
} else thumbnailImageView.setImageResource(R.drawable.dummy_thumbnail_dark);
|
|
|
|
|
|
|
|
if (info.uploader_thumbnail_url != null && !info.uploader_thumbnail_url.isEmpty()) {
|
2017-04-26 21:32:04 +02:00
|
|
|
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) {
|
2017-04-26 21:32:04 +02:00
|
|
|
//long first = System.nanoTime(), each;
|
|
|
|
int to = info.related_streams.size() >= INITIAL_RELATED_VIDEOS ? INITIAL_RELATED_VIDEOS : info.related_streams.size();
|
|
|
|
for (int i = 0; i < to; i++) {
|
|
|
|
InfoItem item = info.related_streams.get(i);
|
|
|
|
//each = System.nanoTime();
|
2017-03-31 20:15:26 +02:00
|
|
|
relatedStreamsView.addView(infoItemBuilder.buildView(relatedStreamsView, item));
|
2017-04-26 21:32:04 +02:00
|
|
|
//if (DEBUG) Log.d(TAG, "each took " + ((System.nanoTime() - each) / 1000000L) + "ms");
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
2017-04-26 21:32:04 +02:00
|
|
|
//if (DEBUG) Log.d(TAG, "Total time " + ((System.nanoTime() - first) / 1000000L) + "ms");
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
relatedStreamRootLayout.setVisibility(View.VISIBLE);
|
2017-04-26 21:32:04 +02:00
|
|
|
relatedStreamExpandButton.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
relatedStreamExpandButton.setImageDrawable(ContextCompat.getDrawable(activity, getResourceIdFromAttr(R.attr.expand)));
|
|
|
|
} else {
|
|
|
|
if (info.next_video == null) relatedStreamRootLayout.setVisibility(View.GONE);
|
|
|
|
relatedStreamExpandButton.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);
|
|
|
|
ActionBar supportActionBar = activity.getSupportActionBar();
|
|
|
|
if (supportActionBar != null) {
|
|
|
|
supportActionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
supportActionBar.setDisplayShowTitleEnabled(false);
|
|
|
|
}
|
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-12 08:07:15 +02:00
|
|
|
sortedStreamVideosList = Utils.getSortedStreamVideosList(activity, info.video_streams, info.video_only_streams, false);
|
2017-04-26 21:32:04 +02:00
|
|
|
actionBarHandler.setupStreamList(sortedStreamVideosList, spinnerToolbar);
|
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.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 {
|
2017-05-15 05:57:57 +02:00
|
|
|
DownloadDialog downloadDialog = DownloadDialog.newInstance(info, sortedStreamVideosList, selectedStreamId);
|
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-05-15 05:57:57 +02:00
|
|
|
Toast.makeText(activity, R.string.could_not_setup_download_menu, Toast.LENGTH_LONG).show();
|
2017-03-31 20:15:26 +02:00
|
|
|
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) {
|
2017-04-26 21:32:04 +02:00
|
|
|
if (DEBUG) Log.d(TAG, "pushToStack() called with: videoUrl = [" + videoUrl + "], videoTitle = [" + videoTitle + "]");
|
2017-04-09 19:34:00 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
public void setStreamInfoToUrl(String videoUrl, StreamInfo info) {
|
|
|
|
if (info != null) {
|
|
|
|
for (StackItem stackItem : stack) {
|
|
|
|
if (stackItem.getUrl().equals(videoUrl)) stackItem.setInfo(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
public boolean onActivityBackPressed() {
|
2017-04-26 21:32:04 +02:00
|
|
|
if (DEBUG) Log.d(TAG, "onActivityBackPressed() called");
|
2017-04-09 19:34:00 +02:00
|
|
|
// 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();
|
2017-04-26 21:32:04 +02:00
|
|
|
|
|
|
|
if (peek.getInfo() != null) selectAndHandleInfo(peek.getInfo());
|
|
|
|
else selectAndLoadVideo(0, peek.getUrl(), !TextUtils.isEmpty(peek.getTitle()) ? peek.getTitle() : "");
|
2017-04-09 19:34:00 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
public void selectAndHandleInfo(StreamInfo info) {
|
2017-04-28 05:58:50 +02:00
|
|
|
selectAndHandleInfo(info, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void selectAndHandleInfo(StreamInfo info, boolean scrollToTop) {
|
|
|
|
if (DEBUG) Log.d(TAG, "selectAndHandleInfo() called with: info = [" + info + "], scrollToTop = [" + scrollToTop + "]");
|
2017-04-26 21:32:04 +02:00
|
|
|
selectVideo(info.service_id, info.webpage_url, info.title);
|
2017-04-28 05:58:50 +02:00
|
|
|
prepareAndLoad(info, scrollToTop);
|
2017-04-26 21:32:04 +02:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
public void selectAndLoadVideo(int serviceId, String videoUrl, String videoTitle) {
|
2017-04-28 05:58:50 +02:00
|
|
|
selectAndLoadVideo(serviceId, videoUrl, videoTitle, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void selectAndLoadVideo(int serviceId, String videoUrl, String videoTitle, boolean scrollToTop) {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "selectAndLoadVideo() called with: serviceId = [" + serviceId + "], videoUrl = [" + videoUrl + "], videoTitle = [" + videoTitle + "], scrollToTop = [" + scrollToTop + "]");
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
selectVideo(serviceId, videoUrl, videoTitle);
|
2017-04-28 05:58:50 +02:00
|
|
|
prepareAndLoad(null, scrollToTop);
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
/**
|
|
|
|
* Prepare the UI for loading the info.</br>
|
|
|
|
* If the argument info is not null, it'll be passed in {@link #handleStreamInfo(StreamInfo, boolean)}.</br>
|
|
|
|
* If it is, check if the cache contains the info already.</br>
|
|
|
|
* If the cache doesn't have the info, load from the network.
|
|
|
|
*
|
2017-05-08 15:33:26 +02:00
|
|
|
* @param info info to prepare and load, can be null
|
2017-04-28 05:58:50 +02:00
|
|
|
* @param scrollToTop whether or not scroll the scrollView to y = 0
|
2017-04-26 21:32:04 +02:00
|
|
|
*/
|
2017-04-28 05:58:50 +02:00
|
|
|
public void prepareAndLoad(StreamInfo info, boolean scrollToTop) {
|
2017-04-26 21:32:04 +02:00
|
|
|
if (DEBUG) Log.d(TAG, "prepareAndLoad() called with: info = [" + info + "]");
|
2017-04-12 08:07:15 +02:00
|
|
|
isLoading.set(true);
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
// Only try to get from the cache if the passed info IS null
|
|
|
|
if (info == null && StreamInfoCache.getInstance().hasKey(videoUrl)) {
|
|
|
|
info = StreamInfoCache.getInstance().getFromKey(videoUrl);
|
2017-04-09 19:34:00 +02:00
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
if (info != null) selectVideo(info.service_id, info.webpage_url, info.title);
|
|
|
|
pushToStack(videoUrl, videoTitle);
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
if (curExtractorWorker != null && curExtractorWorker.isRunning()) curExtractorWorker.cancel();
|
|
|
|
animateView(spinnerToolbar, false, 200);
|
|
|
|
animateView(errorPanel, false, 200);
|
2017-04-28 05:58:50 +02:00
|
|
|
|
|
|
|
videoTitleTextView.setText(videoTitle != null ? videoTitle : "");
|
|
|
|
videoTitleTextView.setMaxLines(1);
|
|
|
|
animateView(videoTitleTextView, true, 0);
|
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
videoDescriptionRootLayout.setVisibility(View.GONE);
|
|
|
|
videoTitleToggleArrow.setImageResource(R.drawable.arrow_down);
|
|
|
|
videoTitleToggleArrow.setVisibility(View.GONE);
|
|
|
|
videoTitleRoot.setClickable(false);
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
animateView(thumbnailPlayButton, false, 50);
|
2017-03-31 20:15:26 +02:00
|
|
|
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-26 21:32:04 +02:00
|
|
|
if (info != null) {
|
|
|
|
final StreamInfo infoFinal = info;
|
2017-04-28 05:58:50 +02:00
|
|
|
final boolean greaterThanThreshold = parallaxScrollRootView.getScrollY() >
|
|
|
|
(int) (getResources().getDisplayMetrics().heightPixels * .1f);
|
|
|
|
|
|
|
|
if (scrollToTop) {
|
|
|
|
if (greaterThanThreshold) parallaxScrollRootView.smoothScrollTo(0, 0);
|
|
|
|
else parallaxScrollRootView.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
2017-05-08 15:33:26 +02:00
|
|
|
animateView(contentRootLayoutHiding, false, greaterThanThreshold ? 250 : 0, 0, new Runnable() {
|
2017-04-26 21:32:04 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
handleStreamInfo(infoFinal, false);
|
|
|
|
isLoading.set(false);
|
2017-04-28 05:58:50 +02:00
|
|
|
showContentWithAnimation(greaterThanThreshold ? 120 : 200, 0, .02f);
|
2017-04-26 21:32:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2017-04-28 05:58:50 +02:00
|
|
|
if (scrollToTop) parallaxScrollRootView.smoothScrollTo(0, 0);
|
2017-04-26 21:32:04 +02:00
|
|
|
curExtractorWorker = new StreamExtractorWorker(activity, serviceId, videoUrl, this);
|
|
|
|
curExtractorWorker.start();
|
|
|
|
animateView(loadingProgressBar, true, 200);
|
|
|
|
animateView(contentRootLayoutHiding, false, 200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleStreamInfo(@NonNull StreamInfo info, boolean fromNetwork) {
|
|
|
|
if (DEBUG) Log.d(TAG, "handleStreamInfo() called with: info = [" + info + "]");
|
|
|
|
currentStreamInfo = info;
|
|
|
|
selectVideo(info.service_id, info.webpage_url, info.title);
|
|
|
|
|
|
|
|
loadingProgressBar.setVisibility(View.GONE);
|
|
|
|
animateView(thumbnailPlayButton, true, 200);
|
|
|
|
|
|
|
|
// Since newpipe is designed to work even if certain information is not available,
|
|
|
|
// the UI has to react on missing information.
|
|
|
|
if (fromNetwork) videoTitleTextView.setText(info.title);
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(info.uploader)) uploaderTextView.setText(info.uploader);
|
|
|
|
uploaderTextView.setVisibility(!TextUtils.isEmpty(info.uploader) ? View.VISIBLE : View.GONE);
|
|
|
|
uploaderButton.setVisibility(!TextUtils.isEmpty(info.channel_url) ? View.VISIBLE : View.GONE);
|
|
|
|
uploaderThumb.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.buddy));
|
|
|
|
|
|
|
|
if (info.view_count >= 0) videoCountView.setText(Localization.localizeViewCount(info.view_count, activity));
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (info.dislike_count >= 0) thumbsDownTextView.setText(getShortCount((long) info.dislike_count));
|
|
|
|
thumbsDownTextView.setVisibility(info.dislike_count >= 0 ? View.VISIBLE : View.GONE);
|
|
|
|
thumbsDownImageView.setVisibility(info.dislike_count >= 0 ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
if (info.like_count >= 0) thumbsUpTextView.setText(getShortCount((long) info.like_count));
|
|
|
|
thumbsUpTextView.setVisibility(info.like_count >= 0 ? View.VISIBLE : View.GONE);
|
|
|
|
thumbsUpImageView.setVisibility(info.like_count >= 0 ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(info.upload_date)) videoUploadDateView.setText(Localization.localizeDate(info.upload_date, activity));
|
|
|
|
videoUploadDateView.setVisibility(!TextUtils.isEmpty(info.upload_date) ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(info.description)) { //noinspection deprecation
|
|
|
|
videoDescriptionView.setText(Build.VERSION.SDK_INT >= 24 ? Html.fromHtml(info.description, 0) : Html.fromHtml(info.description));
|
|
|
|
}
|
|
|
|
videoDescriptionView.setVisibility(!TextUtils.isEmpty(info.description) ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
videoDescriptionRootLayout.setVisibility(View.GONE);
|
|
|
|
videoTitleToggleArrow.setImageResource(R.drawable.arrow_down);
|
|
|
|
videoTitleToggleArrow.setVisibility(View.VISIBLE);
|
|
|
|
videoTitleRoot.setClickable(true);
|
|
|
|
|
|
|
|
animateView(spinnerToolbar, true, 500);
|
|
|
|
setupActionBarHandler(info);
|
|
|
|
initThumbnailViews(info);
|
|
|
|
initRelatedVideos(info);
|
|
|
|
if (wasRelatedStreamsExpanded) {
|
|
|
|
toggleExpandRelatedVideos(currentStreamInfo);
|
|
|
|
wasRelatedStreamsExpanded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
setTitleToUrl(info.webpage_url, info.title);
|
|
|
|
setStreamInfoToUrl(info.webpage_url, info);
|
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);
|
2017-04-26 21:32:04 +02:00
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
public String getShortCount(Long viewCount) {
|
|
|
|
if (viewCount >= 1000000000) {
|
|
|
|
return Long.toString(viewCount / 1000000000) + billion;
|
|
|
|
} else if (viewCount >= 1000000) {
|
|
|
|
return Long.toString(viewCount / 1000000) + million;
|
|
|
|
} else if (viewCount >= 1000) {
|
|
|
|
return Long.toString(viewCount / 1000) + thousand;
|
2015-09-04 02:15:03 +02:00
|
|
|
} else {
|
2017-04-26 21:32:04 +02:00
|
|
|
return Long.toString(viewCount);
|
2015-09-04 02:15:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 05:58:50 +02:00
|
|
|
private void showContentWithAnimation(long duration, long delay, @FloatRange(from = 0.0f, to = 1.0f) float translationPercent) {
|
|
|
|
int translationY = (int) (getResources().getDisplayMetrics().heightPixels *
|
|
|
|
(translationPercent > 0.0f ? translationPercent : .12f));
|
|
|
|
|
|
|
|
contentRootLayoutHiding.animate().setListener(null).cancel();
|
|
|
|
contentRootLayoutHiding.setAlpha(0f);
|
|
|
|
contentRootLayoutHiding.setTranslationY(translationY);
|
|
|
|
contentRootLayoutHiding.setVisibility(View.VISIBLE);
|
|
|
|
contentRootLayoutHiding.animate().alpha(1f).translationY(0)
|
|
|
|
.setStartDelay(delay).setDuration(duration).setInterpolator(new FastOutSlowInInterpolator()).start();
|
|
|
|
|
|
|
|
uploaderRootLayout.animate().setListener(null).cancel();
|
|
|
|
uploaderRootLayout.setAlpha(0f);
|
|
|
|
uploaderRootLayout.setTranslationY(translationY);
|
|
|
|
uploaderRootLayout.setVisibility(View.VISIBLE);
|
|
|
|
uploaderRootLayout.animate().alpha(1f).translationY(0)
|
|
|
|
.setStartDelay((long) (duration * .5f) + delay).setDuration(duration).setInterpolator(new FastOutSlowInInterpolator()).start();
|
|
|
|
|
|
|
|
if (showRelatedStreams) {
|
|
|
|
relatedStreamRootLayout.animate().setListener(null).cancel();
|
|
|
|
relatedStreamRootLayout.setAlpha(0f);
|
|
|
|
relatedStreamRootLayout.setTranslationY(translationY);
|
|
|
|
relatedStreamRootLayout.setVisibility(View.VISIBLE);
|
|
|
|
relatedStreamRootLayout.animate().alpha(1f).translationY(0)
|
|
|
|
.setStartDelay((long) (duration * .8f) + delay).setDuration(duration).setInterpolator(new FastOutSlowInInterpolator()).start();
|
|
|
|
}
|
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OnStreamInfoReceivedListener callbacks
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
private void setErrorImage(final int imageResource) {
|
|
|
|
if (thumbnailImageView == null || activity == null) return;
|
|
|
|
thumbnailImageView.setImageDrawable(ContextCompat.getDrawable(activity, imageResource));
|
2017-05-08 15:33:26 +02:00
|
|
|
animateView(thumbnailImageView, false, 0, 0, new Runnable() {
|
2017-04-26 21:32:04 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
animateView(thumbnailImageView, true, 500);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
@Override
|
|
|
|
protected void setErrorMessage(String message, boolean showRetryButton) {
|
|
|
|
super.setErrorMessage(message, showRetryButton);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
if (!TextUtils.isEmpty(videoUrl)) StreamInfoCache.getInstance().removeInfo(videoUrl);
|
|
|
|
currentStreamInfo = null;
|
|
|
|
}
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
@Override
|
|
|
|
public void onReceive(StreamInfo info) {
|
|
|
|
if (DEBUG) Log.d(TAG, "onReceive() called with: info = [" + info + "]");
|
|
|
|
if (info == null || isRemoving() || !isVisible()) return;
|
2017-04-09 19:34:00 +02:00
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
handleStreamInfo(info, true);
|
2017-04-28 05:58:50 +02:00
|
|
|
showContentWithAnimation(300, 0, 0);
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
animateView(loadingProgressBar, false, 200);
|
2017-03-31 20:15:26 +02:00
|
|
|
|
2017-04-09 19:34:00 +02:00
|
|
|
if (autoPlayEnabled) {
|
|
|
|
playVideo(info);
|
|
|
|
// Only auto play in the first open
|
|
|
|
autoPlayEnabled = false;
|
|
|
|
}
|
|
|
|
|
2017-04-26 21:32:04 +02:00
|
|
|
StreamInfoCache.getInstance().putInfo(info);
|
2017-03-31 20:15:26 +02:00
|
|
|
isLoading.set(false);
|
2017-04-26 21:32:04 +02:00
|
|
|
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int messageId) {
|
2017-04-26 21:32:04 +02:00
|
|
|
if (DEBUG) Log.d(TAG, "onError() called with: messageId = [" + messageId + "]");
|
|
|
|
//Toast.makeText(activity, messageId, Toast.LENGTH_LONG).show();
|
|
|
|
setErrorImage(R.drawable.not_available_monkey);
|
|
|
|
setErrorMessage(getString(messageId), true);
|
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-04-26 21:32:04 +02:00
|
|
|
|
|
|
|
setErrorMessage(getString(R.string.recaptcha_request_toast), false);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockedByGemaError() {
|
2017-04-26 21:32:04 +02:00
|
|
|
|
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-26 21:32:04 +02:00
|
|
|
setErrorImage(R.drawable.gruese_die_gema);
|
|
|
|
setErrorMessage(getString(R.string.blocked_by_gema), false);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContentErrorWithMessage(int messageId) {
|
2017-04-26 21:32:04 +02:00
|
|
|
setErrorImage(R.drawable.not_available_monkey);
|
|
|
|
setErrorMessage(getString(messageId), false);
|
2017-03-31 20:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContentError() {
|
2017-04-26 21:32:04 +02:00
|
|
|
setErrorImage(R.drawable.not_available_monkey);
|
|
|
|
setErrorMessage(getString(R.string.content_not_available), false);
|
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
|
|
|
}
|