admin
2022-01-13 b9ed091e3b607af409e30aca468958cdb08641ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.ysvideo.zhibo.app.ui.video.adapter;
 
 
import com.ysvideo.zhibo.app.entity.video.VideoInfo;
import com.ysvideo.zhibo.app.ui.video.EpisodeFragment;
import com.ysvideo.zhibo.app.ui.video.VideoDescFragment;
 
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
 
public class EpisodePagerAdapter extends FragmentPagerAdapter {
 
    private VideoInfo mVideoInfo;
 
    private int mPlayingPosition;
 
    private String resourceId;
 
    public EpisodePagerAdapter(FragmentManager fm, VideoInfo videoInfo, String resourceId,
                               int playingPosition) {
        super(fm);
//        Log.i("result", "EpisodePagerAdapter 中电视剧的长度为:" + videoInfo.getVideoDetailList().size());
        this.mVideoInfo = videoInfo;
        this.mPlayingPosition = playingPosition;
        this.resourceId = resourceId;
    }
 
    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            int start = position * 20;
            int end = start + 20;
            if (end > mVideoInfo.getVideoDetailList().size()) {
                end = mVideoInfo.getVideoDetailList().size();
            }
            return EpisodeFragment.newInstance(mVideoInfo, getPlayingPosition(), resourceId, start,
                    end);
        } else {
            return VideoDescFragment.newInstance(mVideoInfo);
        }
    }
 
    @Override
    public int getCount() {
        return 2;
    }
 
 
    public int getPlayingPosition() {
        return mPlayingPosition;
    }
 
    public void setPlayingPosition(int playingPosition) {
        this.mPlayingPosition = playingPosition;
        notifyDataSetChanged();
    }
}