package com.yeshi.video.ui.adapter;
|
|
import com.lcjian.library.util.common.StringUtils;
|
import com.yeshi.base.entity.video.VideoInfo;
|
import com.yeshi.video.entity.PushEpisode;
|
import com.yeshi.video.ui.VideoEpisodeFragment;
|
import com.yeshi.video.ui.VideoReviewFragment;
|
|
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentPagerAdapter;
|
import de.greenrobot.event.EventBus;
|
|
public class VideoDetailAdapter extends FragmentPagerAdapter {
|
|
private VideoInfo mVideoInfo;
|
|
private int mPlayingPosition;
|
|
public VideoDetailAdapter(FragmentManager fm, VideoInfo videoInfo,
|
int playingPosition) {
|
super(fm);
|
this.mVideoInfo = videoInfo;
|
this.mPlayingPosition = playingPosition;
|
}
|
|
@Override
|
public Fragment getItem(int position) {
|
Fragment fragment = null;
|
switch (position) {
|
case 0: {
|
if (!(VideoEpisodeFragment.newInstance(mVideoInfo,
|
mPlayingPosition)).isAdded())
|
fragment = VideoEpisodeFragment.newInstance(mVideoInfo,
|
mPlayingPosition);
|
}
|
break;
|
case 1: {
|
if (!(VideoReviewFragment.newInstance(mVideoInfo,
|
mPlayingPosition)).isAdded())
|
fragment = VideoReviewFragment.newInstance(mVideoInfo,
|
mPlayingPosition);
|
}
|
break;
|
// case 2: {
|
// fragment = VideoReviewFragment.newInstance(mVideoInfo,
|
// mPlayingPosition);
|
// }
|
// break;
|
default:
|
fragment = null;
|
break;
|
}
|
return fragment;
|
}
|
|
@Override
|
public int getCount() {
|
if (mVideoInfo == null) {
|
return 0;
|
}
|
int count = 2;
|
// if (TextUtils.isEmpty(mVideoInfo.getIntroduction())) {
|
// count--;
|
// }
|
return count;
|
}
|
|
@Override
|
public CharSequence getPageTitle(int position) {
|
String pageTitle;
|
switch (position) {
|
case 0: {
|
pageTitle = "列表";
|
}
|
break;
|
case 1: {
|
// if (TextUtils.isEmpty(mVideoInfo.getIntroduction())) {
|
// pageTitle = "评论";
|
// } else {
|
// pageTitle = "简介";
|
// }
|
pageTitle = StringUtils.isEmpty(mVideoInfo.getCommentCount()) ? ""
|
: "评论 " + mVideoInfo.getCommentCount().toString();
|
}
|
break;
|
// case 2: {
|
// pageTitle = "评论";
|
// }
|
// break;
|
default:
|
pageTitle = "";
|
break;
|
}
|
return pageTitle;
|
}
|
|
public void setPlayingPosition(int playingPosition) {
|
this.mPlayingPosition = playingPosition;
|
PushEpisode info = new PushEpisode();
|
info.setEpisodeNum(playingPosition);
|
EventBus.getDefault().post(info);
|
}
|
}
|