package com.ysvideo.zhibo.app.ui.video;
|
|
import android.app.ProgressDialog;
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
import android.graphics.Bitmap;
|
import android.graphics.Color;
|
import android.graphics.Rect;
|
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.GradientDrawable;
|
import android.os.Bundle;
|
import android.os.Handler;
|
import android.text.Spannable;
|
import android.text.SpannableStringBuilder;
|
import android.text.style.ForegroundColorSpan;
|
import android.text.style.RelativeSizeSpan;
|
import android.util.Log;
|
import android.view.View;
|
import android.view.WindowManager;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.ListView;
|
import android.widget.PopupWindow;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.request.RequestOptions;
|
import com.google.gson.reflect.TypeToken;
|
import com.umeng.socialize.ShareAction;
|
import com.umeng.socialize.UMShareListener;
|
import com.umeng.socialize.bean.SHARE_MEDIA;
|
import com.umeng.socialize.media.UMWeb;
|
import com.ysvideo.zhibo.app.R;
|
import com.ysvideo.zhibo.app.entity.ad.ExpressAdContainer;
|
import com.ysvideo.zhibo.app.entity.video.Play;
|
import com.ysvideo.zhibo.app.entity.video.PlayUrl;
|
import com.ysvideo.zhibo.app.entity.video.Playlocation;
|
import com.ysvideo.zhibo.app.entity.video.VideoContent;
|
import com.ysvideo.zhibo.app.entity.video.VideoDetailInfo;
|
import com.ysvideo.zhibo.app.entity.video.VideoInfo;
|
import com.ysvideo.zhibo.app.entity.video.VideoResource;
|
import com.ysvideo.zhibo.app.ui.video.adapter.EpisodeNewAdapter;
|
import com.ysvideo.zhibo.app.ui.video.adapter.VideoCloumn1Adapter;
|
import com.ysvideo.zhibo.app.ui.video.adapter.VideoColumn2Adapter;
|
import com.ysvideo.zhibo.app.util.JsonUtil;
|
import com.ysvideo.zhibo.app.util.LoginUtil;
|
import com.ysvideo.zhibo.app.util.UserUtil;
|
import com.ysvideo.zhibo.app.util.ad.ExpressAdManager;
|
|
import com.ysvideo.zhibo.app.util.api.BasicTextHttpResponseHandler;
|
import com.ysvideo.zhibo.app.util.api.HttpApiUtil;
|
import com.ysvideo.zhibo.app.util.ui.DividerItemDecoration;
|
import com.ysvideo.zhibo.app.util.video.VideoUtil;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
import com.ysvideo.zhibo.lib.common.RetainViewFragment;
|
import com.ysvideo.zhibo.lib.common.util.SingleToast;
|
import com.ysvideo.zhibo.lib.common.util.common.DimenUtils;
|
import com.ysvideo.zhibo.lib.common.util.common.StringUtils;
|
import com.ysvideo.zhibo.library_ad.AdUtil;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.RecyclerView;
|
import de.greenrobot.event.EventBus;
|
|
/**
|
* 节目选集列表,可设置电视剧6列;电影,综艺1列
|
*/
|
public class EpisodeFragment extends RetainViewFragment implements View.OnClickListener {
|
private int mStart;
|
private int mEnd;
|
private int mPlayingPosition;
|
private VideoInfo mVideoInfo = null;
|
private RecyclerView rv_episode, rv_video_related_video, rv_video_guess_like;
|
|
private ImageView iv_moive_img, iv_add_to_favourite, iv_offline_cache;
|
|
private TextView tv_star_name, tv_update_time, tv_cancle_follow, tv_title, tv_score, tv_tag, tv_resource;
|
|
private LinearLayout ll_add_attention;
|
|
private FrameLayout fl_native_ad1;
|
|
private EpisodeNewAdapter episodeAdapter;
|
|
private LinearLayout ll_score;
|
|
final String TAG = "EpisodeFragment";
|
|
|
private String resourceId;
|
|
public static DisplayImageOptions option = new DisplayImageOptions.Builder()
|
.showImageForEmptyUri(R.drawable.from_other)
|
.showImageOnFail(R.drawable.from_other)
|
.showImageOnLoading(R.drawable.from_other)
|
.resetViewBeforeLoading(false) // default
|
.cacheInMemory(true) // default
|
.cacheOnDisk(true) // default
|
.considerExifParams(false) // default
|
.imageScaleType(ImageScaleType.EXACTLY) // default
|
.bitmapConfig(Bitmap.Config.ARGB_8888) // default
|
.handler(new Handler()) // default
|
.build();
|
|
public static EpisodeFragment newInstance(VideoInfo videoInfo,
|
int playingPosition, String resourceId, int start, int end) {
|
EpisodeFragment episodeFragment = new EpisodeFragment();
|
Bundle args = new Bundle();
|
args.putSerializable("video_info", videoInfo);
|
args.putInt("playing_position", playingPosition);
|
args.putInt("start", start);
|
args.putInt("end", end);
|
args.putString("resourceId", resourceId);
|
episodeFragment.setArguments(args);
|
return episodeFragment;
|
}
|
|
@Override
|
public int getContentResource() {
|
return R.layout.fragment_episode;
|
}
|
|
|
/**
|
* 设置视频信息
|
*/
|
private void setVideoInfo() {
|
if (mVideoInfo == null)
|
return;
|
tv_title.setText(mVideoInfo.getName());
|
|
if (!StringUtils.isBlank(mVideoInfo.getScore())) {
|
tv_score.setText(mVideoInfo.getScore());
|
|
SpannableStringBuilder style = new SpannableStringBuilder(tv_score.getText());
|
RelativeSizeSpan sizeSpan = new RelativeSizeSpan(0.75f);
|
|
if (mVideoInfo.getScore().indexOf(".") > -1) {
|
style.setSpan(sizeSpan, mVideoInfo.getScore().indexOf(".")+1, mVideoInfo.getScore().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
tv_score.setText(style);
|
}
|
|
|
tv_score.setVisibility(View.VISIBLE);
|
ll_score.setVisibility(View.VISIBLE);
|
} else {
|
tv_score.setVisibility(View.GONE);
|
ll_score.setVisibility(View.GONE);
|
}
|
|
if (mVideoInfo.getTag() != null && mVideoInfo.getTag().contains("集")) {
|
tv_tag.setVisibility(View.VISIBLE);
|
tv_tag.setText(mVideoInfo.getTag());
|
} else {
|
tv_tag.setVisibility(View.GONE);
|
}
|
|
guessLike();
|
// getRelativeVideos();
|
}
|
|
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
|
private int space;
|
|
public SpacesItemDecoration(int space) {
|
this.space = space;
|
}
|
|
@Override
|
public void getItemOffsets(Rect outRect, View view,
|
RecyclerView parent, RecyclerView.State state) {
|
int position = parent.getChildAdapterPosition(view);
|
outRect.left = space;
|
if (mVideoInfo != null && position == mVideoInfo.getVideoDetailList().size() - 1)
|
outRect.right = space;
|
}
|
}
|
|
private void loadEpisode() {
|
|
int type = 0;
|
|
if (mVideoInfo.getShowType() == 1) {
|
// 综艺或者电影
|
type = EpisodeNewAdapter.TYPE_ZONGYI;
|
|
} else if (mVideoInfo.getShowType() == 2) {
|
// 电视剧动漫
|
type = EpisodeNewAdapter.TYPE_DIANSHIJU;
|
}
|
episodeAdapter = new EpisodeNewAdapter(getContext(), mVideoInfo, type, mPlayingPosition, new EpisodeNewAdapter.ISelectVideoEpisodeListener() {
|
@Override
|
public void onClick(int position, VideoDetailInfo detailInfo) {
|
VideoDetailInfo videoDetailInfo = detailInfo;
|
mPlayingPosition = position;
|
episodeAdapter.setPlayingPosition(mPlayingPosition);
|
refresh();
|
Playlocation playlocation = new Playlocation();
|
playlocation.setPosition(position);
|
EventBus.getDefault().post(playlocation);
|
getUrl(videoDetailInfo);
|
}
|
});
|
LinearLayoutManager ms = new LinearLayoutManager(getContext());
|
ms.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
rv_episode.setHasFixedSize(true);
|
rv_episode.setNestedScrollingEnabled(false);
|
|
rv_episode.setLayoutManager(ms);
|
rv_episode.addItemDecoration(new SpacesItemDecoration(DimenUtils.dip2px(getContext(), 10)));
|
}
|
|
private void setFollowData(boolean attention) {
|
if (attention) {
|
tv_cancle_follow.setText("已追剧");
|
} else {
|
tv_cancle_follow.setText("追剧");
|
}
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
Log.i(TAG, "onCreateView");
|
EventBus.getDefault().register(this);
|
mVideoInfo = (VideoInfo) getArguments()
|
.getSerializable("video_info");
|
mPlayingPosition = getArguments().getInt("playing_position");
|
mStart = getArguments().getInt("start");
|
mEnd = getArguments().getInt("end");
|
resourceId = getArguments().getString("resourceId");
|
|
|
ll_add_attention = contentView.findViewById(R.id.ll_add_attention);
|
tv_title = contentView.findViewById(R.id.tv_title);
|
tv_score = contentView.findViewById(R.id.tv_score);
|
ll_score = contentView.findViewById(R.id.ll_score);
|
|
tv_score = contentView.findViewById(R.id.tv_score);
|
|
tv_tag = contentView.findViewById(R.id.tv_tag);
|
|
tv_resource = contentView.findViewById(R.id.tv_resource);
|
|
iv_add_to_favourite = contentView.findViewById(R.id.iv_add_to_favourite);
|
|
iv_offline_cache = contentView.findViewById(R.id.iv_offline_cache);
|
|
iv_add_to_favourite.setOnClickListener(this);
|
iv_offline_cache.setOnClickListener(this);
|
tv_resource.setOnClickListener(this);
|
|
|
if (mVideoInfo.getAttention() == null) {
|
ll_add_attention.setVisibility(View.GONE);
|
} else {
|
ll_add_attention.setVisibility(View.VISIBLE);
|
iv_moive_img = contentView.findViewById(R.id.iv_moive_img);
|
tv_star_name = contentView.findViewById(R.id.tv_star_name);
|
tv_update_time = contentView.findViewById(R.id.tv_update_time);
|
tv_cancle_follow = contentView.findViewById(R.id.tv_cancle_follow);
|
try {
|
Glide.with(getActivity()).load(mVideoInfo.getAttention().getMoviePicture())
|
.apply(new RequestOptions().centerCrop().placeholder(R.drawable.ic_default).error(R.drawable.ic_default))
|
.into(iv_moive_img);
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
}
|
tv_star_name.setText(mVideoInfo.getAttention().getMovieName() + "");
|
tv_update_time.setText(mVideoInfo.getAttention().getUpdateInfo() + "");
|
setFollowData(mVideoInfo.getAttention().isAttention());
|
|
tv_cancle_follow.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
SharedPreferences sp = getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
|
String uid = sp.getString("uid", "");
|
String loginid = sp.getString("LoginUid", "");
|
if (StringUtils.isEmpty(loginid)) {
|
Toast.makeText(ll_add_attention.getContext(), "登录成功后才能进行追剧!", Toast.LENGTH_LONG).show();
|
LoginUtil.goLogin(getContext());
|
return;
|
}
|
if (mVideoInfo.getAttention().isAttention()) {//取消关注
|
cancleAttention(uid, loginid);
|
} else {//关注
|
addAttention(uid, loginid);
|
}
|
}
|
});
|
}
|
|
setVideoInfo();
|
|
|
fl_native_ad1 = contentView
|
.findViewById(R.id.fl_native_ad_1);
|
rv_episode = contentView.findViewById(R.id.rv_episode);
|
rv_video_related_video = contentView.findViewById(R.id.rv_video_related_video);
|
rv_video_guess_like = contentView.findViewById(R.id.rv_video_guess_like);
|
rv_video_guess_like.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
DividerItemDecoration decoration = new DividerItemDecoration();
|
decoration.setSize(14);
|
rv_video_guess_like.addItemDecoration(decoration);
|
|
rv_video_guess_like.setHasFixedSize(true);
|
rv_video_guess_like.setNestedScrollingEnabled(false);
|
rv_video_related_video.setHasFixedSize(true);
|
rv_video_related_video.setNestedScrollingEnabled(false);
|
|
|
loadEpisode();
|
refresh();
|
loadAD1();
|
if (mVideoInfo.getVideoDetailList() != null && mVideoInfo.getVideoDetailList().size() > 1) {
|
rv_episode.setVisibility(View.VISIBLE);
|
} else
|
rv_episode.setVisibility(View.GONE);
|
isCollect();
|
initResource();
|
}
|
|
|
public void onEventMainThread(Playlocation playlocation) {
|
mPlayingPosition = playlocation.getPosition();
|
loadEpisode();
|
refresh();
|
}
|
|
private void addAttention(String uid, String loginId) {
|
HttpApiUtil.addAttention(ll_add_attention.getContext(), uid, loginId, mVideoInfo.getId(), new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optBoolean("IsPost")) {
|
SingleToast.showToast(ll_add_attention.getContext(), "追剧成功!");
|
mVideoInfo.getAttention().setAttention(true);
|
setFollowData(mVideoInfo.getAttention().isAttention());
|
|
}
|
}
|
});
|
}
|
|
private void cancleAttention(String uid, String loginId) {
|
HttpApiUtil.cancelAttention(ll_add_attention.getContext(), uid, loginId, mVideoInfo.getId(), new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optBoolean("IsPost")) {
|
SingleToast.showToast(ll_add_attention.getContext(), "取消追剧成功!");
|
mVideoInfo.getAttention().setAttention(false);
|
setFollowData(mVideoInfo.getAttention().isAttention());
|
}
|
}
|
});
|
}
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
}
|
|
@Override
|
public void onDestroyView() {
|
super.onDestroyView();
|
EventBus.getDefault().unregister(this);
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
}
|
|
private void getUrl(VideoDetailInfo info) {
|
SharedPreferences preferences = getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
HttpApiUtil.getPlayUrl(getContext(), uid, info.getType(), mVideoInfo.getId(),
|
info.getId(), resourceId, info.geteId(),
|
new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
|
VideoResource resource = JsonUtil.videoGson.fromJson(
|
jsonObject.getJSONObject("Data")
|
.getJSONObject("Resource")
|
.toString(),
|
new TypeToken<VideoResource>() {
|
}.getType());
|
PlayUrl info = new PlayUrl();
|
info.setResource(resource);
|
info.setPlayType(Integer.parseInt(jsonObject
|
.getJSONObject("Data")
|
.optString("PlayType")));
|
info.setUrl(jsonObject.getJSONObject("Data")
|
.optString("Url"));
|
info.setParams(jsonObject.getJSONObject("Data")
|
.optString("Params"));
|
Play play = new Play();
|
play.setPlayUrl(info);
|
EventBus.getDefault().post(play);
|
} else {
|
Toast.makeText(getContext(), jsonObject.optString("Error"), Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString, throwable);
|
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
}
|
});
|
}
|
|
public boolean isPlaying() {
|
return mStart <= mPlayingPosition && mPlayingPosition < mEnd;
|
}
|
|
/**
|
* 刷新adapter
|
*/
|
public void refresh() {
|
if (rv_episode.getAdapter() != null)
|
rv_episode.getAdapter().notifyDataSetChanged();
|
else
|
rv_episode.postDelayed(new Runnable() {
|
@Override
|
public void run() {
|
Log.i(TAG, "refresh");
|
rv_episode.setAdapter(episodeAdapter);
|
if (mPlayingPosition > 4)
|
rv_episode.scrollToPosition(mPlayingPosition);
|
}
|
}, 500);
|
|
|
}
|
|
// 加载播放页第一条广告,先设置加载上下文环境和条件
|
private void loadAD1() {
|
ExpressAdManager expressAdManager = null;
|
try {
|
expressAdManager = new ExpressAdManager(getContext());
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
if (expressAdManager == null)
|
return;
|
|
expressAdManager.loadVideoDetailPlayerBottomAd(new ExpressAdManager.IAdLoadListener() {
|
@Override
|
public void onSuccess(List<ExpressAdContainer> adList) {
|
if (adList != null && adList.size() > 0) {
|
fl_native_ad1.setVisibility(View.VISIBLE);
|
final ExpressAdContainer ad = adList.get(0);
|
if (getActivity() == null)
|
return;
|
|
ExpressAdManager.renderAd(getActivity(), adList.get(0), new ExpressAdManager.IAdRenderListener() {
|
@Override
|
public void onRenderSuccess(List<ExpressAdContainer> adList) {
|
ExpressAdManager.fillAd(adList.get(0), fl_native_ad1);
|
}
|
|
@Override
|
public void onRenderFail(List<ExpressAdContainer> adList) {
|
|
}
|
}, new ExpressAdManager.IAdEventListener() {
|
@Override
|
public void closeAd(ExpressAdContainer ad) {
|
fl_native_ad1.removeAllViews();
|
}
|
});
|
|
} else {
|
fl_native_ad1.setVisibility(View.GONE);
|
}
|
}
|
});
|
}
|
|
List<VideoResource> urlList;
|
VideoResource selectedUrl = null;
|
private PopupWindow popupWindow;
|
|
private void initResource() {
|
urlList = mVideoInfo.getResourceList();
|
selectedUrl = VideoUtil.getSelectedResource(urlList);
|
if (mVideoInfo.getResourceList() != null
|
&& mVideoInfo.getResourceList().size() > 0) {
|
tv_resource.setVisibility(View.VISIBLE);
|
|
if (selectedUrl == null || selectedUrl.getPicture() == null) {
|
tv_resource.setText("来源:其他");
|
} else {
|
tv_resource.setText("来源:" + selectedUrl.getName());
|
}
|
popupWindow = new PopupWindow(
|
DimenUtils.dip2px(getContext(), 93),
|
WindowManager.LayoutParams.WRAP_CONTENT);
|
popupWindow.setOutsideTouchable(true);// 点击外部可点击
|
popupWindow.setBackgroundDrawable(new ColorDrawable(0));// 设置背景
|
popupWindow.setAnimationStyle(R.style.PopupAnimation);
|
popupWindow.setFocusable(true);// 获取焦点
|
|
FrameLayout fl = new FrameLayout(getContext());
|
fl.setLayoutParams(new FrameLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
|
|
ListView lv = new ListView(getContext());
|
ListView.LayoutParams param = new ListView.LayoutParams(
|
FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
|
lv.setLayoutParams(param);
|
lv.setAdapter(new VideoDetailActivity.ResourceAdapter(urlList, getContext(), new VideoDetailActivity.IResourceClickListener() {
|
@Override
|
public void onClick(int index, VideoResource videoResource) {
|
if (popupWindow.isShowing()) {
|
popupWindow.dismiss();
|
}
|
if (selectedUrl.getId() != urlList.get(index).getId()) {
|
resourceId = urlList.get(index).getId();
|
EventBus.getDefault().post(urlList.get(index));
|
EventBus.getDefault().post(new VideoDetailActivity.ChangeVideoEvent(mVideoInfo));
|
|
}
|
selectedUrl = urlList.get(index);
|
if (selectedUrl == null || selectedUrl.getPicture() == null) {
|
tv_resource.setText("来源:其他");
|
} else {
|
tv_resource.setText("来源:" + selectedUrl.getName());
|
}
|
}
|
}));
|
lv.setDivider(new ColorDrawable(Color.WHITE));
|
lv.setDividerHeight(1);
|
fl.setPadding(DimenUtils.dip2px(getContext(), 8), 0, DimenUtils.dip2px(getContext(), 8), 0);
|
|
GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
|
new int[]{getResources().getColor(R.color.theme), getResources().getColor(R.color.theme)});
|
int radius = DimenUtils.dip2px(getContext(), 5);
|
gd.setCornerRadii(new float[]{radius, radius, radius, radius, 0, 0, 0, 0});
|
fl.setBackground(gd);
|
fl.addView(lv);
|
popupWindow.setContentView(fl);
|
/*
|
* Window dialogWindow = dialog.getWindow(); dialogWindow.get
|
*/
|
} else {
|
tv_resource.setVisibility(View.GONE);
|
}
|
|
}
|
|
|
@Override
|
public void onClick(View v) {
|
SharedPreferences preferences = getContext()
|
.getSharedPreferences("user", Context.MODE_PRIVATE);
|
switch (v.getId()) {
|
case R.id.tv_resource:
|
if (popupWindow == null)
|
return;
|
if (popupWindow.isShowing()) {
|
// bug:listview 中的isShowing()可以正确获取而到了这里就一直不进入,原因是pop没设置焦点获取
|
popupWindow.dismiss();
|
} else {// 出现在线下,并且居右
|
if (selectedUrl == null || selectedUrl.getPicture() == null) {
|
|
} else {
|
int y = 0;
|
y += mVideoInfo.getResourceList().size() * DimenUtils.dip2px(getContext(), 30);
|
y += tv_resource.getHeight();
|
popupWindow.showAsDropDown(v, 0, 0 - y);
|
}
|
}
|
break;
|
|
case R.id.iv_offline_cache:
|
Toast.makeText(getContext(), "暂时无法缓存!", Toast.LENGTH_SHORT).show();
|
break;
|
case R.id.iv_share:
|
String shareContent = getShareContent();
|
UMWeb web = new UMWeb(getShareUrl());
|
String shareTitle = getResources().getString(R.string.app_name);
|
web.setTitle(shareTitle);
|
web.setDescription(shareContent);
|
new ShareAction(getActivity()).withText(shareContent).withMedia(web)
|
.setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN)
|
.setCallback(new UMShareListener() {
|
@Override
|
public void onStart(SHARE_MEDIA share_media) {
|
|
}
|
|
@Override
|
public void onResult(SHARE_MEDIA share_media) {
|
|
}
|
|
@Override
|
public void onError(SHARE_MEDIA share_media, Throwable throwable) {
|
|
}
|
|
@Override
|
public void onCancel(SHARE_MEDIA share_media) {
|
|
}
|
}).open();
|
break;
|
case R.id.iv_add_to_favourite:
|
final String loginUid = UserUtil.getLoginUid(getContext());
|
if (StringUtils.isEmpty(loginUid)) {
|
SingleToast.showToast(getContext(), "登录后才能收藏");
|
LoginUtil.goLogin(getContext());
|
break;
|
}
|
HttpApiUtil.isCollect(getContext(), UserUtil.getLoginUid(getContext()), mVideoInfo.getId(),
|
mVideoInfo.getThirdType(),
|
new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
getScoreCollect(loginUid, "0", mVideoInfo.getThirdType());
|
} else {
|
getScoreCollect(loginUid, "1", mVideoInfo.getThirdType());
|
}
|
}
|
});
|
break;
|
|
|
}
|
}
|
|
/**
|
* 收藏
|
*
|
* @param type
|
* @param thirdType
|
*/
|
private void getScoreCollect(String loginUid, final String type, String thirdType) {
|
SharedPreferences preferences = getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
HttpApiUtil.collectVideo(getContext(), uid, loginUid, mVideoInfo.getId(),
|
thirdType, type, new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
if (type.equals("1")) {
|
SingleToast.showToast(getContext(), "收藏成功");
|
} else {
|
SingleToast.showToast(getContext(), "取消收藏成功");
|
}
|
} else {
|
if (type.equals("1")) {
|
SingleToast.showToast(getContext(), "收藏失败");
|
} else {
|
SingleToast.showToast(getContext(), "取消收藏失败");
|
}
|
}
|
isCollect();
|
}
|
});
|
}
|
|
private void isCollect() {
|
HttpApiUtil.isCollect(iv_add_to_favourite.getContext(), UserUtil.getLoginUid(getContext()), mVideoInfo.getId(),
|
mVideoInfo.getThirdType(), new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
iv_add_to_favourite.setImageResource(R.drawable.ic_video_detail_favourite2);
|
} else {
|
iv_add_to_favourite.setImageResource(R.drawable.ic_video_detail_favourite1);
|
}
|
}
|
});
|
}
|
|
|
private String getShareContent() {
|
return "我在" + iv_add_to_favourite.getContext().getResources().getString(R.string.app_name)
|
+ "看了《" + mVideoInfo.getName()
|
+ "》影片,非常不错,大家一起来看吧!" + getShareUrl();
|
}
|
|
private String getShareUrl() {
|
SharedPreferences preferences = iv_add_to_favourite.getContext().getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
return preferences.getString("share_url", "http://yy.umgotv.com");
|
}
|
|
|
public void onEventMainThread(VideoInfo videoInfo) {
|
mVideoInfo = videoInfo;
|
if (mVideoInfo.getVideoDetailList() != null && mVideoInfo.getVideoDetailList().size() > 1) {
|
rv_episode.setVisibility(View.VISIBLE);
|
} else
|
rv_episode.setVisibility(View.GONE);
|
rv_episode.setAdapter(episodeAdapter);
|
}
|
|
|
private void getRelativeVideos() {
|
SharedPreferences preferences = getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
HttpApiUtil.getRelativeVideos(getContext(), uid,
|
mVideoInfo.getId(), new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
|
final List<VideoInfo> videoInfos = JsonUtil.videoGson.fromJson(
|
jsonObject.getJSONObject("Data")
|
.getJSONArray("data").toString(),
|
new TypeToken<List<VideoInfo>>() {
|
}.getType());
|
|
if (videoInfos == null || videoInfos.size() == 0) {
|
} else {
|
final VideoColumn2Adapter adapter = new VideoColumn2Adapter(getActivity(), getContext(), videoInfos, false, 2, new IVideoClickListener() {
|
@Override
|
public void onClick(VideoInfo video) {
|
VideoDetailActivity.ChangeVideoEvent changeVideoEvent = new VideoDetailActivity.ChangeVideoEvent();
|
changeVideoEvent.setVideoInfo(video);
|
changeVideoEvent.setTag("VideoPlayerFragment");
|
tv_resource.postDelayed(new Runnable() {
|
@Override
|
public void run() {
|
EventBus.getDefault().post(changeVideoEvent);
|
}
|
}, 500);
|
|
}
|
});
|
adapter.initRecyclerViewDisplayWidthColumn2(rv_video_related_video);
|
|
if (getActivity() == null)
|
return;
|
getActivity().runOnUiThread(new Runnable() {
|
@Override
|
public void run() {
|
if (rv_video_related_video != null) {
|
rv_video_related_video.setAdapter(adapter);
|
}
|
}
|
});
|
}
|
}
|
}
|
});
|
}
|
|
|
private void guessLike() {
|
SharedPreferences preferences = getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
HttpApiUtil.guessLike(getContext(), uid, mVideoInfo.getId(),
|
new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
|
List<VideoInfo> videoInfos = JsonUtil.videoGson.fromJson(
|
jsonObject.getJSONObject("Data")
|
.getJSONArray("data").toString(),
|
new TypeToken<List<VideoInfo>>() {
|
}.getType());
|
|
List<VideoContent> list = new ArrayList<>();
|
for (VideoInfo video : videoInfos) {
|
list.add(VideoContent.createVideoContent(video));
|
}
|
|
final VideoCloumn1Adapter adapter = new VideoCloumn1Adapter(getActivity(), list, new IVideoClickListener() {
|
@Override
|
public void onClick(VideoInfo video) {
|
VideoDetailActivity.ChangeVideoEvent changeVideoEvent = new VideoDetailActivity.ChangeVideoEvent();
|
changeVideoEvent.setVideoInfo(video);
|
changeVideoEvent.setTag("VideoPlayerFragment");
|
EventBus.getDefault().post(changeVideoEvent);
|
}
|
});
|
// adapter.initRecyclerViewDisplayWidthColumn1(rv_video_guess_like);
|
if (getActivity() != null)
|
getActivity().runOnUiThread(new Runnable() {
|
@Override
|
public void run() {
|
if (rv_video_guess_like != null)
|
rv_video_guess_like
|
.setAdapter(adapter);
|
}
|
});
|
}
|
}
|
});
|
}
|
|
|
}
|