admin
2020-10-17 2f9e1cb327b1d58e4035b77bd903a452774ce66b
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
package com.weikou.beibeivideo.ui.media;
 
import android.text.TextUtils;
import android.view.Gravity;
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 GridEpisodeAdapter2 extends BaseAdapter {
 
    private VideoInfo mVideoInfo;
 
    private int mPlayingPosition;
 
    public GridEpisodeAdapter2(VideoInfo videoInfo, int playingPosition) {
        super();
        this.mVideoInfo = videoInfo;
        this.mPlayingPosition = playingPosition;
    }
 
    @Override
    public int getCount() {
        return mVideoInfo == null ? 0
                : (VideoUtil.videoEpisodeList == null ? 0 : VideoUtil.videoEpisodeList.size());
    }
 
    @Override
    public Object getItem(int position) {
        return VideoUtil.videoEpisodeList.get(position);
    }
 
    @Override
    public long getItemId(int position) {
        return position;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = new TextView(parent.getContext());
            ((TextView) convertView).setGravity(Gravity.CENTER);
        }
        VideoDetailInfo videoDetailInfo = (VideoDetailInfo) getItem(position);
        if (position == mPlayingPosition) {
            ((TextView) convertView)
                    .setBackgroundResource(R.drawable.episode_playing2);
        } else {
            if (TextUtils.isEmpty(DownloadUtils.getOfflinePath(
                    parent.getContext(), mVideoInfo.getId(),
                    videoDetailInfo.getId()))) {
                ((TextView) convertView)
                        .setBackgroundResource(R.drawable.episode_unwatched2);
            } else {
                ((TextView) convertView)
                        .setBackgroundResource(R.drawable.episode_offlined2);
            }
        }
        ((TextView) convertView).setTextColor(parent.getResources().getColor(
                android.R.color.white));
        ((TextView) convertView).setText(TextUtils.isEmpty(videoDetailInfo
                .getTag()) ? videoDetailInfo.getName() : videoDetailInfo
                .getTag());
        return convertView;
    }
 
    public int getPlayingPosition() {
        return mPlayingPosition;
    }
 
    public void setPlayingPosition(int playingPosition) {
        this.mPlayingPosition = playingPosition;
    }
}