admin
6 天以前 7f0825f8195a522ed7e8bcdb6347f3a719e06c74
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.weikou.beibeivideo.ui.media;
 
import java.util.ArrayList;
import java.util.List;
 
import android.graphics.Color;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
 
import com.weikou.beibeivideo.R;
import com.weikou.beibeivideo.entity.VideoDetailInfo;
import com.weikou.beibeivideo.entity.VideoInfo;
import com.weikou.beibeivideo.util.DownloadUtils;
import com.weikou.beibeivideo.util.VideoUtil;
 
/**
 * 收起时显示的剧集适配器
 */
public class EpisodeAdapter2 extends BaseAdapter {
 
    private VideoInfo mVideoInfo;
    private int mPlayingPosition;
    private List<VideoDetailInfo> mList;
 
    public EpisodeAdapter2(VideoInfo videoInfo, int playingPosition) {
        super();
        mList = new ArrayList<VideoDetailInfo>();
        this.mVideoInfo = videoInfo;
        this.mPlayingPosition = playingPosition;
    }
 
    @Override
    public int getCount() {
        mList.clear();
        mList.addAll(VideoUtil.videoEpisodeList);
        int count = mList.size();
        if (mVideoInfo.getShowType() == 1) {// 电影
            // return count;
            // } else if (mStretch == 1) {// 综艺
            if (count > 2) {
                return 2;
            } else {
                return count;
            }
        } else {// 电视剧什么的,需要特殊处理,第一集显示用户选择的那集
            // 如果mPlayingPosition 为12 就添加原集合中的 position 1-12 一共12个数据到集合中
            // 首先,
            if (mPlayingPosition >= 10) {// 从1开始到12结束
                mList.clear();
                for (int i = mPlayingPosition - 9; i <= mPlayingPosition; i++) {
                    mList.add(VideoUtil.videoEpisodeList.get(i));
                }
                // 再重新赋值
                count = mList.size();
            }
            // 再对后续数据显示处理
            if (count > 10) {
                return 10;
            } else {
                return count;
            }
        }
    }
 
    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }
 
    @Override
    public long getItemId(int position) {
        return position;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_episode, null);
        TextView tv_episode = convertView.findViewById(R.id.tv_episode);
        VideoDetailInfo videoDetailInfo = (VideoDetailInfo) getItem(position);
        // 此处的position 从0开始 mPlayingPosition为12时 position应该是从1-12
        // mPlayingPosition为18时 position应该是从7-18
        if (mPlayingPosition >= 12 && position == mList.size() - 1) {// 用户选择大于12集以上内容时
 
 
            tv_episode.setBackgroundResource(R.drawable.shape_video_detail_episode_selected);
            tv_episode.setTextColor(Color.parseColor("#FFFFFF"));
 
 
        } else if (position == mPlayingPosition) {
                tv_episode.setBackgroundResource(R.drawable.shape_video_detail_episode_selected);
                tv_episode.setTextColor(Color.parseColor("#FFFFFF"));
        } else {
            if (TextUtils.isEmpty(DownloadUtils.getOfflinePath(
                    parent.getContext(), mVideoInfo.getId(),
                    videoDetailInfo.getId()))) {
                tv_episode.setBackgroundResource(R.drawable.episode_offlined);
            }
            tv_episode.setBackgroundResource(R.drawable.shape_video_detail_episode_unselected);
            tv_episode.setTextColor(Color.parseColor("#232323"));
        }
        if (mVideoInfo.getShowType() == 1) {
            // ((TextView) convertView).setText(videoDetailInfo.getName());
            // } else if (mStretch == 1) {
            if (videoDetailInfo.getIntroduction() == null) {
                videoDetailInfo.setIntroduction("");
            }
            tv_episode.setText(TextUtils.isEmpty(videoDetailInfo
                    .getTag()) ? ""
                    : (videoDetailInfo.getTag() + videoDetailInfo
                    .getIntroduction()));
        } else {
            tv_episode.setText(videoDetailInfo.getTag());
        }
        return convertView;
    }
}