| | |
| | | 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.util.Log; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | |
| | | 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.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.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.UMShareAPI; |
| | | import com.umeng.socialize.UMShareListener; |
| | |
| | | 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.db.WatchHistoryTable; |
| | | import com.weikou.beibeivideo.entity.Follow; |
| | | import com.weikou.beibeivideo.entity.Play; |
| | |
| | | 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.yeshi.buwanshequ.R; |
| | | import com.weikou.beibeivideo.util.GlideCircleTransform; |
| | | 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 com.weikou.beibeivideo.R; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONArray; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | private int mEnd; |
| | | private int mPlayingPosition; |
| | | private VideoInfo mVideoInfo = null; |
| | | private static GridView gv_episode; |
| | | private static EpisodeAdapter episodeAdapter; |
| | | private static EpisodeAdapter2 episodeAdapter2; |
| | | private RecyclerView rv_episode; |
| | | |
| | | 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 ImageView iv_moive_img; |
| | | |
| | | private TextView tv_star_name, tv_update_time, tv_cancle_follow; |
| | | 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;//当前页 |
| | | |
| | | public static DisplayImageOptions option = new DisplayImageOptions.Builder() |
| | | .showImageForEmptyUri(R.drawable.from_other) |
| | |
| | | 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) { |
| | | 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); |
| | | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); |
| | | tv_cancle_follow.setCompoundDrawables(drawable, null, null, null); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onCreateView(View contentView, Bundle savedInstanceState) { |
| | | EventBus.getDefault().register(this); |
| | | mVideoInfo = (VideoInfo) getArguments() |
| | | Log.i(TAG, "onCreateView"); |
| | | Bundle bundle = getArguments(); |
| | | mVideoInfo = (VideoInfo) bundle |
| | | .getSerializable("video_info"); |
| | | mPlayingPosition = getArguments().getInt("playing_position"); |
| | | mStart = getArguments().getInt("start"); |
| | | mEnd = getArguments().getInt("end"); |
| | | mPlayingPosition = bundle.getInt("playing_position"); |
| | | mStart = bundle.getInt("start"); |
| | | mEnd = bundle.getInt("end"); |
| | | |
| | | ll_add_attention = (LinearLayout) contentView.findViewById(R.id.ll_add_attention); |
| | | 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); |
| | | 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 = (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); |
| | | 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()).error(R.drawable.ic_default).placeholder(R.drawable.ic_default).centerCrop().into(iv_moive_img); |
| | | 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() + ""); |
| | | 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); |
| | | } |
| | | setFollowData(mVideoInfo.getAttention().isAttention()); |
| | | |
| | | tv_cancle_follow.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | |
| | | }); |
| | | } |
| | | |
| | | 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, gv_episode.getContext()); |
| | | 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); |
| | | setVideoInfo(); |
| | | |
| | | episodeAdapter = new EpisodeAdapter(mVideoInfo, mPlayingPosition); |
| | | episodeAdapter2 = new EpisodeAdapter2(mVideoInfo, mPlayingPosition); |
| | | 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(); |
| | | episodeAdapter = new EpisodeAdapter(mVideoInfo, |
| | | mPlayingPosition); |
| | | episodeAdapter2 = new EpisodeAdapter2(mVideoInfo, |
| | | mPlayingPosition); |
| | | // 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) { |
| | |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | SingleToast.showToast(ll_add_attention.getContext(), "添加关注成功!"); |
| | | mVideoInfo.getAttention().setAttention(true); |
| | | tv_cancle_follow.setText("已关注"); |
| | | tv_cancle_follow.setBackgroundColor(getResources().getColor(R.color.gray)); |
| | | setFollowData(mVideoInfo.getAttention().isAttention()); |
| | | |
| | | } |
| | | } |
| | | }); |
| | |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | SingleToast.showToast(ll_add_attention.getContext(), "取消关注成功!"); |
| | | mVideoInfo.getAttention().setAttention(false); |
| | | tv_cancle_follow.setText("关注"); |
| | | tv_cancle_follow.setBackgroundColor(getResources().getColor(R.color.yellow)); |
| | | 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 = iv_report.getContext().getSharedPreferences( |
| | | SharedPreferences preferences = getContext().getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.getPlayUrl(iv_report.getContext(), uid, info.getType(), mVideoInfo.getId(), |
| | | BeibeiVideoAPI.getPlayUrl(getContext(), uid, info.getType(), mVideoInfo.getId(), |
| | | info.getId(), selectedUrl.getId(), info.geteId(), |
| | | new BasicTextHttpResponseHandler() { |
| | | |
| | |
| | | .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); |
| | |
| | | /** |
| | | * 刷新adapter |
| | | */ |
| | | public static void refresh() { |
| | | if (VideoEpisodeFragment.isShowMore && episodeAdapter != null) {// 展示更多 |
| | | gv_episode.setAdapter(episodeAdapter); |
| | | } else if ((!VideoEpisodeFragment.isShowMore) && episodeAdapter2 != null) { |
| | | gv_episode.setAdapter(episodeAdapter2); |
| | | } |
| | | 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() { |
| | | NativeExpressAD nativeExpressAD = new NativeExpressAD(ll_add_attention.getContext(), new ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT), |
| | | BeibeiConstant.GDT_ID, BeibeiConstant.GDT_PLAYER_NATIVE1, new NativeExpressAD.NativeExpressADListener() { |
| | | new ExpressAdManager(AdUtil.AD_TYPE.gdt2, getContext()).loadVideoDetailPlayerBottomAd(new ExpressAdManager.IAdLoadListener() { |
| | | @Override |
| | | public void onADLoaded(final List<NativeExpressADView> list) { |
| | | tv_add_to_favourite.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (null != list && list.size() > 0) { |
| | | NativeExpressADView adView = list.get(0); |
| | | adView.render(); |
| | | FrameLayout parent = (FrameLayout) adView.getParent(); |
| | | if (parent != null) { |
| | | parent.removeAllViews(); |
| | | } |
| | | fl_native_ad1.addView(adView); |
| | | 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 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(2); |
| | | }); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onClick(View v) { |
| | | SharedPreferences preferences = iv_report.getContext() |
| | | SharedPreferences preferences = getContext() |
| | | .getSharedPreferences("user", Context.MODE_PRIVATE); |
| | | switch (v.getId()) { |
| | | case R.id.fl_add_to_favourite: |
| | | case R.id.iv_add_to_favourite: |
| | | final String loginUid = preferences.getString("LoginUid", ""); |
| | | if (StringUtils.isEmpty(loginUid)) { |
| | | SingleToast.showToast(ll_add_attention.getContext(), "登录后才能收藏"); |
| | |
| | | break; |
| | | } |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.isCollect(iv_report.getContext(), uid, mVideoInfo.getId(), |
| | | BeibeiVideoAPI.isCollect(getContext(), uid, mVideoInfo.getId(), |
| | | mVideoInfo.getThirdType(), |
| | | new BasicTextHttpResponseHandler() { |
| | | |
| | |
| | | } |
| | | } |
| | | break; |
| | | case R.id.fl_offline_cache: |
| | | case R.id.iv_offline_cache: |
| | | Toast.makeText(ll_add_attention.getContext(), "暂时无法缓存!", Toast.LENGTH_SHORT).show(); |
| | | break; |
| | | case R.id.fl_share: |
| | | case R.id.iv_share: |
| | | String shareContent = getShareContent(); |
| | | UMWeb web = new UMWeb(getShareUrl()); |
| | | String shareTitle = getResources().getString(R.string.app_name); |
| | |
| | | |
| | | 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); |
| | | 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); |
| | | iv_favourite.setEnabled(true); |
| | | fl_report.setEnabled(true); |
| | | if (VideoEpisodeFragment.isShowMore) {// 展示更多 |
| | | gv_episode.setAdapter(episodeAdapter); |
| | | } else { |
| | | gv_episode.setAdapter(episodeAdapter2); |
| | | } |
| | | // isCollect(); |
| | | rv_episode.setAdapter(episodeAdapter); |
| | | |
| | | } |
| | | |
| | | private void setFrom(VideoInfo info) { |
| | |
| | | } |
| | | } |
| | | EventBus.getDefault().post(selectedUrl); |
| | | tv_add_to_favourite.postDelayed(new Runnable() { |
| | | iv_favourite.postDelayed(new Runnable() { |
| | | |
| | | @Override |
| | | public void run() { |
| | |
| | | |
| | | if (mVideoInfo.getResourceList() != null |
| | | && mVideoInfo.getResourceList().size() > 0) { |
| | | // tv_report.setText("来源:"); |
| | | iv_report.setVisibility(View.VISIBLE); |
| | | tv_video_resource.setVisibility(View.VISIBLE); |
| | | if (selectedUrl == null || selectedUrl.getPicture() == null) { |
| | | Glide.with(getActivity().getApplicationContext()).load(R.drawable.from_other).into(iv_report); |
| | | tv_video_resource.setText("来源:其他"); |
| | | } 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); |
| | | tv_video_resource.setText("来源:" + selectedUrl.getName()); |
| | | } |
| | | popupWindow = new PopupWindow( |
| | | com.weikou.beibeivideo.util.DimenUtils.dip2px(iv_report.getContext(), 120), |
| | | com.weikou.beibeivideo.util.DimenUtils.dip2px(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 lv = new ListView(getContext()); |
| | | ListView.LayoutParams param = new ListView.LayoutParams( |
| | | FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); |
| | | FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); |
| | | lv.setLayoutParams(param); |
| | | lv.setOnItemClickListener(new OnItemClickListener() { |
| | | @Override |
| | |
| | | .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); |
| | | tv_video_resource.setText("来源:其他"); |
| | | } 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); |
| | | tv_video_resource.setText("来源:" + selectedUrl.getName()); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | lv.setAdapter(new ResourceAdapter(urlList)); |
| | | lv.setDividerHeight(0); |
| | | lv.setDivider(new ColorDrawable(Color.BLACK)); |
| | | lv.setDividerHeight(1); |
| | | popupWindow.setContentView(lv); |
| | | /* |
| | | * Window dialogWindow = dialog.getWindow(); dialogWindow.get |
| | | */ |
| | | } else { |
| | | iv_report.setVisibility(View.GONE); |
| | | // tv_report.setText("其它"); |
| | | tv_video_resource.setVisibility(View.GONE); |
| | | } |
| | | |
| | | } |
| | |
| | | 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 = (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); |
| | | // } |
| | | 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().contains("http://") ? reList |
| | | .get(position).getPicture() : BeibeiConstant.HOST |
| | | + "/BuWan/" + reList.get(position).getPicture()) |
| | | .placeholder(R.drawable.from_other) |
| | | .error(R.drawable.from_other).crossFade().into(iv); |
| | | .apply(new RequestOptions().placeholder(R.drawable.from_other).error(R.drawable.from_other)) |
| | | .into(iv); |
| | | } catch (IllegalArgumentException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | |
| | | private void getVideoDetail(String videoId, final String resourceId, |
| | | String videoThirdType, final boolean isSetup) { |
| | | SharedPreferences preferences = iv_report.getContext().getSharedPreferences( |
| | | SharedPreferences preferences = getContext().getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | String loginid = preferences.getString("LoginUid", ""); |
| | | BeibeiVideoAPI.getVideoDetail(iv_report.getContext(), uid, resourceId, videoId, loginid, |
| | | BeibeiVideoAPI.getVideoDetail(getContext(), uid, resourceId, videoId, loginid, |
| | | videoThirdType, new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | |
| | | .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) { |
| | |
| | | if (extraData != null) |
| | | videoInfo.setExtraData(extraData.toString()); |
| | | |
| | | if (videoInfo.getVideoDetailList() == null |
| | | || videoInfo.getVideoDetailList().isEmpty()) { |
| | | Toast.makeText(iv_report.getContext(), "影片已删除", |
| | | 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) { |
| | | mVideoInfo.getVideoDetailList().clear(); |
| | | mVideoInfo.setVideoDetailList(videoInfo |
| | | .getVideoDetailList()); |
| | | VideoUtil.saveVideoEpisodeList(BeibeiVideoApplication.application,videoInfo.getVideoDetailList(),false); |
| | | |
| | | EventBus.getDefault().post(videoInfo); |
| | | int position = 0; |
| | | // boolean isFromWatchHistory = false; |
| | | // isFromWatchHistory = getArguments().getBoolean("isFromWatchHistory", false);// 是否从观看记录点击过来 |
| | | Cursor cursor = gv_episode.getContext().getContentResolver().query( |
| | | Cursor cursor = rv_episode.getContext().getContentResolver().query( |
| | | WatchHistoryTable.CONTENT_URI, null, |
| | | WatchHistoryTable.VIDEO_ID + " = ? ", |
| | | new String[]{videoInfo.getId()}, null); |
| | |
| | | "playing_position", 0); |
| | | } |
| | | // if (isFromWatchHistory) { |
| | | getUrl(videoInfo.getVideoDetailList().get(position)); |
| | | getUrl(VideoUtil.videoEpisodeList.get(position)); |
| | | EventBus.getDefault() |
| | | .post(videoInfo |
| | | .getVideoDetailList() |
| | | .post(VideoUtil.videoEpisodeList |
| | | .get(position)); |
| | | // } else {// 不是从观看记录点击过来 --跳到当前播放的集数 |
| | | // getUrl(videoInfo.getVideoDetailList().get(position)); |
| | |
| | | // position)); |
| | | // } |
| | | } else { |
| | | tv_offline_cache.postDelayed(new Runnable() { |
| | | iv_favourite.postDelayed(new Runnable() { |
| | | |
| | | @Override |
| | | public void run() { |
| | | EventBus.getDefault().post(videoInfo); |
| | | EventBus.getDefault().post( |
| | | videoInfo.getVideoDetailList() |
| | | VideoUtil.videoEpisodeList |
| | | .get(0)); |
| | | } |
| | | }, 200); |
| | |
| | | * @param thirdType |
| | | */ |
| | | private void getScoreCollect(String loginUid, final String type, String thirdType) { |
| | | SharedPreferences preferences = iv_report.getContext().getSharedPreferences( |
| | | SharedPreferences preferences = getContext().getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.getScoreCollect(iv_report.getContext(), uid, loginUid, mVideoInfo.getId(), |
| | | BeibeiVideoAPI.getScoreCollect(getContext(), uid, loginUid, mVideoInfo.getId(), |
| | | thirdType, type, new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | |
| | | throws Exception { |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | | if (type.equals("1")) { |
| | | SingleToast.showToast(iv_report.getContext(), "收藏成功"); |
| | | SingleToast.showToast(getContext(), "收藏成功"); |
| | | } else { |
| | | SingleToast.showToast(iv_report.getContext(), "取消收藏成功"); |
| | | SingleToast.showToast(getContext(), "取消收藏成功"); |
| | | } |
| | | } else { |
| | | if (type.equals("1")) { |
| | | SingleToast.showToast(iv_report.getContext(), "收藏失败"); |
| | | SingleToast.showToast(getContext(), "收藏失败"); |
| | | } else { |
| | | SingleToast.showToast(iv_report.getContext(), "取消收藏失败"); |
| | | SingleToast.showToast(getContext(), "取消收藏失败"); |
| | | } |
| | | } |
| | | isCollect(); |
| | |
| | | } |
| | | |
| | | private void isCollect() { |
| | | SharedPreferences preferences = tv_add_to_favourite.getContext().getSharedPreferences( |
| | | SharedPreferences preferences = iv_favourite.getContext().getSharedPreferences( |
| | | "user", Context.MODE_PRIVATE); |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.isCollect(tv_add_to_favourite.getContext(), uid, mVideoInfo.getId(), |
| | | BeibeiVideoAPI.isCollect(iv_favourite.getContext(), uid, mVideoInfo.getId(), |
| | | mVideoInfo.getThirdType(), new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 加载更多剧集 |
| | | * |
| | | * @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"); |
| | | } |
| | | |
| | | } |