admin
2021-09-30 2f1ab8af88cae4e723126ea5cf2f7d42dff7dbdc
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package com.weikou.beibeivideo.ui.dialog;
 
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
 
import com.androidquery.AQuery;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.lcjian.library.util.common.StringUtils;
import com.weikou.beibeivideo.R;
import com.weikou.beibeivideo.entity.VideoResource;
import com.weikou.beibeivideo.entity.vo.PPTVWatchVIPVideoActivityWay;
import com.weikou.beibeivideo.util.DimenUtils;
 
import java.util.List;
 
/**
 * vip弹框
 */
public class VideoResourceListDialog extends Dialog {
 
    private static String TAG = VideoResourceListDialog.class.getName();
 
    public VideoResourceListDialog(Context context) {
        super(context);
        this.setCancelable(false);
    }
 
    public VideoResourceListDialog(Context context, int theme) {
        super(context, theme);
        this.setCancelable(false);
    }
 
 
    public static class Builder {
 
 
        private Activity context;
 
        public Builder(Activity context) {
            this.context = context;
        }
 
        private View.OnClickListener closeListener;
 
        private ItemClickListener itemClickListener;
 
        private List<VideoResource> resourceList;
 
 
        public Builder setCloseListener(View.OnClickListener listener) {
            this.closeListener = listener;
            return this;
        }
 
 
        public Builder setItemClickListener(ItemClickListener listener) {
            this.itemClickListener = listener;
            return this;
        }
 
        public Builder setVideoResources(List<VideoResource> resources) {
            this.resourceList = resources;
            return this;
        }
 
 
        public VideoResourceListDialog create() {
 
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final VideoResourceListDialog dialog = new VideoResourceListDialog(context, R.style.Dialog);
            dialog.setCanceledOnTouchOutside(true);
            final View layout = inflater.inflate(R.layout.item_video_resource_list, null);
            AQuery aQuery = new AQuery(layout);
            aQuery.id(R.id.lv_resources).adapter(new ResourceAdapter(resourceList));
            aQuery.id(R.id.lv_resources).itemClicked(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    itemClickListener.onClick(position, resourceList.get(position));
                }
            });
 
            aQuery.id(R.id.tv_cancel).clicked(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (closeListener != null)
                        closeListener.onClick(v);
                }
            });
 
 
            dialog.setContentView(layout);
 
            WindowManager.LayoutParams params = dialog.getWindow()
                    .getAttributes();
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            dialog.getWindow().setAttributes(params);
            dialog.getWindow().setGravity(Gravity.BOTTOM);
            return dialog;
        }
 
 
        private class ResourceAdapter extends BaseAdapter {
            List<VideoResource> reList;
 
            public ResourceAdapter(List<VideoResource> list) {
                reList = list;
            }
 
            @Override
            public int getCount() {
                return reList.size();
            }
 
            @Override
            public Object getItem(int position) {
                return reList.get(position);
            }
 
            @Override
            public long getItemId(int position) {
                return position;
            }
 
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View view = LayoutInflater.from(context).inflate(
                        R.layout.item_resource, null);
                ImageView iv = view.findViewById(R.id.iv_resource);
                TextView tv = view.findViewById(R.id.tv_resource);
                TextView tv_input = view.findViewById(R.id.tv_input);
                try {
                    Glide.with(iv)
                            .load(reList.get(position).getPicture())
                            .apply(new RequestOptions().placeholder(R.drawable.from_other).error(R.drawable.from_other))
                            .into(iv);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
                if (reList.get(position) == null
                        || StringUtils.isEmpty(reList.get(position).getName())) {
                    tv.setText("其它");
                } else {
                    tv.setText(reList.get(position).getName());
                }
 
                int background = 0;
 
                tv_input.setText(reList.get(position).isChecked() ? "当前浏览" : "");
 
                background = reList.get(position).isChecked() ? R.drawable.shape_video_detail_resource_middle_item_selected_bg : R.drawable.shape_video_detail_resource_middle_item_bg;
//TODO 解决bug
//                ViewGroup.LayoutParams params =view.getLayoutParams();
//                params.width=ViewGroup.LayoutParams.MATCH_PARENT;
//                params.height=DimenUtils.dip2px(context, 64);
                view.setBackgroundResource(background);
 
                return view;
            }
        }
 
 
    }
 
    public interface MeasureCallBack {
        public void onMeasure(int height);
    }
 
 
    public interface ItemClickListener {
        public void onClick(int position, VideoResource videoResource);
    }
}