2016-08-02 21:17:54 +02:00
|
|
|
package org.schabi.newpipe.detail;
|
2015-09-04 02:15:03 +02:00
|
|
|
|
|
|
|
import android.app.Activity;
|
2016-02-08 18:46:42 +01:00
|
|
|
import android.content.DialogInterface;
|
2015-10-25 19:13:44 +01:00
|
|
|
import android.content.Intent;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2015-12-14 11:01:34 +01:00
|
|
|
import android.graphics.Point;
|
2015-12-28 00:32:38 +01:00
|
|
|
import android.net.Uri;
|
2015-12-15 22:53:29 +01:00
|
|
|
import android.os.Build;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.os.Bundle;
|
2015-09-21 01:10:11 +02:00
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.support.design.widget.FloatingActionButton;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.support.v4.app.Fragment;
|
2016-02-08 18:46:42 +01:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2015-10-29 17:56:35 +01:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2016-08-03 00:54:03 +02:00
|
|
|
import android.support.v7.widget.RecyclerView;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.text.Html;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
2015-10-29 17:56:35 +01:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2016-02-05 17:09:29 +01:00
|
|
|
import android.view.MotionEvent;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2015-10-25 19:13:44 +01:00
|
|
|
import android.widget.Button;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.widget.ImageView;
|
2016-09-26 17:02:55 +02:00
|
|
|
import android.widget.LinearLayout;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.widget.ProgressBar;
|
2015-09-21 01:10:11 +02:00
|
|
|
import android.widget.RelativeLayout;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.widget.TextView;
|
2015-10-29 17:56:35 +01:00
|
|
|
import android.view.MenuItem;
|
2015-12-28 00:32:38 +01:00
|
|
|
import android.widget.Toast;
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2016-02-16 03:49:58 +01:00
|
|
|
import com.google.android.exoplayer.util.Util;
|
2016-02-05 17:09:29 +01:00
|
|
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
|
|
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
|
import com.nostra13.universalimageloader.core.assist.FailReason;
|
|
|
|
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
|
|
|
|
2015-09-04 02:15:03 +02:00
|
|
|
import java.util.Vector;
|
|
|
|
|
2016-08-02 21:17:54 +02:00
|
|
|
import org.schabi.newpipe.ActivityCommunicator;
|
|
|
|
import org.schabi.newpipe.ChannelActivity;
|
2017-01-03 14:22:07 +01:00
|
|
|
import org.schabi.newpipe.ReCaptchaActivity;
|
2016-09-28 17:13:15 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream_info.StreamInfo;
|
|
|
|
import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfo;
|
2016-09-26 17:02:55 +02:00
|
|
|
import org.schabi.newpipe.info_list.InfoItemBuilder;
|
2016-09-13 23:39:32 +02:00
|
|
|
import org.schabi.newpipe.report.ErrorActivity;
|
2016-08-02 21:17:54 +02:00
|
|
|
import org.schabi.newpipe.ImageErrorLoadingListener;
|
|
|
|
import org.schabi.newpipe.Localization;
|
|
|
|
import org.schabi.newpipe.R;
|
2016-03-25 19:01:22 +01:00
|
|
|
import org.schabi.newpipe.download.DownloadDialog;
|
2016-09-28 17:13:15 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream_info.AudioStream;
|
2016-02-18 11:50:22 +01:00
|
|
|
import org.schabi.newpipe.extractor.MediaFormat;
|
2016-09-27 22:59:04 +02:00
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
2016-09-28 17:13:15 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream_info.VideoStream;
|
2016-02-22 20:28:37 +01:00
|
|
|
import org.schabi.newpipe.player.BackgroundPlayer;
|
|
|
|
import org.schabi.newpipe.player.PlayVideoActivity;
|
|
|
|
import org.schabi.newpipe.player.ExoPlayerActivity;
|
2015-11-17 00:32:00 +01:00
|
|
|
|
2017-01-03 14:22:07 +01:00
|
|
|
import static android.app.Activity.RESULT_OK;
|
|
|
|
import static org.schabi.newpipe.ReCaptchaActivity.RECAPTCHA_REQUEST;
|
|
|
|
|
2015-09-04 02:15:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
|
|
|
* VideoItemDetailFragment.java is part of NewPipe.
|
|
|
|
*
|
|
|
|
* NewPipe is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* NewPipe is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class VideoItemDetailFragment extends Fragment {
|
|
|
|
|
|
|
|
private static final String TAG = VideoItemDetailFragment.class.toString();
|
2016-02-08 18:46:42 +01:00
|
|
|
private static final String KORE_PACKET = "org.xbmc.kore";
|
2015-09-04 02:15:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The fragment argument representing the item ID that this fragment
|
|
|
|
* represents.
|
|
|
|
*/
|
|
|
|
public static final String VIDEO_URL = "video_url";
|
|
|
|
public static final String STREAMING_SERVICE = "streaming_service";
|
2015-09-11 09:50:30 +02:00
|
|
|
public static final String AUTO_PLAY = "auto_play";
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2015-10-29 17:56:35 +01:00
|
|
|
private AppCompatActivity activity;
|
|
|
|
private ActionBarHandler actionBarHandler;
|
2016-01-09 12:09:31 +01:00
|
|
|
private ProgressBar progressBar;
|
2015-10-29 17:56:35 +01:00
|
|
|
|
2015-12-25 00:09:35 +01:00
|
|
|
private int streamingServiceId = -1;
|
|
|
|
|
2016-06-24 02:37:44 +02:00
|
|
|
private boolean autoPlayEnabled;
|
2016-08-08 20:21:18 +02:00
|
|
|
private boolean showNextStreamItem;
|
2015-10-27 18:13:04 +01:00
|
|
|
|
2015-12-14 11:01:34 +01:00
|
|
|
private View thumbnailWindowLayout;
|
2016-02-18 13:49:01 +01:00
|
|
|
//this only remains due to downwards compatibility
|
2015-12-14 11:01:34 +01:00
|
|
|
private FloatingActionButton playVideoButton;
|
|
|
|
private final Point initialThumbnailPos = new Point(0, 0);
|
2016-08-08 20:21:18 +02:00
|
|
|
private View rootView = null;
|
|
|
|
private Bitmap streamThumbnail = null;
|
2016-02-05 17:09:29 +01:00
|
|
|
|
|
|
|
private ImageLoader imageLoader = ImageLoader.getInstance();
|
|
|
|
private DisplayImageOptions displayImageOptions =
|
|
|
|
new DisplayImageOptions.Builder().cacheInMemory(true).build();
|
|
|
|
|
2016-09-26 17:02:55 +02:00
|
|
|
private InfoItemBuilder infoItemBuilder = null;
|
2016-02-05 17:09:29 +01:00
|
|
|
|
2015-10-29 17:56:35 +01:00
|
|
|
public interface OnInvokeCreateOptionsMenuListener {
|
|
|
|
void createOptionsMenu();
|
|
|
|
}
|
|
|
|
|
2016-06-24 02:37:44 +02:00
|
|
|
private OnInvokeCreateOptionsMenuListener onInvokeCreateOptionsMenuListener;
|
2015-10-29 17:56:35 +01:00
|
|
|
|
2016-02-27 16:37:15 +01:00
|
|
|
private void updateInfo(final StreamInfo info) {
|
2016-09-26 17:02:55 +02:00
|
|
|
Activity a = getActivity();
|
2015-11-11 17:23:22 +01:00
|
|
|
|
2016-09-26 17:02:55 +02:00
|
|
|
RelativeLayout textContentLayout =
|
|
|
|
(RelativeLayout) activity.findViewById(R.id.detail_text_content_layout);
|
|
|
|
final TextView videoTitleView =
|
|
|
|
(TextView) activity.findViewById(R.id.detail_video_title_view);
|
|
|
|
TextView uploaderView = (TextView) activity.findViewById(R.id.detail_uploader_view);
|
|
|
|
TextView viewCountView = (TextView) activity.findViewById(R.id.detail_view_count_view);
|
|
|
|
TextView thumbsUpView = (TextView) activity.findViewById(R.id.detail_thumbs_up_count_view);
|
|
|
|
TextView thumbsDownView =
|
|
|
|
(TextView) activity.findViewById(R.id.detail_thumbs_down_count_view);
|
|
|
|
TextView uploadDateView = (TextView) activity.findViewById(R.id.detail_upload_date_view);
|
|
|
|
TextView descriptionView = (TextView) activity.findViewById(R.id.detail_description_view);
|
|
|
|
RecyclerView nextStreamView =
|
|
|
|
(RecyclerView) activity.findViewById(R.id.detail_next_stream_content);
|
|
|
|
RelativeLayout nextVideoRootFrame =
|
|
|
|
(RelativeLayout) activity.findViewById(R.id.detail_next_stream_root_layout);
|
|
|
|
TextView similarTitle = (TextView) activity.findViewById(R.id.detail_similar_title);
|
|
|
|
Button backgroundButton = (Button)
|
|
|
|
activity.findViewById(R.id.detail_stream_thumbnail_window_background_button);
|
|
|
|
View topView = activity.findViewById(R.id.detailTopView);
|
|
|
|
Button channelButton = (Button) activity.findViewById(R.id.channel_button);
|
2016-02-05 17:09:29 +01:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
// prevents a crash if the activity/fragment was already left when the response came
|
|
|
|
if(channelButton != null) {
|
|
|
|
|
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
if (info.next_video != null) {
|
|
|
|
// todo: activate this function or remove it
|
|
|
|
nextStreamView.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
nextStreamView.setVisibility(View.GONE);
|
|
|
|
activity.findViewById(R.id.detail_similar_title).setVisibility(View.GONE);
|
|
|
|
}
|
2016-02-05 17:09:29 +01:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
textContentLayout.setVisibility(View.VISIBLE);
|
|
|
|
if (android.os.Build.VERSION.SDK_INT < 18) {
|
|
|
|
playVideoButton.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
ImageView playArrowView = (ImageView) activity.findViewById(R.id.play_arrow_view);
|
|
|
|
playArrowView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2016-09-26 17:02:55 +02:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
if (!showNextStreamItem) {
|
|
|
|
nextVideoRootFrame.setVisibility(View.GONE);
|
|
|
|
similarTitle.setVisibility(View.GONE);
|
|
|
|
}
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
videoTitleView.setText(info.title);
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
topView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
|
|
|
|
ImageView arrow = (ImageView) activity.findViewById(R.id.toggle_description_view);
|
|
|
|
View extra = activity.findViewById(R.id.detailExtraView);
|
|
|
|
if (extra.getVisibility() == View.VISIBLE) {
|
|
|
|
extra.setVisibility(View.GONE);
|
|
|
|
arrow.setImageResource(R.drawable.arrow_down);
|
|
|
|
} else {
|
|
|
|
extra.setVisibility(View.VISIBLE);
|
|
|
|
arrow.setImageResource(R.drawable.arrow_up);
|
|
|
|
}
|
2016-09-26 17:02:55 +02:00
|
|
|
}
|
2016-09-27 20:18:41 +02:00
|
|
|
return true;
|
2016-01-31 19:57:30 +01:00
|
|
|
}
|
2016-09-27 20:18:41 +02:00
|
|
|
});
|
2016-09-26 17:02:55 +02:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
// Since newpipe is designed to work even if certain information is not available,
|
|
|
|
// the UI has to react on missing information.
|
|
|
|
videoTitleView.setText(info.title);
|
|
|
|
if (!info.uploader.isEmpty()) {
|
|
|
|
uploaderView.setText(info.uploader);
|
|
|
|
} else {
|
|
|
|
activity.findViewById(R.id.detail_uploader_view).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (info.view_count >= 0) {
|
|
|
|
viewCountView.setText(Localization.localizeViewCount(info.view_count, a));
|
|
|
|
} else {
|
|
|
|
viewCountView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (info.dislike_count >= 0) {
|
|
|
|
thumbsDownView.setText(Localization.localizeNumber(info.dislike_count, a));
|
|
|
|
} else {
|
|
|
|
thumbsDownView.setVisibility(View.INVISIBLE);
|
|
|
|
activity.findViewById(R.id.detail_thumbs_down_count_view).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (info.like_count >= 0) {
|
|
|
|
thumbsUpView.setText(Localization.localizeNumber(info.like_count, a));
|
|
|
|
} else {
|
|
|
|
thumbsUpView.setVisibility(View.GONE);
|
|
|
|
activity.findViewById(R.id.detail_thumbs_up_img_view).setVisibility(View.GONE);
|
|
|
|
thumbsDownView.setVisibility(View.GONE);
|
|
|
|
activity.findViewById(R.id.detail_thumbs_down_img_view).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (!info.upload_date.isEmpty()) {
|
|
|
|
uploadDateView.setText(Localization.localizeDate(info.upload_date, a));
|
|
|
|
} else {
|
|
|
|
uploadDateView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (!info.description.isEmpty()) {
|
|
|
|
descriptionView.setText(Html.fromHtml(info.description));
|
|
|
|
} else {
|
|
|
|
descriptionView.setVisibility(View.GONE);
|
|
|
|
}
|
2016-02-05 14:09:04 +01:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
descriptionView.setMovementMethod(LinkMovementMethod.getInstance());
|
2016-01-31 19:57:30 +01:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
// parse streams
|
|
|
|
Vector<VideoStream> streamsToUse = new Vector<>();
|
|
|
|
for (VideoStream i : info.video_streams) {
|
|
|
|
if (useStream(i, streamsToUse)) {
|
|
|
|
streamsToUse.add(i);
|
|
|
|
}
|
2016-08-08 20:21:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
textContentLayout.setVisibility(View.VISIBLE);
|
2015-09-04 02:15:03 +02:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
if (info.next_video == null) {
|
|
|
|
activity.findViewById(R.id.detail_next_stream_title).setVisibility(View.GONE);
|
|
|
|
}
|
2016-02-18 17:40:26 +01:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
if (info.related_streams != null && !info.related_streams.isEmpty()) {
|
|
|
|
initSimilarVideos(info);
|
|
|
|
} else {
|
|
|
|
activity.findViewById(R.id.detail_similar_title).setVisibility(View.GONE);
|
|
|
|
activity.findViewById(R.id.similar_streams_view).setVisibility(View.GONE);
|
|
|
|
}
|
2016-02-08 18:46:42 +01:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
setupActionBarHandler(info);
|
2016-02-08 18:46:42 +01:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
if (autoPlayEnabled) {
|
|
|
|
playVideo(info);
|
|
|
|
}
|
2016-09-26 17:02:55 +02:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
if (android.os.Build.VERSION.SDK_INT < 18) {
|
|
|
|
playVideoButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
playVideo(info);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
backgroundButton.setOnClickListener(new View.OnClickListener() {
|
2016-02-08 18:46:42 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
playVideo(info);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
if (info.channel_url != null && info.channel_url != "") {
|
|
|
|
channelButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
Intent i = new Intent(activity, ChannelActivity.class);
|
|
|
|
i.putExtra(ChannelActivity.CHANNEL_URL, info.channel_url);
|
|
|
|
i.putExtra(ChannelActivity.SERVICE_ID, info.service_id);
|
|
|
|
startActivity(i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
channelButton.setVisibility(Button.GONE);
|
2016-08-01 01:56:19 +02:00
|
|
|
}
|
2016-07-26 13:50:52 +02:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
initThumbnailViews(info);
|
2015-09-04 02:15:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-08 20:21:18 +02:00
|
|
|
private void initThumbnailViews(final StreamInfo info) {
|
|
|
|
ImageView videoThumbnailView = (ImageView) activity.findViewById(R.id.detail_thumbnail_view);
|
2016-02-05 17:09:29 +01:00
|
|
|
ImageView uploaderThumb
|
2016-08-08 20:21:18 +02:00
|
|
|
= (ImageView) activity.findViewById(R.id.detail_uploader_thumbnail_view);
|
2016-02-05 17:09:29 +01:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
if (info.thumbnail_url != null && !info.thumbnail_url.isEmpty()) {
|
2016-02-18 13:49:01 +01:00
|
|
|
imageLoader.displayImage(info.thumbnail_url, videoThumbnailView,
|
|
|
|
displayImageOptions, new ImageLoadingListener() {
|
|
|
|
@Override
|
|
|
|
public void onLoadingStarted(String imageUri, View view) {
|
|
|
|
}
|
2016-02-05 17:09:29 +01:00
|
|
|
|
2016-02-18 13:49:01 +01:00
|
|
|
@Override
|
|
|
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
2016-08-01 01:56:19 +02:00
|
|
|
ErrorActivity.reportError(getActivity(),
|
|
|
|
failReason.getCause(), null, rootView,
|
|
|
|
ErrorActivity.ErrorInfo.make(ErrorActivity.LOAD_IMAGE,
|
2016-09-27 22:59:04 +02:00
|
|
|
NewPipe.getNameOfService(info.service_id), imageUri,
|
2016-08-01 01:56:19 +02:00
|
|
|
R.string.could_not_load_thumbnails));
|
2016-02-18 13:49:01 +01:00
|
|
|
}
|
2016-02-05 17:09:29 +01:00
|
|
|
|
2016-02-18 13:49:01 +01:00
|
|
|
@Override
|
|
|
|
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
2016-08-08 20:21:18 +02:00
|
|
|
streamThumbnail = loadedImage;
|
2016-02-18 13:49:01 +01:00
|
|
|
}
|
2016-02-05 17:09:29 +01:00
|
|
|
|
2016-02-18 13:49:01 +01:00
|
|
|
@Override
|
|
|
|
public void onLoadingCancelled(String imageUri, View view) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
videoThumbnailView.setImageResource(R.drawable.dummy_thumbnail_dark);
|
|
|
|
}
|
2016-09-27 20:18:41 +02:00
|
|
|
if (info.uploader_thumbnail_url != null && !info.uploader_thumbnail_url.isEmpty()) {
|
2016-02-18 13:49:01 +01:00
|
|
|
imageLoader.displayImage(info.uploader_thumbnail_url,
|
2016-08-01 21:50:41 +02:00
|
|
|
uploaderThumb, displayImageOptions,
|
|
|
|
new ImageErrorLoadingListener(activity, rootView, info.service_id));
|
2016-02-18 13:49:01 +01:00
|
|
|
}
|
2016-02-05 17:09:29 +01:00
|
|
|
}
|
|
|
|
|
2016-02-27 16:37:15 +01:00
|
|
|
private void setupActionBarHandler(final StreamInfo info) {
|
2016-02-08 18:46:42 +01:00
|
|
|
actionBarHandler.setupStreamList(info.video_streams);
|
|
|
|
|
|
|
|
actionBarHandler.setOnShareListener(new ActionBarHandler.OnActionListener() {
|
|
|
|
@Override
|
|
|
|
public void onActionSelected(int selectedStreamId) {
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(Intent.ACTION_SEND);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info.webpage_url);
|
|
|
|
intent.setType("text/plain");
|
|
|
|
activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.share_dialog_title)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
actionBarHandler.setOnOpenInBrowserListener(new ActionBarHandler.OnActionListener() {
|
|
|
|
@Override
|
|
|
|
public void onActionSelected(int selectedStreamId) {
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse(info.webpage_url));
|
|
|
|
|
|
|
|
activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.choose_browser)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
actionBarHandler.setOnPlayWithKodiListener(new ActionBarHandler.OnActionListener() {
|
|
|
|
@Override
|
|
|
|
public void onActionSelected(int selectedStreamId) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setPackage(KORE_PACKET);
|
|
|
|
intent.setData(Uri.parse(info.webpage_url.replace("https", "http")));
|
|
|
|
activity.startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
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);
|
|
|
|
intent.setData(Uri.parse(activity.getString(R.string.fdroid_kore_url)));
|
|
|
|
activity.startActivity(intent);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.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) {
|
2016-02-17 21:39:41 +01:00
|
|
|
try {
|
|
|
|
Bundle args = new Bundle();
|
2016-02-08 18:46:42 +01:00
|
|
|
|
2016-02-17 21:39:41 +01:00
|
|
|
// 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) {
|
2016-03-04 13:36:06 +01:00
|
|
|
AudioStream audioStream =
|
2016-02-17 21:39:41 +01:00
|
|
|
info.audio_streams.get(getPreferredAudioStreamId(info));
|
|
|
|
|
|
|
|
String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
|
|
|
|
args.putString(DownloadDialog.AUDIO_URL, audioStream.url);
|
|
|
|
args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix);
|
2016-02-08 18:46:42 +01:00
|
|
|
}
|
2016-02-17 21:39:41 +01:00
|
|
|
|
|
|
|
if (info.video_streams != null) {
|
2016-03-04 13:36:06 +01:00
|
|
|
VideoStream selectedStreamItem = info.video_streams.get(selectedStreamId);
|
2016-02-17 21:39:41 +01:00
|
|
|
String videoSuffix = "." + MediaFormat.getSuffixById(selectedStreamItem.format);
|
|
|
|
args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix);
|
|
|
|
args.putString(DownloadDialog.VIDEO_URL, selectedStreamItem.url);
|
2016-02-08 18:46:42 +01:00
|
|
|
}
|
2016-02-17 21:39:41 +01:00
|
|
|
|
|
|
|
args.putString(DownloadDialog.TITLE, info.title);
|
2016-04-29 12:40:03 +02:00
|
|
|
DownloadDialog downloadDialog = DownloadDialog.newInstance(args);
|
2016-02-17 21:39:41 +01:00
|
|
|
downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
|
2016-02-17 23:55:19 +01:00
|
|
|
} catch (Exception e) {
|
2016-02-17 21:39:41 +01:00
|
|
|
Toast.makeText(VideoItemDetailFragment.this.getActivity(),
|
|
|
|
R.string.could_not_setup_download_menu, Toast.LENGTH_LONG).show();
|
|
|
|
e.printStackTrace();
|
2016-02-08 18:46:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-02-17 21:39:41 +01:00
|
|
|
|
2016-09-27 20:18:41 +02:00
|
|
|
if (info.audio_streams == null) {
|
2016-02-17 21:39:41 +01:00
|
|
|
actionBarHandler.showAudioAction(false);
|
|
|
|
} else {
|
|
|
|
actionBarHandler.setOnPlayAudioListener(new ActionBarHandler.OnActionListener() {
|
|
|
|
@Override
|
|
|
|
public void onActionSelected(int selectedStreamId) {
|
|
|
|
boolean useExternalAudioPlayer = PreferenceManager.getDefaultSharedPreferences(activity)
|
|
|
|
.getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
|
|
|
|
Intent intent;
|
2016-03-04 13:36:06 +01:00
|
|
|
AudioStream audioStream =
|
2016-02-17 21:39:41 +01:00
|
|
|
info.audio_streams.get(getPreferredAudioStreamId(info));
|
|
|
|
if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 18) {
|
|
|
|
//internal music player: explicit intent
|
2016-08-08 20:21:18 +02:00
|
|
|
if (!BackgroundPlayer.isRunning && streamThumbnail != null) {
|
2016-02-17 21:39:41 +01:00
|
|
|
ActivityCommunicator.getCommunicator()
|
2016-08-08 20:21:18 +02:00
|
|
|
.backgroundPlayerThumbnail = streamThumbnail;
|
2016-02-17 21:39:41 +01:00
|
|
|
intent = new Intent(activity, BackgroundPlayer.class);
|
|
|
|
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
Log.i(TAG, "audioStream is null:" + (audioStream == null));
|
|
|
|
Log.i(TAG, "audioStream.url is null:" + (audioStream.url == null));
|
|
|
|
intent.setDataAndType(Uri.parse(audioStream.url),
|
|
|
|
MediaFormat.getMimeById(audioStream.format));
|
|
|
|
intent.putExtra(BackgroundPlayer.TITLE, info.title);
|
|
|
|
intent.putExtra(BackgroundPlayer.WEB_URL, info.webpage_url);
|
|
|
|
intent.putExtra(BackgroundPlayer.SERVICE_ID, streamingServiceId);
|
|
|
|
intent.putExtra(BackgroundPlayer.CHANNEL_NAME, info.uploader);
|
|
|
|
activity.startService(intent);
|
|
|
|
}
|
|
|
|
} 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 !!!
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-02-08 18:46:42 +01:00
|
|
|
}
|
|
|
|
|
2016-02-27 16:37:15 +01:00
|
|
|
private int getPreferredAudioStreamId(final StreamInfo info) {
|
2016-02-08 18:46:42 +01:00
|
|
|
String preferredFormatString = PreferenceManager.getDefaultSharedPreferences(getActivity())
|
|
|
|
.getString(activity.getString(R.string.default_audio_format_key), "webm");
|
|
|
|
|
|
|
|
int preferredFormat = MediaFormat.WEBMA.id;
|
|
|
|
switch(preferredFormatString) {
|
|
|
|
case "webm":
|
|
|
|
preferredFormat = MediaFormat.WEBMA.id;
|
|
|
|
break;
|
|
|
|
case "m4a":
|
|
|
|
preferredFormat = MediaFormat.M4A.id;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < info.audio_streams.size(); i++) {
|
|
|
|
if(info.audio_streams.get(i).format == preferredFormat) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//todo: make this a proper error
|
|
|
|
Log.e(TAG, "FAILED to set audioStream value!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-03 15:32:25 +02:00
|
|
|
private void initSimilarVideos(final StreamInfo info) {
|
2016-09-26 17:02:55 +02:00
|
|
|
LinearLayout similarLayout = (LinearLayout) activity.findViewById(R.id.similar_streams_view);
|
|
|
|
for (final StreamPreviewInfo item : info.related_streams) {
|
|
|
|
similarLayout.addView(infoItemBuilder.buildView(similarLayout, item));
|
|
|
|
}
|
2016-09-26 18:01:39 +02:00
|
|
|
infoItemBuilder.setOnItemSelectedListener(new InfoItemBuilder.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void selected(String url) {
|
|
|
|
openStreamUrl(url);
|
|
|
|
}
|
|
|
|
});
|
2016-02-05 17:09:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-31 19:57:30 +01:00
|
|
|
private void onErrorBlockedByGema() {
|
|
|
|
Button backgroundButton = (Button)
|
2016-08-08 20:21:18 +02:00
|
|
|
activity.findViewById(R.id.detail_stream_thumbnail_window_background_button);
|
|
|
|
ImageView thumbnailView = (ImageView) activity.findViewById(R.id.detail_thumbnail_view);
|
2016-01-31 19:57:30 +01:00
|
|
|
|
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
thumbnailView.setImageBitmap(BitmapFactory.decodeResource(
|
|
|
|
getResources(), R.drawable.gruese_die_gema));
|
|
|
|
backgroundButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse(activity.getString(R.string.c3s_url)));
|
|
|
|
activity.startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Toast.makeText(VideoItemDetailFragment.this.getActivity(),
|
|
|
|
R.string.blocked_by_gema, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onNotSpecifiedContentError() {
|
2016-08-08 20:21:18 +02:00
|
|
|
ImageView thumbnailView = (ImageView) activity.findViewById(R.id.detail_thumbnail_view);
|
2016-01-31 19:57:30 +01:00
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
thumbnailView.setImageBitmap(BitmapFactory.decodeResource(
|
|
|
|
getResources(), R.drawable.not_available_monkey));
|
|
|
|
Toast.makeText(activity, R.string.content_not_available, Toast.LENGTH_LONG)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
2016-02-21 21:05:16 +01:00
|
|
|
private void onNotSpecifiedContentErrorWithMessage(int resourceId) {
|
2016-08-08 20:21:18 +02:00
|
|
|
ImageView thumbnailView = (ImageView) activity.findViewById(R.id.detail_thumbnail_view);
|
2016-02-21 21:05:16 +01:00
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
thumbnailView.setImageBitmap(BitmapFactory.decodeResource(
|
|
|
|
getResources(), R.drawable.not_available_monkey));
|
|
|
|
Toast.makeText(activity, resourceId, Toast.LENGTH_LONG)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
2016-03-04 13:36:06 +01:00
|
|
|
private boolean useStream(VideoStream stream, Vector<VideoStream> streams) {
|
|
|
|
for(VideoStream i : streams) {
|
2015-09-04 02:15:03 +02:00
|
|
|
if(i.resolution.equals(stream.resolution)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2015-10-29 17:56:35 +01:00
|
|
|
activity = (AppCompatActivity) getActivity();
|
2016-08-08 20:21:18 +02:00
|
|
|
showNextStreamItem = PreferenceManager.getDefaultSharedPreferences(getActivity())
|
2016-01-05 20:56:40 +01:00
|
|
|
.getBoolean(activity.getString(R.string.show_next_video_key), true);
|
2015-12-02 21:20:52 +01:00
|
|
|
|
2016-08-03 00:12:58 +02:00
|
|
|
|
|
|
|
StreamInfoWorker siw = StreamInfoWorker.getInstance();
|
|
|
|
siw.setOnStreamInfoReceivedListener(new StreamInfoWorker.OnStreamInfoReceivedListener() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(StreamInfo info) {
|
|
|
|
updateInfo(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(int messageId) {
|
|
|
|
postNewErrorToast(messageId);
|
|
|
|
}
|
|
|
|
|
2017-01-03 14:22:07 +01:00
|
|
|
@Override
|
|
|
|
public void onReCaptchaException() {
|
|
|
|
Toast.makeText(getActivity(), R.string.recaptcha_request_toast,
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
// Starting ReCaptcha Challenge Activity
|
|
|
|
startActivityForResult(
|
|
|
|
new Intent(getActivity(), ReCaptchaActivity.class),
|
|
|
|
RECAPTCHA_REQUEST);
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:12:58 +02:00
|
|
|
@Override
|
|
|
|
public void onBlockedByGemaError() {
|
|
|
|
onErrorBlockedByGema();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContentErrorWithMessage(int messageId) {
|
|
|
|
onNotSpecifiedContentErrorWithMessage(messageId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContentError() {
|
|
|
|
onNotSpecifiedContentError();
|
|
|
|
}
|
|
|
|
});
|
2015-09-04 02:15:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
|
Bundle savedInstanceState) {
|
2016-08-01 01:56:19 +02:00
|
|
|
rootView = inflater.inflate(R.layout.fragment_videoitem_detail, container, false);
|
2016-08-08 20:21:18 +02:00
|
|
|
progressBar = (ProgressBar) rootView.findViewById(R.id.detail_progress_bar);
|
2016-01-09 12:09:31 +01:00
|
|
|
|
2015-10-29 17:56:35 +01:00
|
|
|
actionBarHandler = new ActionBarHandler(activity);
|
|
|
|
actionBarHandler.setupNavMenu(activity);
|
|
|
|
if(onInvokeCreateOptionsMenuListener != null) {
|
|
|
|
onInvokeCreateOptionsMenuListener.createOptionsMenu();
|
|
|
|
}
|
|
|
|
|
2015-09-04 02:15:03 +02:00
|
|
|
return rootView;
|
|
|
|
}
|
2015-09-21 01:10:11 +02:00
|
|
|
|
|
|
|
@Override
|
2017-01-16 13:01:52 +01:00
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
2015-12-14 11:01:34 +01:00
|
|
|
Activity a = getActivity();
|
2016-09-26 17:02:55 +02:00
|
|
|
|
|
|
|
infoItemBuilder = new InfoItemBuilder(a, a.findViewById(android.R.id.content));
|
|
|
|
|
2016-02-17 23:55:19 +01:00
|
|
|
if (android.os.Build.VERSION.SDK_INT < 18) {
|
2016-08-08 20:21:18 +02:00
|
|
|
playVideoButton = (FloatingActionButton) a.findViewById(R.id.play_video_button);
|
2016-02-17 23:55:19 +01:00
|
|
|
}
|
2016-08-08 20:21:18 +02:00
|
|
|
thumbnailWindowLayout = a.findViewById(R.id.detail_stream_thumbnail_window_layout);
|
2015-12-14 11:01:34 +01:00
|
|
|
Button backgroundButton = (Button)
|
2016-08-08 20:21:18 +02:00
|
|
|
a.findViewById(R.id.detail_stream_thumbnail_window_background_button);
|
2015-09-21 01:10:11 +02:00
|
|
|
|
2015-11-02 19:57:47 +01:00
|
|
|
// Sometimes when this fragment is not visible it still gets initiated
|
|
|
|
// then we must not try to access objects of this fragment.
|
|
|
|
// Otherwise the applications would crash.
|
2016-02-17 23:55:19 +01:00
|
|
|
if(backgroundButton != null) {
|
2016-08-03 00:12:58 +02:00
|
|
|
streamingServiceId = getArguments().getInt(STREAMING_SERVICE);
|
|
|
|
String videoUrl = getArguments().getString(VIDEO_URL);
|
|
|
|
StreamInfoWorker siw = StreamInfoWorker.getInstance();
|
|
|
|
siw.search(streamingServiceId, videoUrl, getActivity());
|
2015-11-02 22:29:43 +01:00
|
|
|
|
2016-08-03 00:12:58 +02:00
|
|
|
autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY);
|
2015-10-23 23:08:01 +02:00
|
|
|
|
2015-12-15 22:53:29 +01:00
|
|
|
if(Build.VERSION.SDK_INT >= 18) {
|
2016-08-08 20:21:18 +02:00
|
|
|
ImageView thumbnailView = (ImageView) activity.findViewById(R.id.detail_thumbnail_view);
|
2015-12-15 22:53:29 +01:00
|
|
|
thumbnailView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
|
|
|
// This is used to synchronize the thumbnailWindowButton and the playVideoButton
|
|
|
|
// inside the ScrollView with the actual size of the thumbnail.
|
2016-02-17 23:55:19 +01:00
|
|
|
//todo: onLayoutChage sometimes not triggered
|
|
|
|
// background buttons area seem to overlap the thumbnail view
|
|
|
|
// So although you just clicked slightly beneath the thumbnail the action still
|
|
|
|
// gets triggered.
|
2015-12-15 22:53:29 +01:00
|
|
|
@Override
|
2016-02-05 17:09:29 +01:00
|
|
|
public void onLayoutChange(View v, int left, int top, int right, int bottom,
|
|
|
|
int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
2015-12-15 22:53:29 +01:00
|
|
|
RelativeLayout.LayoutParams newWindowLayoutParams =
|
|
|
|
(RelativeLayout.LayoutParams) thumbnailWindowLayout.getLayoutParams();
|
|
|
|
newWindowLayoutParams.height = bottom - top;
|
|
|
|
thumbnailWindowLayout.setLayoutParams(newWindowLayoutParams);
|
2015-12-08 21:29:29 +01:00
|
|
|
|
2015-12-15 22:53:29 +01:00
|
|
|
//noinspection SuspiciousNameCombination
|
|
|
|
initialThumbnailPos.set(top, left);
|
2015-12-08 21:29:29 +01:00
|
|
|
|
2015-12-15 22:53:29 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-10-23 23:08:01 +02:00
|
|
|
}
|
2015-09-21 01:10:11 +02:00
|
|
|
}
|
2015-09-21 23:53:10 +02:00
|
|
|
|
2016-02-27 16:37:15 +01:00
|
|
|
public void playVideo(final StreamInfo info) {
|
2016-02-08 18:46:42 +01:00
|
|
|
// ----------- THE MAGIC MOMENT ---------------
|
2016-03-04 13:36:06 +01:00
|
|
|
VideoStream selectedVideoStream =
|
2016-02-08 18:46:42 +01:00
|
|
|
info.video_streams.get(actionBarHandler.getSelectedVideoStream());
|
|
|
|
|
|
|
|
if (PreferenceManager.getDefaultSharedPreferences(activity)
|
|
|
|
.getBoolean(activity.getString(R.string.use_external_video_player_key), false)) {
|
|
|
|
|
|
|
|
// External Player
|
|
|
|
Intent intent = new Intent();
|
|
|
|
try {
|
2016-02-23 01:56:04 +01:00
|
|
|
intent.setAction(Intent.ACTION_VIEW)
|
|
|
|
.setDataAndType(Uri.parse(selectedVideoStream.url),
|
|
|
|
MediaFormat.getMimeById(selectedVideoStream.format))
|
|
|
|
.putExtra(Intent.EXTRA_TITLE, info.title)
|
|
|
|
.putExtra("title", info.title);
|
2016-02-08 18:46:42 +01:00
|
|
|
|
|
|
|
activity.startActivity(intent); // HERE !!!
|
|
|
|
} 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) {
|
2016-02-23 01:56:04 +01:00
|
|
|
Intent intent = new Intent()
|
|
|
|
.setAction(Intent.ACTION_VIEW)
|
|
|
|
.setData(Uri.parse(activity.getString(R.string.fdroid_vlc_url)));
|
2016-02-08 18:46:42 +01:00
|
|
|
activity.startActivity(intent);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
} else {
|
2016-02-16 03:49:58 +01:00
|
|
|
if (PreferenceManager.getDefaultSharedPreferences(activity)
|
|
|
|
.getBoolean(activity.getString(R.string.use_exoplayer_key), false)) {
|
2016-02-22 20:28:37 +01:00
|
|
|
|
|
|
|
// exo player
|
|
|
|
|
|
|
|
if(info.dashMpdUrl != null && !info.dashMpdUrl.isEmpty()) {
|
2016-02-23 01:56:04 +01:00
|
|
|
// try dash
|
|
|
|
Intent intent = new Intent(activity, ExoPlayerActivity.class)
|
2016-02-22 20:28:37 +01:00
|
|
|
.setData(Uri.parse(info.dashMpdUrl))
|
|
|
|
.putExtra(ExoPlayerActivity.CONTENT_TYPE_EXTRA, Util.TYPE_DASH);
|
2016-02-23 01:56:04 +01:00
|
|
|
startActivity(intent);
|
|
|
|
} else if((info.audio_streams != null && !info.audio_streams.isEmpty()) &&
|
|
|
|
(info.video_only_streams != null && !info.video_only_streams.isEmpty())) {
|
|
|
|
// try smooth streaming
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//default streaming
|
|
|
|
Intent intent = new Intent(activity, ExoPlayerActivity.class)
|
|
|
|
.setDataAndType(Uri.parse(selectedVideoStream.url),
|
|
|
|
MediaFormat.getMimeById(selectedVideoStream.format))
|
|
|
|
.putExtra(ExoPlayerActivity.CONTENT_TYPE_EXTRA, Util.TYPE_OTHER);
|
|
|
|
|
|
|
|
activity.startActivity(intent); // HERE !!!
|
2016-02-22 20:28:37 +01:00
|
|
|
}
|
|
|
|
//-------------
|
|
|
|
|
2016-02-16 03:49:58 +01:00
|
|
|
} else {
|
|
|
|
// Internal Player
|
2016-02-23 01:56:04 +01:00
|
|
|
Intent intent = new Intent(activity, PlayVideoActivity.class)
|
|
|
|
.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);
|
2016-02-16 03:49:58 +01:00
|
|
|
activity.startActivity(intent); //also HERE !!!
|
|
|
|
}
|
2016-02-08 18:46:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------
|
|
|
|
}
|
|
|
|
|
2015-10-29 17:56:35 +01:00
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
actionBarHandler.setupMenu(menu, inflater);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
return actionBarHandler.onItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnInvokeCreateOptionsMenuListener(OnInvokeCreateOptionsMenuListener listener) {
|
|
|
|
this.onInvokeCreateOptionsMenuListener = listener;
|
|
|
|
}
|
2016-01-31 19:57:30 +01:00
|
|
|
|
2016-08-03 00:12:58 +02:00
|
|
|
private void postNewErrorToast(final int stringResource) {
|
|
|
|
Toast.makeText(VideoItemDetailFragment.this.getActivity(),
|
|
|
|
stringResource, Toast.LENGTH_LONG).show();
|
2016-01-31 19:57:30 +01:00
|
|
|
}
|
2016-08-08 20:21:18 +02:00
|
|
|
|
|
|
|
private void openStreamUrl(String url) {
|
|
|
|
Intent detailIntent = new Intent(activity, VideoItemDetailActivity.class);
|
|
|
|
detailIntent.putExtra(VideoItemDetailFragment.VIDEO_URL, url);
|
|
|
|
detailIntent.putExtra(
|
|
|
|
VideoItemDetailFragment.STREAMING_SERVICE, streamingServiceId);
|
|
|
|
activity.startActivity(detailIntent);
|
|
|
|
}
|
2017-01-03 14:22:07 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case RECAPTCHA_REQUEST:
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
String videoUrl = getArguments().getString(VIDEO_URL);
|
|
|
|
StreamInfoWorker siw = StreamInfoWorker.getInstance();
|
|
|
|
siw.search(streamingServiceId, videoUrl, getActivity());
|
|
|
|
} else {
|
|
|
|
Log.d(TAG, "ReCaptcha failed");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Log.e(TAG, "Request code from activity not supported [" + requestCode + "]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|