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
package com.yeshi.video.ui.adapter;
 
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.yeshi.base.entity.video.VideoDetailInfo;
import com.yeshi.base.entity.video.VideoInfo;
import com.yeshi.base.utils.downutil.DownloadUtils;
import com.yeshi.video.R;
 
public class GridEpisodeAdapter extends BaseAdapter {
    
    private VideoInfo mVideoInfo;
    
    private int mPlayingPosition;
 
    public GridEpisodeAdapter(VideoInfo videoInfo, int playingPosition) {
        super();
        this.mVideoInfo = videoInfo;
        this.mPlayingPosition = playingPosition;
    }
 
    @Override
    public int getCount() {
        return mVideoInfo == null ? 0
                : (mVideoInfo.getVideoDetailList() == null ? 0 : mVideoInfo.getVideoDetailList().size());
    }
 
    @Override
    public Object getItem(int position) {
        return mVideoInfo.getVideoDetailList().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_playing);
            ((TextView) convertView).setTextColor(parent.getResources().getColor(android.R.color.white));
        } else {
            if (TextUtils.isEmpty(DownloadUtils.getOfflinePath(parent.getContext(), mVideoInfo.getId(), videoDetailInfo.getId()))) {
                ((TextView) convertView).setBackgroundResource(R.drawable.episode_offlined);
                ((TextView) convertView).setTextColor(parent.getResources().getColor(android.R.color.white));
            }
            ((TextView) convertView).setBackgroundResource(R.drawable.episode_unwatched);
            ((TextView) convertView).setTextColor(parent.getResources().getColor(android.R.color.black));
        }
        if (mVideoInfo.getVideoDetailList().size() == 1) {
            ((TextView) convertView).setText(TextUtils.isEmpty(videoDetailInfo.getTag()) ? videoDetailInfo.getName() : videoDetailInfo.getTag());
        } else {
            ((TextView) convertView).setText(String.valueOf(position + 1));
        }
        return convertView;
    }
 
    public int getPlayingPosition() {
        return mPlayingPosition;
    }
 
    public void setPlayingPosition(int playingPosition) {
        this.mPlayingPosition = playingPosition;
    }
}