| | |
| | | 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.ui.video.EpisodeNewAdapter; |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | 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 org.json.JSONArray; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | 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) |
| | |
| | | RecyclerView parent, RecyclerView.State state) { |
| | | int position = parent.getChildAdapterPosition(view); |
| | | outRect.left = space; |
| | | if (mVideoInfo != null && position == mVideoInfo.getVideoDetailList().size() - 1) |
| | | if (mVideoInfo != null && position == VideoUtil.videoEpisodeList.size() - 1) |
| | | outRect.right = space; |
| | | } |
| | | } |
| | |
| | | if (rv_episode.getLayoutManager() == null) |
| | | rv_episode.setLayoutManager(ms); |
| | | |
| | | |
| | | rv_episode.addItemDecoration(new SpacesItemDecoration(DimenUtils.dip2px(getContext(), 10))); |
| | | if (rv_episode.getItemDecorationCount() == 0) |
| | | rv_episode.addItemDecoration(new SpacesItemDecoration(DimenUtils.dip2px(getContext(), 10))); |
| | | } |
| | | |
| | | |
| | |
| | | @Override |
| | | public void onCreateView(View contentView, Bundle savedInstanceState) { |
| | | Log.i(TAG, "onCreateView"); |
| | | EventBus.getDefault().register(this); |
| | | mVideoInfo = (VideoInfo) getArguments() |
| | | 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"); |
| | | |
| | | if (getArguments() != null) |
| | | getArguments().clear(); |
| | | 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); |
| | |
| | | isCollect(); |
| | | loadAD1(); |
| | | setFrom(mVideoInfo); |
| | | if (mVideoInfo.getVideoDetailList() != null && mVideoInfo.getVideoDetailList().size() > 1) { |
| | | 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(); |
| | | // loadEpisode(); |
| | | refresh(); |
| | | } |
| | | |
| | |
| | | .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); |
| | |
| | | }); |
| | | |
| | | } else { |
| | | fl_native_ad1.setVisibility(View.GONE); |
| | | //加载穿山甲 |
| | | 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); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | |
| | | |
| | | public void onEventMainThread(VideoInfo videoInfo) { |
| | | mVideoInfo = videoInfo; |
| | | if (mVideoInfo.getVideoDetailList() != null && mVideoInfo.getVideoDetailList().size() > 1) { |
| | | if (VideoUtil.videoEpisodeList != null && VideoUtil.videoEpisodeList.size() > 1) { |
| | | rv_episode.setVisibility(View.VISIBLE); |
| | | } else |
| | | rv_episode.setVisibility(View.GONE); |
| | |
| | | .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()) { |
| | | 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; |
| | |
| | | "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)); |
| | |
| | | public void run() { |
| | | EventBus.getDefault().post(videoInfo); |
| | | EventBus.getDefault().post( |
| | | videoInfo.getVideoDetailList() |
| | | VideoUtil.videoEpisodeList |
| | | .get(0)); |
| | | } |
| | | }, 200); |
| | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 加载更多剧集 |
| | | * |
| | | * @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(); |