admin
2021-07-20 27bd1f81221b8c8e8047118a64c2beb7bc214bbb
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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);
    }
}