package com.yeshi.video.ui;
|
|
import android.app.ProgressDialog;
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
import android.database.Cursor;
|
import android.graphics.Bitmap;
|
import android.graphics.drawable.ColorDrawable;
|
import android.os.Bundle;
|
import android.os.Handler;
|
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.GridView;
|
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.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.ImageLoader;
|
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
import com.qq.e.ads.cfg.VideoOption;
|
import com.qq.e.ads.nativ.ADSize;
|
import com.qq.e.ads.nativ.NativeExpressAD;
|
import com.qq.e.ads.nativ.NativeExpressADView;
|
import com.qq.e.comm.util.AdError;
|
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.yeshi.base.entity.ad.AdPositionEnum;
|
import com.yeshi.base.entity.db.WatchHistoryTable;
|
import com.yeshi.base.entity.video.Follow;
|
import com.yeshi.base.entity.video.Play;
|
import com.yeshi.base.entity.video.PlayUrl;
|
import com.yeshi.base.entity.video.Playlocation;
|
import com.yeshi.base.entity.video.VideoDetailInfo;
|
import com.yeshi.base.entity.video.VideoInfo;
|
import com.yeshi.base.entity.video.VideoResource;
|
import com.yeshi.base.utils.BeibeiConstant;
|
import com.yeshi.base.utils.JsonUtil;
|
import com.yeshi.base.utils.ad.AdUtil;
|
import com.yeshi.base.utils.ad.GDTConstant;
|
import com.yeshi.base.utils.http.BasicTextHttpResponseHandler;
|
import com.yeshi.video.R;
|
import com.yeshi.video.ui.adapter.EpisodeAdapter;
|
import com.yeshi.video.ui.adapter.EpisodeAdapter2;
|
import com.yeshi.video.utils.VideoApiUtil;
|
|
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;
|
|
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
|
|
/**
|
* 节目选集列表,可设置电视剧6列;电影,综艺1列
|
*/
|
public class EpisodeFragment extends RetainViewFragment implements
|
View.OnClickListener {
|
private int mStart;
|
private int mEnd;
|
private int mPlayingPosition;
|
private VideoInfo mVideoInfo = null;
|
private static GridView gv_episode;
|
private static EpisodeAdapter episodeAdapter;
|
private static EpisodeAdapter2 episodeAdapter2;
|
|
private TextView tv_add_to_favourite;
|
private LinearLayout fl_add_to_favourite;
|
private LinearLayout fl_report;
|
private ImageView iv_report;
|
private ImageView iv_favourite;
|
|
private TextView tv_offline_cache;
|
|
private LinearLayout fl_offline_cache;
|
|
private FrameLayout fl_native_ad1;
|
|
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) {
|
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);
|
episodeFragment.setArguments(args);
|
return episodeFragment;
|
}
|
|
@Override
|
public int getContentResource() {
|
return R.layout.fragment_episode;
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
EventBus.getDefault().register(this);
|
mVideoInfo = (VideoInfo) getArguments().getSerializable("video_info");
|
mPlayingPosition = getArguments().getInt("playing_position");
|
mStart = getArguments().getInt("start");
|
mEnd = getArguments().getInt("end");
|
|
// if (mVideoInfo.getAttention() == null) {
|
// ll_add_attention.setVisibility(View.GONE);
|
// } else {
|
// ll_add_attention.setVisibility(View.VISIBLE);
|
// iv_moive_img = (ImageView) contentView
|
// .findViewById(R.id.iv_moive_img);
|
// tv_star_name = (TextView) contentView
|
// .findViewById(R.id.tv_star_name);
|
// tv_update_time = (TextView) contentView
|
// .findViewById(R.id.tv_update_time);
|
// tv_cancle_follow = (TextView) contentView
|
// .findViewById(R.id.tv_cancle_follow);
|
// try {
|
// Glide.with(getActivity().getApplicationContext())
|
// .load(mVideoInfo.getAttention().getMoviePicture())
|
// .error(R.drawable.ic_default)
|
// .placeholder(R.drawable.ic_default).centerCrop()
|
// .into(iv_moive_img);
|
// } catch (IllegalArgumentException e) {
|
// e.printStackTrace();
|
// }
|
// tv_star_name.setText(mVideoInfo.getAttention().getMovieName() + "");
|
// tv_update_time.setText(mVideoInfo.getAttention().getUpdateInfo()
|
// + "");
|
// if (mVideoInfo.getAttention().isAttention()) {
|
// tv_cancle_follow.setText("已关注");
|
// tv_cancle_follow.setBackgroundResource(R.color.gray);
|
// } else {
|
// tv_cancle_follow.setText("关注");
|
// tv_cancle_follow.setBackgroundResource(R.color.yellow);
|
// }
|
//
|
// tv_cancle_follow.setOnClickListener(new View.OnClickListener() {
|
// @Override
|
// public void onClick(View v) {
|
// SharedPreferences sp = tv_cancle_follow.getContext()
|
// .getSharedPreferences("user", Context.MODE_PRIVATE);
|
// String uid = sp.getString("uid", "");
|
// String loginid = sp.getString("LoginUid", "");
|
// if (StringUtils.isEmpty(loginid)) {
|
// Toast.makeText(tv_cancle_follow.getContext(),
|
// "登陆成功后才能进行关注!", Toast.LENGTH_LONG).show();
|
// tv_cancle_follow.getContext().startActivity(
|
// new Intent(tv_cancle_follow.getContext(),
|
// LoginActivity.class));
|
// return;
|
// }
|
// if (mVideoInfo.getAttention().isAttention()) {// 取消关注
|
// cancleAttention(uid, loginid);
|
// } else {// 关注
|
// addAttention(uid, loginid);
|
// }
|
// }
|
// });
|
// }
|
|
fl_native_ad1 = (FrameLayout) contentView
|
.findViewById(R.id.fl_native_ad_1);
|
gv_episode = (GridView) contentView
|
.findViewById(R.id.gv_fragment_episode);
|
gv_episode.setLayoutParams(new LinearLayout.LayoutParams(
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
LinearLayout.LayoutParams.WRAP_CONTENT));
|
int padding = DimenUtils.dipToPixels(8, getActivity());
|
gv_episode.setPadding(padding, padding, padding, padding);
|
if (mVideoInfo.getShowType() == 1) {// 综艺或者电影
|
gv_episode.setNumColumns(1);
|
} else if (mVideoInfo.getShowType() == 2) {
|
// 电视剧什么的
|
gv_episode.setNumColumns(5);
|
}
|
gv_episode.setHorizontalSpacing(padding);
|
gv_episode.setVerticalSpacing(padding);
|
gv_episode.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
|
gv_episode.setOnItemClickListener(new OnItemClickListener() {
|
@Override
|
public void onItemClick(AdapterView<?> parent, View view,
|
int position, long id) {
|
VideoDetailInfo videoDetailInfo = (VideoDetailInfo) parent
|
.getItemAtPosition(position);
|
if (selectedUrl == null) {
|
return;
|
}
|
mPlayingPosition = position;
|
episodeAdapter = new EpisodeAdapter(mVideoInfo,
|
mPlayingPosition);
|
episodeAdapter2 = new EpisodeAdapter2(mVideoInfo,
|
mPlayingPosition);
|
refresh();
|
Playlocation playlocation = new Playlocation();
|
playlocation.setPosition(position);
|
EventBus.getDefault().post(playlocation);
|
getUrl(videoDetailInfo);
|
}
|
});
|
fl_add_to_favourite = (LinearLayout) contentView
|
.findViewById(R.id.fl_add_to_favourite);
|
tv_add_to_favourite = (TextView) contentView
|
.findViewById(R.id.tv_add_to_favourite);
|
fl_add_to_favourite.setOnClickListener(this);
|
contentView.findViewById(R.id.fl_share).setOnClickListener(this);
|
fl_report = (LinearLayout) contentView.findViewById(R.id.fl_report);
|
iv_report = (ImageView) contentView.findViewById(R.id.iv_report_more);
|
iv_favourite = (ImageView) contentView
|
.findViewById(R.id.iv_add_to_favourite);
|
fl_report.setOnClickListener(this);
|
tv_offline_cache = (TextView) contentView
|
.findViewById(R.id.tv_offline_cache);
|
fl_offline_cache = (LinearLayout) contentView
|
.findViewById(R.id.fl_offline_cache);
|
fl_offline_cache.setOnClickListener(this);
|
|
episodeAdapter = new EpisodeAdapter(mVideoInfo, mPlayingPosition);
|
episodeAdapter2 = new EpisodeAdapter2(mVideoInfo, mPlayingPosition);
|
refresh();
|
isCollect();
|
loadAD();
|
setFrom(mVideoInfo);
|
}
|
|
public void onEventMainThread(Playlocation playlocation) {
|
mPlayingPosition = playlocation.getPosition();
|
episodeAdapter = new EpisodeAdapter(mVideoInfo, mPlayingPosition);
|
episodeAdapter2 = new EpisodeAdapter2(mVideoInfo, mPlayingPosition);
|
refresh();
|
}
|
|
|
@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 = iv_report.getContext()
|
.getSharedPreferences("user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
VideoApiUtil.getPlayUrl(iv_report.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")) {
|
|
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"));
|
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 static void refresh() {
|
if (VideoEpisodeFragment.isShowMore && episodeAdapter != null) {// 展示更多
|
gv_episode.setAdapter(episodeAdapter);
|
} else if ((!VideoEpisodeFragment.isShowMore)
|
&& episodeAdapter2 != null) {
|
gv_episode.setAdapter(episodeAdapter2);
|
}
|
|
}
|
|
private void loadAD() {
|
if (AdUtil.getAdType(getContext(), AdPositionEnum.other) == null)
|
return;
|
NativeExpressAD nativeExpressAD = new NativeExpressAD(getContext(), new ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT),
|
GDTConstant.GDT_HOME_AND_PLAY_BIG_PICTURE, new NativeExpressAD.NativeExpressADListener() {
|
@Override
|
public void onADLoaded(final List<NativeExpressADView> list) {
|
if (list.size() > 0) {
|
list.get(0).render();
|
fl_native_ad1.removeAllViews();
|
fl_native_ad1.addView(list.get(0));
|
}
|
}
|
|
@Override
|
public void onRenderFail(NativeExpressADView nativeExpressADView) {
|
|
}
|
|
@Override
|
public void onRenderSuccess(NativeExpressADView nativeExpressADView) {
|
|
}
|
|
@Override
|
public void onADExposure(NativeExpressADView nativeExpressADView) {
|
}
|
|
@Override
|
public void onADClicked(NativeExpressADView nativeExpressADView) {
|
|
}
|
|
@Override
|
public void onADClosed(NativeExpressADView nativeExpressADView) {
|
|
}
|
|
@Override
|
public void onADLeftApplication(NativeExpressADView nativeExpressADView) {
|
|
}
|
|
@Override
|
public void onADOpenOverlay(NativeExpressADView nativeExpressADView) {
|
|
}
|
|
@Override
|
public void onADCloseOverlay(NativeExpressADView nativeExpressADView) {
|
|
}
|
|
@Override
|
public void onNoAD(AdError adError) {
|
|
}
|
}); // 传入Activity
|
// 注意:如果您在联盟平台上新建原生模板广告位时,选择了支持视频,那么可以进行个性化设置(可选)
|
nativeExpressAD.setVideoOption(new VideoOption.Builder()
|
.setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // WIFI 环境下可以自动播放视频
|
.setAutoPlayMuted(true) // 自动播放时为静音
|
.build()); //
|
nativeExpressAD.loadAD(1);
|
}
|
|
@Override
|
public void onClick(View v) {
|
SharedPreferences preferences = iv_report.getContext()
|
.getSharedPreferences("user", Context.MODE_PRIVATE);
|
int id = v.getId();
|
if (id == R.id.fl_add_to_favourite) {
|
String uid = preferences.getString("uid", "");
|
VideoApiUtil.isCollect(iv_report.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("0", mVideoInfo.getThirdType());
|
} else {
|
getScoreCollect("1", mVideoInfo.getThirdType());
|
}
|
}
|
});
|
} else if (id == 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);
|
}
|
}
|
} else if (id == R.id.fl_offline_cache) {
|
Toast.makeText(tv_add_to_favourite.getContext(), "暂时无法缓存!",
|
Toast.LENGTH_SHORT).show();
|
} else if (id == R.id.fl_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) {
|
Toast.makeText(iv_favourite.getContext(), "分享出错!" + throwable,
|
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;
|
setFrom(videoInfo);
|
if (mVideoInfo.isCanSave()) {
|
// fl_offline_cache.setEnabled(true);
|
// tv_offline_cache.setText("缓存");
|
} else {
|
// fl_offline_cache.setEnabled(false);
|
// tv_offline_cache.setText("无法缓存");
|
}
|
fl_add_to_favourite.setEnabled(true);
|
fl_report.setEnabled(true);
|
if (VideoEpisodeFragment.isShowMore) {// 展示更多
|
gv_episode.setAdapter(episodeAdapter);
|
} else {
|
gv_episode.setAdapter(episodeAdapter2);
|
}
|
// isCollect();
|
}
|
|
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);
|
tv_add_to_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 initResource() {
|
|
if (mVideoInfo.getResourceList() != null
|
&& mVideoInfo.getResourceList().size() > 0) {
|
// tv_report.setText("来源:");
|
iv_report.setVisibility(View.VISIBLE);
|
if (selectedUrl == null || selectedUrl.getPicture() == null) {
|
Glide.with(getActivity().getApplicationContext())
|
.load(R.drawable.from_other).into(iv_report);
|
} else {
|
// Glide.with(getActivity().getApplicationContext()).load(selectedUrl.getPicture()).placeholder(R.drawable.from_other).error(R.drawable.from_other).into(iv_report);
|
ImageLoader.getInstance().displayImage(
|
selectedUrl.getPicture(), iv_report, option);
|
}
|
popupWindow = new PopupWindow(
|
DimenUtils.dip2px(
|
iv_report.getContext(), 120),
|
android.view.WindowManager.LayoutParams.WRAP_CONTENT);
|
popupWindow.setOutsideTouchable(true);// 点击外部可点击
|
popupWindow.setBackgroundDrawable(new ColorDrawable(0));// 设置背景
|
popupWindow.setAnimationStyle(R.style.PopupAnimation);
|
popupWindow.setFocusable(true);// 获取焦点
|
|
ListView lv = new ListView(iv_report.getContext());
|
ListView.LayoutParams param = new ListView.LayoutParams(
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
FrameLayout.LayoutParams.WRAP_CONTENT);
|
lv.setLayoutParams(param);
|
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(iv_report.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);
|
}
|
selectedUrl = urlList.get(position);
|
iv_report.setVisibility(View.VISIBLE);
|
if (selectedUrl == null || selectedUrl.getPicture() == null) {
|
// ImageLoader.getInstance().displayImage(
|
// "drawable://" + R.drawable.from_other,
|
// iv_report);
|
Glide.with(getActivity().getApplicationContext())
|
.load(R.drawable.from_other).into(iv_report);
|
} else {
|
Glide.with(getActivity().getApplicationContext())
|
.load(selectedUrl.getPicture())
|
.placeholder(R.drawable.from_other)
|
.error(R.drawable.from_other).into(iv_report);
|
// ImageLoader.getInstance().displayImage(
|
// selectedUrl.getPicture(), iv_report, option);
|
}
|
|
}
|
});
|
lv.setAdapter(new ResourceAdapter(urlList));
|
lv.setDividerHeight(0);
|
popupWindow.setContentView(lv);
|
/*
|
* Window dialogWindow = dialog.getWindow(); dialogWindow.get
|
*/
|
} else {
|
iv_report.setVisibility(View.GONE);
|
// tv_report.setText("其它");
|
}
|
|
}
|
|
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(iv_report.getContext()).inflate(
|
R.layout.item_resource, null);
|
ImageView iv = (ImageView) view.findViewById(R.id.iv_resource);
|
TextView tv = (TextView) view.findViewById(R.id.tv_resource);
|
// if (reList.get(position) == null
|
// || reList.get(position).getPicture() == null) {
|
// ImageLoader.getInstance().displayImage(
|
// "drawable://" + R.drawable.from_other, iv);
|
// } else {
|
// ImageLoader.getInstance().displayImage(
|
// reList.get(position).getPicture(), iv, option);
|
// }
|
try {
|
Glide.with(getActivity().getApplicationContext())
|
.load(reList.get(position).getPicture()
|
.contains("http://") ? reList.get(position)
|
.getPicture() : BeibeiConstant.HOST + "/BuWan/"
|
+ reList.get(position).getPicture())
|
.placeholder(R.drawable.from_other)
|
.error(R.drawable.from_other).transition(withCrossFade()).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) {
|
SharedPreferences preferences = iv_report.getContext()
|
.getSharedPreferences("user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
String loginid = preferences.getString("LoginUid", "");
|
VideoApiUtil.getVideoDetail(iv_report.getContext(), uid, resourceId,
|
videoId, loginid, videoThirdType,
|
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")) {
|
|
|
final VideoInfo videoInfo = JsonUtil.videoGson
|
.fromJson(jsonObject.getJSONObject("Data")
|
.toString(),
|
new TypeToken<VideoInfo>() {
|
}.getType());
|
// 附加字段
|
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 (videoInfo.getVideoDetailList() == null
|
|| videoInfo.getVideoDetailList().isEmpty()) {
|
Toast.makeText(iv_report.getContext(), "影片已删除",
|
Toast.LENGTH_LONG).show();
|
getActivity().finish();
|
return;
|
}
|
// videoInfo.setSave(jsonObject.getJSONObject("Data").optBoolean("Save"));
|
if (isSetup) {
|
mVideoInfo.getVideoDetailList().clear();
|
mVideoInfo.setVideoDetailList(videoInfo
|
.getVideoDetailList());
|
EventBus.getDefault().post(videoInfo);
|
int position = 0;
|
// boolean isFromWatchHistory = false;
|
// isFromWatchHistory =
|
// getArguments().getBoolean("isFromWatchHistory",
|
// false);// 是否从观看记录点击过来
|
Cursor cursor = gv_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(videoInfo.getVideoDetailList().get(
|
position));
|
EventBus.getDefault().post(
|
videoInfo.getVideoDetailList().get(
|
position));
|
// } else {// 不是从观看记录点击过来 --跳到当前播放的集数
|
// getUrl(videoInfo.getVideoDetailList().get(position));
|
// EventBus.getDefault().post(
|
// videoInfo.getVideoDetailList().get(
|
// position));
|
// }
|
} else {
|
tv_offline_cache.postDelayed(new Runnable() {
|
|
@Override
|
public void run() {
|
EventBus.getDefault().post(videoInfo);
|
EventBus.getDefault().post(
|
videoInfo.getVideoDetailList()
|
.get(0));
|
}
|
}, 200);
|
}
|
}
|
}
|
});
|
}
|
|
/**
|
* 收藏
|
*
|
* @param type
|
* @param thirdType
|
*/
|
private void getScoreCollect(final String type, String thirdType) {
|
SharedPreferences preferences = iv_report.getContext()
|
.getSharedPreferences("user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
VideoApiUtil.getScoreCollect(iv_report.getContext(), uid,
|
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(iv_report.getContext(),
|
"收藏成功");
|
} else {
|
SingleToast.showToast(iv_report.getContext(),
|
"取消收藏成功");
|
}
|
EventBus.getDefault().post(
|
new VideoPlayerFragment.FavouriteEvent());
|
} else {
|
if (type.equals("1")) {
|
SingleToast.showToast(iv_report.getContext(),
|
"收藏失败");
|
} else {
|
SingleToast.showToast(iv_report.getContext(),
|
"取消收藏失败");
|
}
|
}
|
isCollect();
|
}
|
});
|
}
|
|
private void isCollect() {
|
SharedPreferences preferences = getActivity().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
VideoApiUtil.isCollect(getActivity(), 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);
|
}
|
}
|
});
|
}
|
}
|