package com.yeshi.video.ui.adapter;
|
|
import com.yeshi.base.entity.video.VideoInfo;
|
import com.yeshi.video.ui.EpisodeFragment;
|
|
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
|
public class EpisodePagerAdapter extends FragmentStatePagerAdapter {
|
|
private VideoInfo mVideoInfo;
|
|
private int mPlayingPosition;
|
|
public EpisodePagerAdapter(FragmentManager fm, VideoInfo videoInfo,
|
int playingPosition) {
|
super(fm);
|
// Log.i("result", "EpisodePagerAdapter 中电视剧的长度为:" + videoInfo.getVideoDetailList().size());
|
this.mVideoInfo = videoInfo;
|
this.mPlayingPosition = playingPosition;
|
}
|
|
@Override
|
public Fragment getItem(int position) {
|
int start = position * 20;
|
int end = start + 20;
|
if (end > mVideoInfo.getVideoDetailList().size()) {
|
end = mVideoInfo.getVideoDetailList().size();
|
}
|
return EpisodeFragment.newInstance(mVideoInfo, getPlayingPosition(), start,
|
end);
|
}
|
|
@Override
|
public int getCount() {
|
return 1;
|
// return mVideoInfo == null ? 0
|
// : (mVideoInfo.getVideoDetailList() == null ? 0
|
// : (mVideoInfo.getVideoDetailList().size() % 20 == 0 ?
|
// mVideoInfo.getVideoDetailList().size() / 20
|
// : mVideoInfo.getVideoDetailList().size() / 20 + 1));
|
}
|
|
// @Override
|
// public CharSequence getPageTitle(int position) {
|
// int start = position * 20;
|
// int end = start + 20;
|
// if (end > mVideoInfo.getVideoDetailList().size()) {
|
// end = mVideoInfo.getVideoDetailList().size();
|
// }
|
// return (start + 1) + "-" + end;
|
// }
|
|
@Override
|
public int getItemPosition(Object object) {
|
if (((EpisodeFragment) object).isPlaying()
|
|| ((EpisodeFragment) object).isVisible()) {
|
return POSITION_NONE;
|
}
|
return super.getItemPosition(object);
|
}
|
|
public int getPlayingPosition() {
|
return mPlayingPosition;
|
}
|
|
public void setPlayingPosition(int playingPosition) {
|
this.mPlayingPosition = playingPosition;
|
notifyDataSetChanged();
|
}
|
}
|