admin
2021-07-15 49982f5a1a305c0cc7da04735e1c604b802d2a22
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
123
124
125
126
127
128
129
130
131
132
package com.mugua.mgvideo.ui.category;
 
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.bumptech.glide.Glide;
import com.lcjian.library.util.common.StringUtils;
import com.mugua.mgvideo.R;
import com.yeshi.base.entity.video.VideoInfo;
import com.yeshi.video.ui.VideoDetailActivity;
 
import java.text.DecimalFormat;
import java.util.List;
 
public class CategoryListAdapter extends BaseAdapter {
    private Context mContext;
    private List<VideoInfo> mList;
 
    private LayoutInflater inflater;
 
    public CategoryListAdapter(List<VideoInfo> list, Context context) {
        super();
        this.mContext = context;
        this.mList = list;
    }
 
    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }
 
    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }
 
    @Override
    public long getItemId(int position) {
        return position;
    }
 
    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        inflater = LayoutInflater.from(parent.getContext());
        if (convertView == null) {
            holder = new Holder();
            convertView = inflater.inflate(R.layout.item_star_work, null);
            holder.fl_ad = convertView.findViewById(R.id.fl_ad);
            holder.fl_content= convertView.findViewById(R.id.fl_content);
            holder.iv_moive_img = (ImageView) convertView.findViewById(R.id.iv_moive_img);
            holder.tv_moive_name = (TextView) convertView.findViewById(R.id.tv_moive_name);
            holder.tv_moive_score = (TextView) convertView.findViewById(R.id.tv_moive_score);
            holder.tv_moive_play_num = (TextView) convertView.findViewById(R.id.tv_moive_play_num);
            holder.tv_moive_comment_num = (TextView) convertView.findViewById(R.id.tv_moive_comment_num);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        final VideoInfo info = (VideoInfo) getItem(position);
        if (info.getAdView() == null) {
            holder.fl_ad.setVisibility(View.GONE);
            holder.fl_content.setVisibility(View.VISIBLE);
            holder.iv_moive_img.setVisibility(View.VISIBLE);
            try {
                Glide.with(mContext).load(info.getPicture()).into(holder.iv_moive_img);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            holder.tv_moive_name.setText(info.getName() + "");
            holder.tv_moive_score.setText(StringUtils.isEmpty(info.getTag()) ? "" : info.getTag());
//        holder.tv_moive_play_num.setText(info.getWatchCount());
            DecimalFormat df = new DecimalFormat("###.0");
            holder.tv_moive_play_num.setText(StringUtils.isBlank(info
                    .getWatchCount()) ? "0" : (Integer.parseInt(info
                    .getWatchCount())) / 10000 > 0 ? df.format(Integer.parseInt(info
                    .getWatchCount()) / 10000f) + "万" : info
                    .getWatchCount() + "");
            holder.tv_moive_comment_num.setText(info.getCommentCount());
        } else {
            holder.iv_moive_img.setVisibility(View.GONE);
            holder.fl_ad.setVisibility(View.VISIBLE);
            holder.fl_content.setVisibility(View.GONE);
            info.getAdView().render();
            FrameLayout adParent = (FrameLayout) info.getAdView().getParent();
            if (adParent != null) {
                adParent.removeAllViews();
            }
            holder.fl_ad.addView(info.getAdView());
        }
        convertView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
                if (info.getAdView() == null) {
                    myClick(info, v);
                } else {//广告点击
                   ;
                }
 
            }
        });
        return convertView;
    }
 
    private void myClick(VideoInfo videoInfo, View v) {
        Intent intent = new Intent(v.getContext(), VideoDetailActivity.class);
        intent.putExtra("video_info", videoInfo);
        v.getContext().startActivity(intent);
    }
 
    class Holder {
        ImageView iv_moive_img;
        TextView tv_moive_name;
        TextView tv_moive_score;
        TextView tv_moive_play_num;
        TextView tv_moive_comment_num;
        FrameLayout fl_ad,fl_content;
    }
}