package com.yeshi.video.ui;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
import android.os.Bundle;
|
import android.util.Log;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.view.animation.Animation;
|
import android.view.animation.RotateAnimation;
|
import android.view.animation.Transformation;
|
import android.widget.AdapterView;
|
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.FrameLayout;
|
import android.widget.GridView;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.ScrollView;
|
import android.widget.TextView;
|
|
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.common.StringUtils;
|
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.analytics.MobclickAgent;
|
import com.viewpagerindicator.TabPageIndicator;
|
import com.yeshi.base.entity.ad.AdPositionEnum;
|
import com.yeshi.base.entity.video.VideoInfo;
|
import com.yeshi.base.utils.BeibeiConstant;
|
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.entity.PushEpisode;
|
import com.yeshi.video.ui.adapter.EpisodePagerAdapter;
|
import com.yeshi.video.ui.adapter.GridVideoAdapter1;
|
import com.yeshi.video.utils.VideoApiUtil;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.util.List;
|
|
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 TabPageIndicator indicator_episode;
|
|
private ViewPager vp_episode;
|
|
private GridView gv_video_related_video, gv_video_guess_like,
|
gv_video_everybody_look;
|
|
private ScrollView sv_detail;
|
|
private EpisodePagerAdapter mEpisodePagerAdapter;
|
|
private TextView video_score, video_year, video_type, video_actor,
|
video_introduction, video_more_text;
|
private ImageView video_more_image;
|
private LinearLayout video_introduction_more;
|
private FrameLayout fl_native_ad1, fl_native_ad2, fl_native_ad3;
|
// 查看更多
|
private LinearLayout ll_more;
|
private ImageView iv_episode;
|
private TextView tv_more;
|
|
public static boolean isShowMore = false;// 是否显示更多
|
public static int page_varietyshow = 0;// 综艺节目的分页
|
int maxDescripLine = 2;
|
|
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);
|
// Log.i("result","进入了VideoEpisodeFragment");
|
return videoEpisodeFragment;
|
}
|
|
@Override
|
public int getContentResource() {
|
return R.layout.video_episode_fragment;
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
|
// Toast.makeText(getActivity(), "我到VideoEpisodeFragment了",
|
// Toast.LENGTH_LONG).show();
|
sv_detail = (ScrollView) contentView.findViewById(R.id.sv_detail);
|
// Log.i("result", "VideoEpisodeFragment被创建了");
|
mVideoInfo = (VideoInfo) getArguments().getSerializable("video_info");
|
mPlayingPosition = getArguments().getInt("playing_position");
|
tv_more = (TextView) contentView
|
.findViewById(R.id.tv_video_episode_more);
|
iv_episode = (ImageView) contentView
|
.findViewById(R.id.iv_video_episode_more);
|
ll_more = (LinearLayout) contentView
|
.findViewById(R.id.video_episode_tv_lookmore);
|
ll_more.setOnClickListener(this);
|
// ******简介*******
|
video_score = (TextView) contentView.findViewById(R.id.video_score);
|
video_year = (TextView) contentView.findViewById(R.id.video_year);
|
video_type = (TextView) contentView.findViewById(R.id.video_type);
|
video_actor = (TextView) contentView.findViewById(R.id.video_actor);
|
video_introduction = (TextView) contentView
|
.findViewById(R.id.video_introduction);
|
video_introduction_more = (LinearLayout) contentView
|
.findViewById(R.id.video_introduction_more);
|
video_more_image = (ImageView) contentView
|
.findViewById(R.id.video_more_image);
|
video_more_text = (TextView) contentView
|
.findViewById(R.id.video_more_text);
|
|
video_introduction_more.setOnClickListener(this);
|
indicator_episode = (TabPageIndicator) contentView
|
.findViewById(R.id.indicator_episode);
|
vp_episode = (ViewPager) contentView.findViewById(R.id.vp_episode);
|
|
gv_video_related_video = (GridView) contentView
|
.findViewById(R.id.gv_video_related_video);
|
|
fl_native_ad1 = (FrameLayout) contentView
|
.findViewById(R.id.fl_native_ad_1);
|
|
gv_video_guess_like = (GridView) contentView
|
.findViewById(R.id.gv_video_guess_like);
|
|
fl_native_ad2 = (FrameLayout) contentView
|
.findViewById(R.id.fl_native_ad_2);
|
|
gv_video_everybody_look = (GridView) contentView
|
.findViewById(R.id.gv_video_everybody_look);
|
|
fl_native_ad3 = (FrameLayout) contentView
|
.findViewById(R.id.fl_native_ad_3);
|
|
contentView.findViewById(R.id.ll_container).setFocusable(true);
|
contentView.findViewById(R.id.ll_container).setFocusableInTouchMode(
|
true);
|
|
gv_video_related_video
|
.setOnItemClickListener(new OnItemClickListener() {
|
|
@Override
|
public void onItemClick(AdapterView<?> parent, View view,
|
int position, long id) {
|
VideoDetailActivity.ChangeVideoEvent changeVideoEvent_related = new VideoDetailActivity.ChangeVideoEvent();
|
changeVideoEvent_related
|
.setVideoInfo((VideoInfo) parent
|
.getItemAtPosition(position));
|
changeVideoEvent_related.setTag("VideoPlayerFragment");
|
EventBus.getDefault().post(changeVideoEvent_related);
|
}
|
});
|
|
gv_video_guess_like.setOnItemClickListener(new OnItemClickListener() {
|
|
@Override
|
public void onItemClick(AdapterView<?> parent, View view,
|
int position, long id) {
|
// if (position == mVideoInfos.size() - 1) {
|
// mList.get(0).onAdClicked();
|
// } else {
|
VideoDetailActivity.ChangeVideoEvent changeVideoEvent = new VideoDetailActivity.ChangeVideoEvent();
|
changeVideoEvent.setVideoInfo((VideoInfo) parent
|
.getItemAtPosition(position));
|
changeVideoEvent.setTag("VideoPlayerFragment");
|
EventBus.getDefault().post(changeVideoEvent);
|
// }
|
}
|
});
|
|
gv_video_everybody_look
|
.setOnItemClickListener(new OnItemClickListener() {
|
|
@Override
|
public void onItemClick(AdapterView<?> parent, View view,
|
int position, long id) {
|
VideoDetailActivity.ChangeVideoEvent changeVideoEvent_look = new VideoDetailActivity.ChangeVideoEvent();
|
changeVideoEvent_look.setVideoInfo((VideoInfo) parent
|
.getItemAtPosition(position));
|
changeVideoEvent_look.setTag("VideoPlayerFragment");
|
EventBus.getDefault().post(changeVideoEvent_look);
|
}
|
});
|
|
if (mVideoInfo.getShowType() == 1) {// 综艺
|
indicator_episode.setVisibility(View.GONE);
|
if (mVideoInfo.getVideoDetailList().size() <= 2) {
|
ll_more.setVisibility(View.GONE);
|
} else {
|
ll_more.setVisibility(View.VISIBLE);
|
}
|
} else if (mVideoInfo.getShowType() == 2) {// 电视剧什么的
|
if (mVideoInfo.getVideoDetailList().size() <= 10) {
|
ll_more.setVisibility(View.GONE);
|
} else {
|
ll_more.setVisibility(View.VISIBLE);
|
}
|
}
|
mEpisodePagerAdapter = new EpisodePagerAdapter(
|
getChildFragmentManager(), mVideoInfo, mPlayingPosition);
|
//
|
vp_episode.setAdapter(mEpisodePagerAdapter);
|
indicator_episode.setViewPager(vp_episode);
|
// 指示当前播放页---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) {
|
|
}
|
}
|
});
|
gv_video_related_video.postDelayed(new Runnable() {
|
|
@Override
|
public void run() {
|
getRelativeVideos();
|
guessLike();
|
getPeopleSeeVideos();
|
}
|
}, 1000);
|
|
video_introduction.setHeight(video_introduction.getLineHeight()
|
* maxDescripLine);
|
video_introduction.post(new Runnable() {
|
|
@Override
|
public void run() {
|
video_introduction_more.setVisibility(video_introduction
|
.getLineCount() > maxDescripLine ? View.VISIBLE
|
: View.GONE);
|
|
}
|
});
|
if (AdUtil.getAdType(getContext(), AdPositionEnum.other) != null) {
|
// loadAD1();
|
loadAD();
|
}
|
getIntroductionInfo();
|
}
|
|
private void getIntroductionInfo() {
|
Log.i("", "");
|
video_score.setText((StringUtils.isEmpty(mVideoInfo.getArea()) ? "" : mVideoInfo
|
.getArea()));
|
video_year.setText("年份:" + mVideoInfo.getYear());
|
if (mVideoInfo.getVideoType() != null)
|
video_type
|
.setText("类型:"
|
+ (StringUtils.isEmpty(mVideoInfo.getVideoType()
|
.getName()) ? "未知" : mVideoInfo
|
.getVideoType().getName()));
|
video_actor.setText("主演:" + mVideoInfo.getMainActor());
|
if (!StringUtils.isBlank(mVideoInfo.getIntroduction())) {
|
video_introduction.setText("主要内容:" + mVideoInfo.getIntroduction());
|
} else {
|
video_introduction.setText("主要内容:");
|
}
|
}
|
|
private void getRelativeVideos() {
|
if (getActivity() == null)
|
return;
|
SharedPreferences preferences = getActivity().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
VideoApiUtil.getRelativeVideos(getActivity(), uid,
|
mVideoInfo.getId(), new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE)
|
.create();
|
List<VideoInfo> videoInfos = gson.fromJson(
|
jsonObject.getJSONObject("Data")
|
.getJSONArray("data").toString(),
|
new TypeToken<List<VideoInfo>>() {
|
}.getType());
|
gv_video_related_video
|
.setAdapter(new GridVideoAdapter1(
|
videoInfos, getActivity()
|
.getApplicationContext(),
|
false));
|
sv_detail.scrollTo(0, 0);
|
}
|
}
|
});
|
}
|
|
private void guessLike() {
|
if (getActivity() == null)
|
return;
|
SharedPreferences preferences = getActivity().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
VideoApiUtil.guessLike(getActivity(), uid, mVideoInfo.getId(),
|
new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE)
|
.create();
|
List<VideoInfo> videoInfos = gson.fromJson(
|
jsonObject.getJSONObject("Data")
|
.getJSONArray("data").toString(),
|
new TypeToken<List<VideoInfo>>() {
|
}.getType());
|
// 非聚效广告显示
|
gv_video_guess_like
|
.setAdapter(new GridVideoAdapter1(
|
videoInfos, getActivity()
|
.getApplicationContext(),
|
false));
|
sv_detail.scrollTo(0, 0);
|
// 聚效广告
|
// if (videoInfos.size() > 2) {
|
// videoInfos.remove(videoInfos.size() - 1);
|
// }
|
// mVideoInfos.addAll(videoInfos);
|
// mAdView.loadAds();
|
}
|
}
|
});
|
}
|
|
private void getPeopleSeeVideos() {
|
if (getActivity() == null)
|
return;
|
SharedPreferences preferences = getActivity().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
VideoApiUtil.getPeopleSeeVideos(getActivity(), uid,
|
mVideoInfo.getId(), new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE)
|
.create();
|
List<VideoInfo> videoInfos = gson.fromJson(
|
jsonObject.getJSONObject("Data")
|
.getJSONArray("data").toString(),
|
new TypeToken<List<VideoInfo>>() {
|
}.getType());
|
gv_video_everybody_look
|
.setAdapter(new GridVideoAdapter1(
|
videoInfos, getActivity()
|
.getApplicationContext(),
|
false));
|
sv_detail.scrollTo(0, 0);
|
}
|
}
|
});
|
}
|
|
@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;
|
}
|
mEpisodePagerAdapter = new EpisodePagerAdapter(
|
getChildFragmentManager(), info, mPlayingPosition);
|
//
|
vp_episode.setAdapter(mEpisodePagerAdapter);
|
}
|
|
public void onEventMainThread(PushEpisode info) {
|
// 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;
|
tv_more.setText("点击收起");
|
// Drawable drawable = getResources().getDrawable(
|
// R.drawable.more_introduction2);
|
// drawable.setBounds(0, 0, drawable.getMinimumWidth(),
|
// drawable.getMinimumHeight());// 必须设置图片大小,否则不显示
|
iv_episode.setImageResource(R.drawable.more_introduction2);
|
}
|
}
|
mEpisodePagerAdapter.setPlayingPosition(info.getEpisodeNum());
|
if (mVideoInfo != null && mVideoInfo.getVideoDetailList() != null
|
&& mVideoInfo.getVideoDetailList().size() > 12)
|
EpisodeFragment.refresh();
|
}
|
|
boolean isExpand;
|
|
@Override
|
public void onClick(View v) {
|
int id = v.getId();
|
if (id == R.id.video_introduction_more) {
|
isExpand = !isExpand;
|
video_introduction.clearAnimation();
|
final int deltaValue;
|
final int startValue = video_introduction.getHeight();
|
int durationMillis = 100;
|
if (isExpand) {
|
video_introduction_more.setVisibility(View.VISIBLE);
|
deltaValue = video_introduction.getLineHeight()
|
* video_introduction.getLineCount() - startValue;
|
RotateAnimation animation = new RotateAnimation(0, 180,
|
Animation.RELATIVE_TO_SELF, 0.5f,
|
Animation.RELATIVE_TO_SELF, 0.5f);
|
animation.setDuration(durationMillis);
|
animation.setFillAfter(true);
|
video_more_image.startAnimation(animation);
|
video_more_text.setText("点击收起");
|
|
} else {
|
video_introduction_more.setVisibility(View.VISIBLE);
|
deltaValue = video_introduction.getLineHeight()
|
* maxDescripLine - startValue;
|
RotateAnimation animation = new RotateAnimation(180, 0,
|
Animation.RELATIVE_TO_SELF, 0.5f,
|
Animation.RELATIVE_TO_SELF, 0.5f);
|
animation.setDuration(durationMillis);
|
animation.setFillAfter(true);
|
video_more_image.startAnimation(animation);
|
video_more_text.setText("查看更多");
|
|
}
|
Animation animation = new Animation() {
|
protected void applyTransformation(float interpolatedTime,
|
Transformation t) {
|
video_introduction.setHeight((int) (startValue + deltaValue
|
* interpolatedTime));
|
}
|
};
|
animation.setDuration(durationMillis);
|
video_introduction.startAnimation(animation);
|
} else if (id == R.id.video_episode_tv_lookmore) {// 查看更多
|
if (mVideoInfo.getShowType() == 1) {// 综艺 如果是综艺的话就分页加载
|
page_varietyshow++;
|
isShowMore = true;
|
} else {
|
if (!isShowMore) {// 如果还没有点击查看更多,点击后查看更多
|
isShowMore = true;
|
tv_more.setText("点击收起");
|
// Drawable drawable = getResources().getDrawable(
|
// R.drawable.more_introduction2);
|
// drawable.setBounds(0, 0, drawable.getMinimumWidth(),
|
// drawable.getMinimumHeight());// 必须设置图片大小,否则不显示
|
iv_episode.setImageResource(R.drawable.more_introduction2);
|
} else {// 如果以查看更多。点击后不查看更多
|
sv_detail.scrollTo(0, 0);// 回到顶部
|
isShowMore = false;
|
tv_more.setText("查看更多");
|
// Drawable drawable = getResources().getDrawable(
|
// R.drawable.more_introduction);
|
// drawable.setBounds(0, 0, drawable.getMinimumWidth(),
|
// drawable.getMinimumHeight());// 必须设置图片大小,否则不显示
|
// tv_more.setCompoundDrawables(null, null, drawable, null);
|
iv_episode.setImageResource(R.drawable.more_introduction);
|
}
|
}
|
EpisodeFragment.refresh();
|
}
|
}
|
|
|
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() > 1) {
|
list.get(1).render();
|
fl_native_ad2.removeAllViews();
|
fl_native_ad2.addView(list.get(1));
|
}
|
|
if (list.size() > 2) {
|
list.get(2).render();
|
fl_native_ad3.removeAllViews();
|
fl_native_ad3.addView(list.get(2));
|
}
|
}
|
|
@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(3);
|
}
|
|
}
|