package com.hanju.video.app.ui.media;
|
|
import android.graphics.Canvas;
|
import android.graphics.Rect;
|
import android.os.Bundle;
|
import android.util.Log;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.widget.FrameLayout;
|
import android.widget.ScrollView;
|
|
import com.hanju.video.app.R;
|
import com.hanju.video.app.entity.video.PushEpisode;
|
import com.hanju.video.app.entity.video.VideoInfo;
|
import com.hanju.video.app.entity.video.VideoResource;
|
import com.hanju.video.app.entity.ad.ExpressAdContainer;
|
import com.hanju.video.app.util.video.VideoUtil;
|
import com.hanju.video.app.util.ad.AdUtil;
|
import com.hanju.video.app.util.ad.ExpressAdManager;
|
import com.hanju.lib.library.RetainViewFragment;
|
import com.hanju.lib.library.util.common.DimenUtils;
|
import com.umeng.analytics.MobclickAgent;
|
|
import java.util.List;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.viewpager.widget.ViewPager;
|
import de.greenrobot.event.EventBus;
|
|
/**
|
* 播放详情--选集页面
|
*/
|
public class VideoEpisodeFragment extends RetainViewFragment implements
|
OnClickListener {
|
|
private static VideoInfo mVideoInfo;
|
|
private int mPlayingPosition;
|
|
private ViewPager vp_episode;
|
|
private ScrollView sv_detail;
|
|
private EpisodePagerAdapter mEpisodePagerAdapter;
|
|
private FrameLayout fl_native_ad_1;
|
|
public static boolean isShowMore = false;// 是否显示更多
|
public static int page_varietyshow = 0;// 综艺节目的分页
|
int maxDescripLine = 2;
|
|
|
final String TAG = "VideoEpisodeFragment";
|
|
public static VideoEpisodeFragment newInstance(VideoInfo videoInfo,
|
int playingPostion) {
|
VideoEpisodeFragment videoEpisodeFragment = new VideoEpisodeFragment();
|
Bundle args = new Bundle();
|
args.putSerializable("video_info", videoInfo);
|
args.putInt("playing_position", playingPostion);
|
videoEpisodeFragment.setArguments(args);
|
return videoEpisodeFragment;
|
}
|
|
|
RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {
|
@Override
|
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
super.onDraw(c, parent, state);
|
}
|
|
@Override
|
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
super.onDrawOver(c, parent, state);
|
}
|
|
@Override
|
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
super.getItemOffsets(outRect, view, parent, state);
|
int index = parent.getChildAdapterPosition(view);
|
int total = parent.getAdapter().getItemCount();
|
if (index % 2 == 0) {
|
outRect.left = 0; //第一列左边贴边
|
outRect.right = DimenUtils.dipToPixels(5, view.getContext());
|
} else {
|
outRect.right = 0; //第一列左边贴边
|
outRect.left = DimenUtils.dipToPixels(5, view.getContext());
|
}
|
|
if (index - 1 > 0) {
|
outRect.top = DimenUtils.dipToPixels(5, view.getContext());
|
} else
|
outRect.top = 0;
|
|
if (total % 2 == 0) {
|
if (total > 2 && (index < total - 2))
|
outRect.bottom = DimenUtils.dipToPixels(5, view.getContext());
|
else
|
outRect.bottom = 0;
|
} else {
|
if (total > 2 && (index < total - 1))
|
outRect.bottom = DimenUtils.dipToPixels(5, view.getContext());
|
else
|
outRect.bottom = 0;
|
}
|
}
|
};
|
|
@Override
|
public int getContentResource() {
|
return R.layout.video_episode_fragment;
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
Log.d(TAG, "onCreateView");
|
sv_detail = contentView.findViewById(R.id.sv_detail);
|
mVideoInfo = (VideoInfo) getArguments().getSerializable("video_info");
|
mPlayingPosition = getArguments().getInt("playing_position");
|
|
vp_episode = contentView.findViewById(R.id.vp_episode);
|
|
|
fl_native_ad_1 = contentView
|
.findViewById(R.id.fl_native_ad_1);
|
|
contentView.findViewById(R.id.ll_container).setFocusable(true);
|
contentView.findViewById(R.id.ll_container).setFocusableInTouchMode(true);
|
|
|
if (mVideoInfo == null)
|
return;
|
|
VideoResource videoResource = VideoUtil.getSelectedResource(mVideoInfo.getResourceList());
|
mEpisodePagerAdapter = new EpisodePagerAdapter(
|
getChildFragmentManager(), mVideoInfo, videoResource != null ? videoResource.getId() : null, mPlayingPosition);
|
//
|
vp_episode.setAdapter(mEpisodePagerAdapter);
|
// 指示当前播放页---hxh
|
|
vp_episode.post(new Runnable() {
|
|
@Override
|
public void run() {
|
int page = (mPlayingPosition + 1) % 20 == 0 ? (mPlayingPosition + 1) / 20
|
: (mPlayingPosition + 1) / 20 + 1;
|
if (page < 1)
|
return;
|
vp_episode.setCurrentItem(page - 1);
|
try {
|
mEpisodePagerAdapter.notifyDataSetChanged();
|
} catch (Exception e) {
|
|
}
|
}
|
});
|
}
|
|
private Runnable adRunnable = new Runnable() {
|
@Override
|
public void run() {
|
loadAD2();
|
}
|
};
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
EventBus.getDefault().register(this);
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
EventBus.getDefault().unregister(this);
|
isShowMore = false;
|
page_varietyshow = 0;
|
}
|
|
public void onEventMainThread(VideoInfo info) {
|
// Log.i("result", "收到来源点击产生的列表EventBus-------------1,电视剧的长度为:" + mVideoInfo.getVideoDetailList().size());
|
int playingPosition = 0;
|
if (mPlayingPosition != playingPosition) {
|
mPlayingPosition = playingPosition;
|
}
|
|
VideoResource videoResource = VideoUtil.getSelectedResource(info.getResourceList());
|
mEpisodePagerAdapter = new EpisodePagerAdapter(
|
getChildFragmentManager(), info, videoResource != null ? videoResource.getId() : null, mPlayingPosition);
|
vp_episode.setAdapter(mEpisodePagerAdapter);
|
}
|
|
public void onEventMainThread(PushEpisode info) {
|
if (mVideoInfo == null)
|
return;
|
// Log.i("result", "收到来源点击产生的列表EventBus-------------1,电视剧的长度为:" + mVideoInfo.getVideoDetailList().size());
|
if (mVideoInfo.getShowType() == 1) {// 综艺 如果是综艺的话就分页加载
|
if (info.getEpisodeNum() > 10) {
|
page_varietyshow = info.getEpisodeNum() / 10 + 1;
|
isShowMore = true;
|
}
|
} else {
|
if (info.getEpisodeNum() > 12) {
|
isShowMore = true;
|
}
|
}
|
mEpisodePagerAdapter.setPlayingPosition(info.getEpisodeNum());
|
}
|
|
boolean isExpand;
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
|
}
|
}
|
|
/**
|
* 广点通原生广告
|
*/
|
// 加载播放页第二条广告
|
private void loadAD2() {
|
ExpressAdManager expressAdManager = null;
|
try {
|
expressAdManager = new ExpressAdManager(AdUtil.AD_TYPE.gdt2, getContext());
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
if (expressAdManager == null)
|
return;
|
|
expressAdManager.loadVideoDetailRelativeVideoBottomAd(new ExpressAdManager.IAdLoadListener() {
|
@Override
|
public void onSuccess(List<ExpressAdContainer> adList) {
|
if (adList != null && adList.size() > 0)
|
ExpressAdManager.renderAd(getActivity(), adList.get(0), new ExpressAdManager.IAdRenderListener() {
|
@Override
|
public void onRenderSuccess(List<ExpressAdContainer> adList) {
|
ExpressAdManager.fillAd(adList.get(0), fl_native_ad_1);
|
}
|
|
@Override
|
public void onRenderFail(List<ExpressAdContainer> adList) {
|
|
}
|
}, new ExpressAdManager.IAdEventListener() {
|
|
@Override
|
public void closeAd(ExpressAdContainer ad) {
|
fl_native_ad_1.removeAllViews();
|
}
|
});
|
|
}
|
});
|
}
|
|
@Override
|
public void onDestroy() {
|
super.onDestroy();
|
}
|
}
|