| | |
| | | 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 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.ui.login.LoginActivity; |
| | | 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 com.weikou.beibeivideo.R; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONArray; |
| | |
| | | |
| | | final String TAG = "EpisodeFragment"; |
| | | |
| | | private boolean episodeLoading = false;//剧集是否正在加载更多 |
| | | |
| | | private boolean episodeHasMore = true;//是否还有更多的剧集 |
| | | |
| | | private int episodePage = 2;//当前页 |
| | | |
| | | //默认页大小为100 |
| | | private int pageSize = 100; |
| | | |
| | | private String fromName = null; |
| | | |
| | | public static DisplayImageOptions option = new DisplayImageOptions.Builder() |
| | | .showImageForEmptyUri(R.drawable.from_other) |
| | | .showImageOnFail(R.drawable.from_other) |
| | |
| | | .build(); |
| | | |
| | | public static EpisodeFragment newInstance(VideoInfo videoInfo, |
| | | int playingPosition, int start, int end) { |
| | | int playingPosition, int pageSize, 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.putInt("pageSize", pageSize); |
| | | args.putString("from", from); |
| | | episodeFragment.setArguments(args); |
| | | return episodeFragment; |
| | | } |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | 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); |
| | | 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); |
| | | } |
| | |
| | | Bundle bundle = getArguments(); |
| | | mVideoInfo = (VideoInfo) bundle |
| | | .getSerializable("video_info"); |
| | | fromName = bundle |
| | | .getString("from", ""); |
| | | |
| | | mPlayingPosition = bundle.getInt("playing_position"); |
| | | pageSize = bundle.getInt("pageSize", 100); |
| | | mStart = bundle.getInt("start"); |
| | | mEnd = bundle.getInt("end"); |
| | | |
| | |
| | | |
| | | 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); |
| | |
| | | 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, pageSize); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onScrolled(RecyclerView recyclerView, int dx, final int dy) { |
| | | super.onScrolled(recyclerView, dx, dy); |
| | | } |
| | | }); |
| | | |
| | | |
| | | EventBus.getDefault().register(this); |
| | | } |
| | |
| | | .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); |
| | |
| | | |
| | | 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); |
| | |
| | | |
| | | 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) { |
| | | tv_video_resource.setText("来源:其他"); |
| | | resource = "来源:其他"; |
| | | } else { |
| | | tv_video_resource.setText("来源:" + selectedUrl.getName()); |
| | | 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(new ColorDrawable(0));// 设置背景 |
| | | popupWindow.setAnimationStyle(R.style.PopupAnimation); |
| | | popupWindow.setFocusable(true);// 获取焦点 |
| | | |
| | |
| | | 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, |
| | |
| | | pd.show(); |
| | | getVideoDetail(mVideoInfo.getId(), urlList |
| | | .get(position).getId(), mVideoInfo |
| | | .getThirdType(), true); |
| | | .getThirdType(), true, fromName); |
| | | } |
| | | selectedUrl = urlList.get(position); |
| | | if (selectedUrl == null || selectedUrl.getPicture() == null) { |
| | | tv_video_resource.setText("来源:其他"); |
| | | setResource("来源:其他"); |
| | | } else { |
| | | tv_video_resource.setText("来源:" + selectedUrl.getName()); |
| | | setResource("来源:" + selectedUrl.getName()); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | lv.setAdapter(new ResourceAdapter(urlList)); |
| | | lv.setDivider(new ColorDrawable(Color.BLACK)); |
| | | lv.setDividerHeight(1); |
| | | lv.setDividerHeight(0); |
| | | popupWindow.setContentView(lv); |
| | | /* |
| | | * Window dialogWindow = dialog.getWindow(); dialogWindow.get |
| | |
| | | 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()) |
| | | Glide.with(iv) |
| | | .load(reList.get(position).getPicture()) |
| | | .apply(new RequestOptions().placeholder(R.drawable.from_other).error(R.drawable.from_other)) |
| | | .into(iv); |
| | | } catch (IllegalArgumentException e) { |
| | |
| | | } else { |
| | | tv.setText(reList.get(position).getName()); |
| | | } |
| | | |
| | | int background = 0; |
| | | |
| | | if (reList.size() <= 1) { |
| | | background = reList.get(position).isChecked() ? R.drawable.shape_video_detail_resource_single_item_selected_bg : R.drawable.shape_video_detail_resource_single_item_bg; |
| | | } else { |
| | | if (position == 0) { |
| | | background = reList.get(position).isChecked() ? R.drawable.shape_video_detail_resource_top_item_selected_bg : R.drawable.shape_video_detail_resource_top_item_bg; |
| | | } else if (position == reList.size() - 1) { |
| | | background = reList.get(position).isChecked() ? R.drawable.shape_video_detail_resource_bottom_item_selected_bg : R.drawable.shape_video_detail_resource_bottom_item_bg; |
| | | } else { |
| | | background = reList.get(position).isChecked() ? R.drawable.shape_video_detail_resource_middle_item_selected_bg : R.drawable.shape_video_detail_resource_middle_item_bg; |
| | | } |
| | | } |
| | | view.setBackgroundResource(background); |
| | | |
| | | return view; |
| | | } |
| | | } |
| | | |
| | | private void getVideoDetail(String videoId, final String resourceId, |
| | | String videoThirdType, final boolean isSetup) { |
| | | 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, loginid, |
| | | videoThirdType, new BasicTextHttpResponseHandler() { |
| | | BeibeiVideoAPI.getVideoDetail(getContext(), uid, resourceId, videoId, null, loginid, |
| | | videoThirdType, from, new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | | public void onStart() { |
| | |
| | | .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, int pageSize) { |
| | | BeibeiVideoAPI.getVideoEpisodeList(ll_add_attention.getContext(), UserUtil.getUid(getContext()), resourceId, videoId, page, pageSize, 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(); |