package com.weikou.beibeivideo.ui.media;
|
|
import android.app.ProgressDialog;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.database.Cursor;
|
import android.graphics.Bitmap;
|
import android.graphics.Color;
|
import android.graphics.Rect;
|
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.Drawable;
|
import android.os.Bundle;
|
import android.os.Handler;
|
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.RecyclerView;
|
import android.text.SpannableString;
|
import android.text.Spanned;
|
import android.text.style.ForegroundColorSpan;
|
import android.util.Log;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.AdapterView;
|
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.BaseAdapter;
|
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.FieldNamingPolicy;
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.reflect.TypeToken;
|
import com.lcjian.library.RetainViewFragment;
|
import com.lcjian.library.util.SingleToast;
|
import com.lcjian.library.util.common.DimenUtils;
|
import com.lcjian.library.util.common.StringUtils;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
import com.umeng.socialize.ShareAction;
|
import com.umeng.socialize.UMShareAPI;
|
import com.umeng.socialize.UMShareListener;
|
import com.umeng.socialize.bean.SHARE_MEDIA;
|
import com.umeng.socialize.media.UMWeb;
|
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
|
import com.weikou.beibeivideo.BeibeiVideoAPI;
|
import com.weikou.beibeivideo.BeibeiVideoApplication;
|
import com.weikou.beibeivideo.R;
|
import com.weikou.beibeivideo.db.WatchHistoryTable;
|
import com.weikou.beibeivideo.entity.Follow;
|
import com.weikou.beibeivideo.entity.Play;
|
import com.weikou.beibeivideo.entity.PlayUrl;
|
import com.weikou.beibeivideo.entity.Playlocation;
|
import com.weikou.beibeivideo.entity.VideoDetailInfo;
|
import com.weikou.beibeivideo.entity.VideoInfo;
|
import com.weikou.beibeivideo.entity.VideoResource;
|
import com.weikou.beibeivideo.entity.ad.ExpressAdContainer;
|
import com.weikou.beibeivideo.entity.video.FunshionPlayInfo;
|
import com.weikou.beibeivideo.ui.login.LoginActivity;
|
import com.weikou.beibeivideo.ui.video.EpisodeNewAdapter;
|
import com.weikou.beibeivideo.util.BeibeiConstant;
|
import com.weikou.beibeivideo.util.UserUtil;
|
import com.weikou.beibeivideo.util.VideoUtil;
|
import com.weikou.beibeivideo.util.ad.AdUtil;
|
import com.weikou.beibeivideo.util.ad.ExpressAdManager;
|
|
import org.apache.http.Header;
|
import org.json.JSONArray;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
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;
|
|
private LinearLayout fl_report;
|
private ImageView iv_favourite;
|
|
private ImageView iv_moive_img;
|
|
private TextView tv_star_name, tv_update_time, tv_cancle_follow, tv_video_resource, tv_title, tv_score, tv_play_num;
|
|
private LinearLayout ll_add_attention;
|
|
private FrameLayout fl_native_ad1;
|
|
private EpisodeNewAdapter episodeAdapter;
|
|
final String TAG = "EpisodeFragment";
|
|
private boolean episodeLoading = false;//剧集是否正在加载更多
|
|
private boolean episodeHasMore = true;//是否还有更多的剧集
|
|
private int episodePage = 2;//当前页
|
|
private String fromName = null;
|
|
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, int start, int end, String from) {
|
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("from", from);
|
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());
|
tv_score.setVisibility(View.VISIBLE);
|
} else {
|
tv_score.setVisibility(View.GONE);
|
}
|
tv_play_num.setText("播放:" + VideoUtil.getWatchCountShortName(mVideoInfo.getWatchCount()));
|
}
|
|
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 == VideoUtil.videoEpisodeList.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) {
|
setEpisodeSelected(position);
|
getUrl(detailInfo);
|
}
|
});
|
LinearLayoutManager ms = new LinearLayoutManager(getContext());
|
ms.setOrientation(LinearLayoutManager.HORIZONTAL);
|
rv_episode.setHasFixedSize(true);
|
rv_episode.setNestedScrollingEnabled(false);
|
if (rv_episode.getLayoutManager() == null)
|
rv_episode.setLayoutManager(ms);
|
|
if (rv_episode.getItemDecorationCount() == 0)
|
rv_episode.addItemDecoration(new SpacesItemDecoration(DimenUtils.dip2px(getContext(), 10)));
|
}
|
|
|
//设置选中状态
|
private void setEpisodeSelected(int position) {
|
mPlayingPosition = position;
|
episodeAdapter.setPlayingPosition(mPlayingPosition);
|
refresh();
|
Playlocation playlocation = new Playlocation();
|
playlocation.setPosition(position);
|
EventBus.getDefault().post(playlocation);
|
}
|
|
private void setFollowData(boolean attention) {
|
tv_cancle_follow.setBackgroundResource(R.drawable.shape_video_detail_follow_btn);
|
tv_cancle_follow.setTextColor(getResources().getColor(R.color.video_detail_follow_text_color));
|
if (attention) {
|
tv_cancle_follow.setText("已关注");
|
tv_cancle_follow.setCompoundDrawables(null, null, null, null);
|
} else {
|
tv_cancle_follow.setText("关注");
|
Drawable drawable = getResources().getDrawable(R.drawable.ic_follow_add_w);
|
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
|
tv_cancle_follow.setCompoundDrawables(drawable, null, null, null);
|
}
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
Log.i(TAG, "onCreateView");
|
Bundle bundle = getArguments();
|
mVideoInfo = (VideoInfo) bundle
|
.getSerializable("video_info");
|
fromName = bundle
|
.getString("from", "");
|
|
mPlayingPosition = bundle.getInt("playing_position");
|
mStart = bundle.getInt("start");
|
mEnd = bundle.getInt("end");
|
|
if (bundle != null)
|
bundle.clear();
|
|
//防止没有内容崩溃
|
if (mVideoInfo == null)
|
return;
|
|
tv_video_resource = contentView.findViewById(R.id.tv_video_resource);
|
ll_add_attention = contentView.findViewById(R.id.ll_add_attention);
|
ll_add_attention.setBackgroundResource(R.drawable.shape_video_detail_follow_bg);
|
tv_title = contentView.findViewById(R.id.tv_title);
|
tv_score = contentView.findViewById(R.id.tv_score);
|
tv_play_num = contentView.findViewById(R.id.tv_play_num);
|
|
|
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().getApplicationContext()).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();
|
getContext().startActivity(new Intent(ll_add_attention.getContext(), LoginActivity.class));
|
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);
|
|
contentView.findViewById(R.id.iv_share).setOnClickListener(this);
|
contentView.findViewById(R.id.iv_offline_cache).setOnClickListener(this);
|
fl_report = contentView.findViewById(R.id.fl_report);
|
iv_favourite = contentView.findViewById(R.id.iv_add_to_favourite);
|
fl_report.setOnClickListener(this);
|
iv_favourite.setOnClickListener(this);
|
loadEpisode();
|
refresh();
|
isCollect();
|
loadAD1();
|
setFrom(mVideoInfo);
|
if (VideoUtil.videoEpisodeList != null && VideoUtil.videoEpisodeList.size() > 1) {
|
rv_episode.setVisibility(View.VISIBLE);
|
} else
|
rv_episode.setVisibility(View.GONE);
|
|
//
|
rv_episode.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
@Override
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
super.onScrollStateChanged(recyclerView, newState);
|
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
|
int first = manager.findFirstVisibleItemPosition();
|
int last = manager.findLastVisibleItemPosition();
|
int total = manager.getItemCount();
|
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
if (mVideoInfo == null)
|
return;
|
if (!episodeLoading && episodeHasMore && last == total - 1) {//加载更多
|
VideoResource checkedResource = null;
|
for (VideoResource vr : mVideoInfo.getResourceList()) {
|
checkedResource = vr;
|
break;
|
}
|
if (checkedResource != null) {
|
loadMoreEpisode(mVideoInfo.getId(), checkedResource.getId(), episodePage);
|
}
|
}
|
}
|
}
|
|
@Override
|
public void onScrolled(RecyclerView recyclerView, int dx, final int dy) {
|
super.onScrolled(recyclerView, dx, dy);
|
}
|
});
|
|
|
EventBus.getDefault().register(this);
|
}
|
|
|
public void onEventMainThread(Playlocation playlocation) {
|
mPlayingPosition = playlocation.getPosition();
|
// loadEpisode();
|
refresh();
|
}
|
|
|
public void onEventMainThread(FunshionPlayInfo info) {
|
Log.i(TAG, "风行选集:" + info.getPosition());
|
mPlayingPosition = info.getPosition();
|
episodeAdapter.setPlayingPosition(mPlayingPosition);
|
refresh();
|
rv_episode.scrollToPosition(mPlayingPosition);
|
}
|
|
private void addAttention(String uid, String loginId) {
|
BeibeiVideoAPI.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) {
|
BeibeiVideoAPI.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() {
|
Log.i(TAG, "onResume:");
|
super.onResume();
|
}
|
|
@Override
|
public void onDestroyView() {
|
Log.i(TAG, "onDestroyView:");
|
super.onDestroyView();
|
|
}
|
|
@Override
|
public void onDestroy() {
|
super.onDestroy();
|
EventBus.getDefault().unregister(this);
|
}
|
|
@Override
|
public void onPause() {
|
Log.i(TAG, "onPause");
|
super.onPause();
|
}
|
|
private void getUrl(VideoDetailInfo info) {
|
SharedPreferences preferences = getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
BeibeiVideoAPI.getPlayUrl(getContext(), uid, info.getType(), mVideoInfo.getId(),
|
info.getId(), selectedUrl.getId(), info.geteId(),
|
new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE)
|
.create();
|
VideoResource resource = gson.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"));
|
info.setAid(jsonObject.getJSONObject("Data")
|
.optString("Aid"));
|
info.setVid(jsonObject.getJSONObject("Data")
|
.optString("Vid"));
|
info.setCode(jsonObject.getJSONObject("Data")
|
.optString("Code"));
|
Play play = new Play();
|
play.setPlayUrl(info);
|
EventBus.getDefault().post(play);
|
}
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString, throwable);
|
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
if (pd != null && pd.isShowing())
|
pd.dismiss();
|
}
|
});
|
}
|
|
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() {
|
new ExpressAdManager(AdUtil.AD_TYPE.gdt2, getContext()).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 {
|
//加载穿山甲
|
new ExpressAdManager(AdUtil.AD_TYPE.csj, getContext()).loadVideoDetailPlayerBottomAd(new ExpressAdManager.IAdLoadListener() {
|
@Override
|
public void onSuccess(List<ExpressAdContainer> adList) {
|
if (adList != null && adList.size() > 0) {
|
ExpressAdManager.renderAndFillAd(getActivity(), adList.get(0), fl_native_ad1, new ExpressAdManager.IAdEventListener() {
|
@Override
|
public void closeAd(ExpressAdContainer ad) {
|
fl_native_ad1.removeAllViews();
|
}
|
});
|
} else {
|
fl_native_ad1.setVisibility(View.GONE);
|
}
|
}
|
});
|
}
|
}
|
});
|
}
|
|
|
@Override
|
public void onClick(View v) {
|
SharedPreferences preferences = getContext()
|
.getSharedPreferences("user", Context.MODE_PRIVATE);
|
switch (v.getId()) {
|
case R.id.iv_add_to_favourite:
|
final String loginUid = preferences.getString("LoginUid", "");
|
if (StringUtils.isEmpty(loginUid)) {
|
SingleToast.showToast(ll_add_attention.getContext(), "登录后才能收藏");
|
startActivity(new Intent(ll_add_attention.getContext(), LoginActivity.class));
|
break;
|
}
|
String uid = preferences.getString("uid", "");
|
BeibeiVideoAPI.isCollect(getContext(), uid, 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;
|
case R.id.fl_report:
|
if (popupWindow.isShowing()) {
|
// bug:listview 中的isShowing()可以正确获取而到了这里就一直不进入,原因是pop没设置焦点获取
|
popupWindow.dismiss();
|
} else {// 出现在线下,并且居右
|
if (selectedUrl == null || selectedUrl.getPicture() == null) {
|
|
} else {
|
popupWindow.showAsDropDown(v, 0, 0);
|
}
|
}
|
break;
|
case R.id.iv_offline_cache:
|
Toast.makeText(ll_add_attention.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(shareListener).open();
|
}
|
}
|
|
UMShareListener shareListener = new UMShareListener() {
|
@Override
|
public void onStart(SHARE_MEDIA share_media) {
|
|
}
|
|
@Override
|
public void onResult(SHARE_MEDIA share_media) {
|
Toast.makeText(iv_favourite.getContext(), "分享成功!", Toast.LENGTH_LONG).show();
|
}
|
|
@Override
|
public void onError(SHARE_MEDIA share_media, Throwable throwable) {
|
if (!UMShareAPI.get(ll_add_attention.getContext()).isInstall(getActivity(), share_media)) {
|
Toast.makeText(iv_favourite.getContext(), share_media == SHARE_MEDIA.QQ ? "没有安装QQ" : "没有安装微信", Toast.LENGTH_LONG).show();
|
} else {
|
Toast.makeText(iv_favourite.getContext(), "分享出错!", Toast.LENGTH_LONG).show();
|
}
|
}
|
|
@Override
|
public void onCancel(SHARE_MEDIA share_media) {
|
Toast.makeText(iv_favourite.getContext(), "分享取消!", Toast.LENGTH_LONG).show();
|
}
|
};
|
|
private String getShareContent() {
|
return "我在" + iv_favourite.getContext().getResources().getString(R.string.app_name)
|
+ "看了《" + mVideoInfo.getName()
|
+ "》影片,非常不错,大家一起来看吧!" + getShareUrl();
|
}
|
|
private String getShareUrl() {
|
SharedPreferences preferences = iv_favourite.getContext().getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
return preferences.getString("share_url", "http://yy.umgotv.com");
|
}
|
|
List<VideoResource> urlList;
|
VideoResource selectedUrl = null;
|
|
public void onEventMainThread(VideoInfo videoInfo) {
|
mVideoInfo = videoInfo;
|
if (VideoUtil.videoEpisodeList != null && VideoUtil.videoEpisodeList.size() > 1) {
|
rv_episode.setVisibility(View.VISIBLE);
|
} else
|
rv_episode.setVisibility(View.GONE);
|
setFrom(videoInfo);
|
iv_favourite.setEnabled(true);
|
fl_report.setEnabled(true);
|
rv_episode.setAdapter(episodeAdapter);
|
|
}
|
|
private void setFrom(VideoInfo info) {
|
if (urlList == null)
|
urlList = new ArrayList<VideoResource>();
|
urlList.clear();
|
for (int i = 0; i < info.getResourceList().size(); i++) {
|
if (info.getResourceList().get(i).isChecked()) {
|
selectedUrl = info.getResourceList().get(i);
|
}
|
}
|
EventBus.getDefault().post(selectedUrl);
|
iv_favourite.postDelayed(new Runnable() {
|
|
@Override
|
public void run() {
|
EventBus.getDefault().post(selectedUrl);
|
}
|
}, 1000);
|
urlList.addAll(info.getResourceList());
|
initResource();
|
}
|
|
private PopupWindow popupWindow;
|
|
private ProgressDialog pd;
|
|
private void setResource(String resource) {
|
SpannableString st = new SpannableString(resource);
|
st.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.video_detail_resource_text_color)), 3, resource.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
tv_video_resource.setText(st);
|
}
|
|
private void initResource() {
|
|
if (mVideoInfo.getResourceList() != null
|
&& mVideoInfo.getResourceList().size() > 0) {
|
tv_video_resource.setVisibility(View.VISIBLE);
|
String resource = "";
|
if (selectedUrl == null || selectedUrl.getPicture() == null) {
|
resource = "来源:其他";
|
} else {
|
resource = "来源:" + selectedUrl.getName();
|
}
|
setResource(resource);
|
|
popupWindow = new PopupWindow(
|
com.weikou.beibeivideo.util.DimenUtils.dip2px(getContext(), 120),
|
android.view.WindowManager.LayoutParams.WRAP_CONTENT);
|
popupWindow.setOutsideTouchable(true);// 点击外部可点击
|
popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_video_detail_resource_bg));
|
popupWindow.setAnimationStyle(R.style.PopupAnimation);
|
popupWindow.setFocusable(true);// 获取焦点
|
|
ListView lv = new ListView(getContext());
|
ListView.LayoutParams param = new ListView.LayoutParams(
|
FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
|
lv.setLayoutParams(param);
|
lv.setBackground(getResources().getDrawable(R.drawable.shape_video_detail_resource_bg));
|
|
lv.setOnItemClickListener(new OnItemClickListener() {
|
@Override
|
public void onItemClick(AdapterView<?> parent, View view,
|
int position, long id) {
|
if (popupWindow.isShowing()) {
|
popupWindow.dismiss();
|
}
|
if (selectedUrl.getId() != urlList.get(position).getId()) {
|
pd = new ProgressDialog(ll_add_attention.getContext());
|
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);// 设置进度条的形式为圆形转动的进度条
|
pd.setCancelable(true);// 设置是否可以通过点击Back键取消
|
pd.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
|
pd.setMessage("网络加载中·······");
|
pd.show();
|
getVideoDetail(mVideoInfo.getId(), urlList
|
.get(position).getId(), mVideoInfo
|
.getThirdType(), true, fromName);
|
}
|
selectedUrl = urlList.get(position);
|
if (selectedUrl == null || selectedUrl.getPicture() == null) {
|
setResource("来源:其他");
|
} else {
|
setResource("来源:" + selectedUrl.getName());
|
}
|
|
}
|
});
|
lv.setAdapter(new ResourceAdapter(urlList));
|
lv.setDividerHeight(0);
|
popupWindow.setContentView(lv);
|
/*
|
* Window dialogWindow = dialog.getWindow(); dialogWindow.get
|
*/
|
} else {
|
tv_video_resource.setVisibility(View.GONE);
|
}
|
|
}
|
|
private class ResourceAdapter extends BaseAdapter {
|
List<VideoResource> reList;
|
|
public ResourceAdapter(List<VideoResource> list) {
|
reList = list;
|
}
|
|
@Override
|
public int getCount() {
|
return reList.size();
|
}
|
|
@Override
|
public Object getItem(int position) {
|
return reList.get(position);
|
}
|
|
@Override
|
public long getItemId(int position) {
|
return position;
|
}
|
|
@Override
|
public View getView(int position, View convertView, ViewGroup parent) {
|
View view = LayoutInflater.from(ll_add_attention.getContext()).inflate(
|
R.layout.item_resource, null);
|
ImageView iv = view.findViewById(R.id.iv_resource);
|
TextView tv = view.findViewById(R.id.tv_resource);
|
try {
|
Glide.with(getActivity().getApplicationContext())
|
.load(reList.get(position).getPicture())
|
.apply(new RequestOptions().placeholder(R.drawable.from_other).error(R.drawable.from_other))
|
.into(iv);
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
}
|
if (reList.get(position) == null
|
|| StringUtils.isEmpty(reList.get(position).getName())) {
|
tv.setText("其它");
|
} else {
|
tv.setText(reList.get(position).getName());
|
}
|
return view;
|
}
|
}
|
|
private void getVideoDetail(String videoId, final String resourceId,
|
String videoThirdType, final boolean isSetup, final String from) {
|
SharedPreferences preferences = getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
String loginid = preferences.getString("LoginUid", "");
|
BeibeiVideoAPI.getVideoDetail(getContext(), uid, resourceId, videoId, null, loginid,
|
videoThirdType, from, new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onStart() {
|
super.onStart();
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers,
|
String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString,
|
throwable);
|
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
if (pd != null && pd.isShowing())
|
pd.dismiss();
|
}
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
try {
|
if (getActivity().isDestroyed()) {
|
return;
|
}
|
} catch (NoSuchMethodError e) {
|
e.printStackTrace();
|
}
|
if (jsonObject.getBoolean("IsPost")) {
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE)
|
.create();
|
|
final VideoInfo videoInfo = gson
|
.fromJson(jsonObject.getJSONObject("Data")
|
.toString(),
|
new TypeToken<VideoInfo>() {
|
}.getType());
|
if (videoInfo != null) {
|
|
VideoUtil.saveVideoEpisodeList(BeibeiVideoApplication.application, videoInfo.getVideoDetailList(), false);
|
|
}
|
// 附加字段
|
if (jsonObject.optJSONObject("Extra1") != null) {
|
if (jsonObject.optJSONObject("Extra1").optJSONObject("Attention") != null) {
|
JSONObject obj = jsonObject.optJSONObject("Extra1").optJSONObject("Attention");
|
Follow attention = new Follow();
|
attention.setMovieName(obj.optString("Name"));
|
attention.setMoviePicture(obj.optString("Picture"));
|
attention.setUpdateInfo(obj.optString("UpdateInfo"));
|
attention.setAttention(Boolean.parseBoolean(obj.optString("Name")));
|
videoInfo.setAttention(attention);
|
}
|
}
|
JSONArray extraData = jsonObject
|
.optJSONArray("Extra");
|
if (extraData != null)
|
videoInfo.setExtraData(extraData.toString());
|
|
if (VideoUtil.videoEpisodeList == null
|
|| VideoUtil.videoEpisodeList.isEmpty()) {
|
Toast.makeText(getContext(), "影片已删除",
|
Toast.LENGTH_LONG).show();
|
getActivity().finish();
|
return;
|
}
|
|
if (rv_episode.getAdapter() != null)
|
rv_episode.getAdapter().notifyDataSetChanged();
|
// videoInfo.setSave(jsonObject.getJSONObject("Data").optBoolean("Save"));
|
if (isSetup) {
|
VideoUtil.saveVideoEpisodeList(BeibeiVideoApplication.application, videoInfo.getVideoDetailList(), false);
|
|
EventBus.getDefault().post(videoInfo);
|
int position = 0;
|
// boolean isFromWatchHistory = false;
|
// isFromWatchHistory = getArguments().getBoolean("isFromWatchHistory", false);// 是否从观看记录点击过来
|
Cursor cursor = rv_episode.getContext().getContentResolver().query(
|
WatchHistoryTable.CONTENT_URI, null,
|
WatchHistoryTable.VIDEO_ID + " = ? ",
|
new String[]{videoInfo.getId()}, null);
|
// Cursor cursor = getActivity().getConentResolver().query(WatchHistoryTable.CONTENT_URI, null, WatchHistoryTable.VIDEO_ID + " = ? ", new String[]{videoInfo.getId()}, null);
|
cursor.moveToFirst();
|
String cResoureId = cursor.getString(cursor.getColumnIndex(WatchHistoryTable.VIDEO_RESOURCE_ID));
|
cursor.close();
|
if (resourceId.equalsIgnoreCase(cResoureId) && getActivity() != null) {
|
position = getActivity().getIntent().getIntExtra(
|
"playing_position", 0);
|
}
|
// if (isFromWatchHistory) {
|
getUrl(VideoUtil.videoEpisodeList.get(position));
|
EventBus.getDefault()
|
.post(VideoUtil.videoEpisodeList
|
.get(position));
|
// } else {// 不是从观看记录点击过来 --跳到当前播放的集数
|
// getUrl(videoInfo.getVideoDetailList().get(position));
|
// EventBus.getDefault().post(
|
// videoInfo.getVideoDetailList().get(
|
// position));
|
// }
|
} else {
|
iv_favourite.postDelayed(new Runnable() {
|
|
@Override
|
public void run() {
|
EventBus.getDefault().post(videoInfo);
|
EventBus.getDefault().post(
|
VideoUtil.videoEpisodeList
|
.get(0));
|
}
|
}, 200);
|
}
|
}
|
}
|
});
|
}
|
|
/**
|
* 收藏
|
*
|
* @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", "");
|
BeibeiVideoAPI.getScoreCollect(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() {
|
SharedPreferences preferences = iv_favourite.getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
BeibeiVideoAPI.isCollect(iv_favourite.getContext(), uid, mVideoInfo.getId(),
|
mVideoInfo.getThirdType(), new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
iv_favourite.setImageResource(R.drawable.ic_video_detail_favourite2);
|
} else {
|
iv_favourite.setImageResource(R.drawable.ic_video_detail_favourite1);
|
}
|
}
|
});
|
}
|
|
/**
|
* 加载更多剧集
|
*
|
* @param videoId
|
* @param resourceId
|
*/
|
private synchronized void loadMoreEpisode(String videoId, String resourceId, int page) {
|
BeibeiVideoAPI.getVideoEpisodeList(ll_add_attention.getContext(), UserUtil.getUid(getContext()), resourceId, videoId, page, new
|
|
BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws
|
Exception {
|
if (jsonObject.optBoolean("IsPost")) {
|
JSONObject data = jsonObject.optJSONObject("Data");
|
episodeHasMore = data.optBoolean("hasMore");
|
JSONArray array = data.optJSONArray("list");
|
if (array != null && array.length() > 0) {//
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE)
|
.create();
|
List<VideoDetailInfo> list = gson.fromJson(array.toString(), new TypeToken<List<VideoDetailInfo>>() {
|
}.getType());
|
if (list != null && list.size() > 0) {
|
episodePage++;
|
VideoUtil.saveVideoEpisodeList(BeibeiVideoApplication.application, list, true);
|
rv_episode.getAdapter().notifyDataSetChanged();
|
}
|
}
|
}
|
}
|
|
@Override
|
public void onStart() {
|
super.onStart();
|
episodeLoading = true;
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
episodeLoading = false;
|
}
|
});
|
}
|
|
|
@Override
|
public void onStop() {
|
super.onStop();
|
Log.i(TAG, "onStop");
|
}
|
|
}
|