riku
2020-10-10 5771916ffb24807dd57c1969baa6371611c334da
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
package cn.flightfeather.thirdapp.adapter;
 
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
 
import com.ping.greendao.gen.MediafileDao;
 
import java.io.File;
import java.io.Serializable;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
import cn.flightfeather.thirdapp.CommonApplication;
import cn.flightfeather.thirdapp.R;
import cn.flightfeather.thirdapp.activity.PhotoViewerActivity;
import cn.flightfeather.thirdapp.activity.PromiseActivity;
import cn.flightfeather.thirdapp.activity.SignActivity;
import cn.flightfeather.thirdapp.bean.AllBoolean;
import cn.flightfeather.thirdapp.bean.Inspection;
import cn.flightfeather.thirdapp.bean.Mediafile;
import cn.flightfeather.thirdapp.bean.vo.ProblemlistVo;
import cn.flightfeather.thirdapp.httpservice.InspectionService;
import cn.flightfeather.thirdapp.task.DownloadAndSetImageTask;
import cn.flightfeather.thirdapp.task.SetImageTask;
import cn.flightfeather.thirdapp.util.DateFormatter;
 
/**
 * Created by note_ff_1602 on 2018/3/2.
 */
 
public class ProblemPromiseListAdapter extends RecyclerView.Adapter<ProblemPromiseListAdapter.ProblemPromiseListHolder>{
    private List<ProblemlistVo> problemlistVoList;
    private Context context;
    private LayoutInflater layoutInflater;
    private ProblemlistVo problemlistVoCurrent;
    private MediafileDao mediafileDao;
    private InspectionService inspectionService;
    private Inspection inspectionCurrent;
    private File signFile;
    private List<Mediafile> signMediafileList;
    private CommonApplication application;
    private PromiseActivity promiseActivity;
    private final int SIGN = 9;
    private final int VIEW_SIGN_PHOTO = 117;
    private AllBoolean allBoolean;
 
 
    public ProblemPromiseListAdapter(List<ProblemlistVo> problemlistVoList, Context context, CommonApplication application,PromiseActivity promiseActivity,List<Mediafile> signMediaFileList, AllBoolean allBoolean) {
        this.problemlistVoList = problemlistVoList;
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        mediafileDao = application.getDaoSession().getMediafileDao();
        this.application =application;
        this.promiseActivity = promiseActivity;
        this.signMediafileList = signMediaFileList;
        this.allBoolean = allBoolean;
    }
 
    @Override
    public ProblemPromiseListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.item_problem_promise,parent,false);
        return new ProblemPromiseListHolder(view, new CustomTextWatcher(), new SignClickListener(), new TimeClickListener(), new PhotoClickListener1(), new PhotoClickListener2(), new PhotoClickListener3());
    }
 
    @Override
    public void onBindViewHolder(ProblemPromiseListHolder holder, int position) {
        if (position<problemlistVoList.size()){
            holder.iv_sign.setVisibility(View.GONE);
            holder.tv_sign.setVisibility(View.GONE);
            holder.ll_promise.setVisibility(View.VISIBLE);
            holder.customTextWatcher.updatePosition(position);
            holder.timeClickListener.updatePosition(position);
            holder.photoClickListener1.updatePosition(position);
            holder.photoClickListener2.updatePosition(position);
            holder.photoClickListener3.updatePosition(position);
            problemlistVoCurrent = problemlistVoList.get(position);
            holder.tv_count.setText(""+(position+1));
            holder.tv_name.setText(problemlistVoCurrent.getProblemname());
            if (problemlistVoCurrent.getLocation()!=null){
                holder.tv_location.setText(problemlistVoCurrent.getLocation());
            }
            if (problemlistVoCurrent.getExtension1()!=null){
                holder.tv_time.setText(problemlistVoCurrent.getExtension1());
            }else {
                String date = DateFormatter.dateFormat.format(new Date());
                holder.tv_time.setText(date);
                problemlistVoCurrent.setExtension1(date);
            }
 
            if (problemlistVoCurrent.getExtension2()!=null){
                holder.et_promise.setText(problemlistVoCurrent.getExtension2());
            }
            List<Mediafile> mediafileList = problemlistVoCurrent.getMediafileList();
            List<Mediafile> mediafileList1 = mediafileDao.queryBuilder().where(MediafileDao.Properties.Businessguid.eq(problemlistVoCurrent.getGuid())).where(MediafileDao.Properties.Remark.eq("未上传")).list();
            if (!mediafileList.containsAll(mediafileList1)){
                mediafileList.addAll(mediafileList1);
            }
            List<Mediafile> changedMediaFilelist = new ArrayList<>();
            for (Mediafile mediafile:mediafileList){
                if (mediafile.getIschanged()){
                    changedMediaFilelist.add(mediafile);
                }
            }
            mediafileList.removeAll(changedMediaFilelist);
 
            if (mediafileList!=null&&mediafileList.size()>0){
 
                if (mediafileList.size() ==1){
                    holder.iv_photo1.setVisibility(View.VISIBLE);
                    setImage(mediafileList.get(0),holder.iv_photo1);
                    holder.iv_photo2.setVisibility(View.GONE);
                    holder.iv_photo3.setVisibility(View.GONE);
 
                }else if (mediafileList.size() ==2){
                    holder.iv_photo1.setVisibility(View.VISIBLE);
                    holder.iv_photo2.setVisibility(View.VISIBLE);
                    setImage(mediafileList.get(0),holder.iv_photo1);
                    setImage(mediafileList.get(1),holder.iv_photo2);
                    holder.iv_photo3.setVisibility(View.GONE);
 
                }else if (mediafileList.size() ==3){
                    holder.iv_photo1.setVisibility(View.VISIBLE);
                    holder.iv_photo2.setVisibility(View.VISIBLE);
                    holder.iv_photo3.setVisibility(View.VISIBLE);
                    setImage(mediafileList.get(0),holder.iv_photo1);
                    setImage(mediafileList.get(1),holder.iv_photo2);
                    setImage(mediafileList.get(2),holder.iv_photo3);
 
                }else if (mediafileList.size() ==0){
                    holder.iv_photo1.setVisibility(View.GONE);
                    holder.iv_photo2.setVisibility(View.GONE);
                    holder.iv_photo3.setVisibility(View.GONE);
                }
 
            }else {
                holder.iv_photo1.setVisibility(View.GONE);
                holder.iv_photo2.setVisibility(View.GONE);
                holder.iv_photo3.setVisibility(View.GONE);
            }
            if (allBoolean.isAll()){
                holder.ll_promise2.setVisibility(View.GONE);
            }else {
                holder.ll_promise2.setVisibility(View.VISIBLE);
            }
        }else {
            holder.ll_promise.setVisibility(View.GONE);
            holder.tv_sign.setVisibility(View.VISIBLE);
            holder.iv_sign.setVisibility(View.VISIBLE);
            if (signMediafileList!=null&&signMediafileList.size()>0){
                setImage(signMediafileList.get(0),holder.iv_sign);
            }else {
                holder.iv_sign.setImageResource(R.drawable.icon_add_sign);
            }
        }
 
 
    }
    //设置图片
    private void setImage(Mediafile mediafile,ImageView imageView){
        File file = new File(Environment.getExternalStorageDirectory(), (mediafile.getPath() + mediafile.getDescription()));
            if (file.exists()){
                SetImageTask task1 = new SetImageTask(file,imageView);
                task1.execute();
            }else {
                DownloadAndSetImageTask task2 = new DownloadAndSetImageTask(mediafile,imageView,context);
                task2.execute();
            }
    }
 
 
 
    @Override
    public int getItemCount() {
        return (problemlistVoList.size()+1);
    }
 
 
    public class ProblemPromiseListHolder extends RecyclerView.ViewHolder{
        LinearLayout ll_promise;
        ImageView iv_sign;
        TextView tv_name;
        TextView tv_location;
        TextView tv_time;
        EditText et_promise;
        TextView tv_count;
        ImageView iv_photo1;
        ImageView iv_photo2;
        ImageView iv_photo3;
        CustomTextWatcher customTextWatcher;
        TimeClickListener timeClickListener;
        PhotoClickListener1 photoClickListener1;
        PhotoClickListener2 photoClickListener2;
        PhotoClickListener3 photoClickListener3;
        LinearLayout ll_promise2;
        TextView tv_sign;
 
        public ProblemPromiseListHolder(View itemView, CustomTextWatcher watcher, SignClickListener signClickListener,
                                        TimeClickListener timeClickListener,
                                        PhotoClickListener1 photoClickListener1, PhotoClickListener2 photoClickListener2, PhotoClickListener3 photoClickListener3) {
            super(itemView);
            ll_promise = (LinearLayout) itemView.findViewById(R.id.ll_promise);
            iv_sign = (ImageView) itemView.findViewById(R.id.iv_sign);
            tv_name = (TextView) itemView.findViewById(R.id.tv_problem_name);
            tv_location = (TextView) itemView.findViewById(R.id.tv_problem_location);
            tv_time = (TextView) itemView.findViewById(R.id.tv_time);
            et_promise = (EditText) itemView.findViewById(R.id.et_promise);
            tv_count = (TextView) itemView.findViewById(R.id.tv_count);
            iv_photo1 = (ImageView) itemView.findViewById(R.id.iv_photo1);
            iv_photo2 = (ImageView) itemView.findViewById(R.id.iv_photo2);
            iv_photo3 = (ImageView) itemView.findViewById(R.id.iv_photo3);
            ll_promise2 = (LinearLayout) itemView.findViewById(R.id.ll_promise2);
            tv_sign = (TextView) itemView.findViewById(R.id.tv_sign);
            iv_sign.setOnClickListener(signClickListener);
            this.customTextWatcher = watcher;
            this.timeClickListener = timeClickListener;
            et_promise.addTextChangedListener(watcher);
            tv_time.setOnClickListener(timeClickListener);
            this.photoClickListener1 = photoClickListener1;
            this.photoClickListener2 = photoClickListener2;
            this.photoClickListener3 = photoClickListener3;
            iv_photo1.setOnClickListener(photoClickListener1);
            iv_photo2.setOnClickListener(photoClickListener2);
            iv_photo3.setOnClickListener(photoClickListener3);
        }
    }
 
    public class  CustomTextWatcher implements TextWatcher{
        private int position;
 
        public void updatePosition(int position) {
            this.position = position;
        }
 
 
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
 
        }
 
        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
 
        }
 
        @Override
        public void afterTextChanged(Editable editable) {
            problemlistVoList.get(position).setExtension2(editable.toString());
 
 
        }
    }
    //签名的点击事件
    public class SignClickListener implements View.OnClickListener{
 
        @Override
        public void onClick(View view) {
            if (signMediafileList!=null&&signMediafileList.size()>0){
                Mediafile mediaFile = signMediafileList.get(0);
                File file = new File(Environment.getExternalStorageDirectory(), (mediaFile.getPath() + mediaFile.getDescription()));
                List<File> files = new ArrayList<>();
                files.add(file);
                Intent intent = new Intent(application, PhotoViewerActivity.class);
//                intent.putExtra("file", file);
                intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) files);
                intent.putExtra("type", PhotoViewerActivity.CAMERA_PHOTO);
                intent.putExtra("deletable", true);
//                intent.putExtra("mediaFile", mediaFile);
                intent.putExtra(PhotoViewerActivity.PARA_MEDIAS, (Serializable) signMediafileList);
                promiseActivity.startActivityForResult(intent, VIEW_SIGN_PHOTO);
            }else {
                promiseActivity.startActivityForResult(new Intent(promiseActivity, SignActivity.class), SIGN);
            }
        }
    }
    //时间的点击事件
    public class TimeClickListener implements View.OnClickListener{
        private int position;
 
        public void updatePosition(int position) {
            this.position = position;
        }
        @Override
        public void onClick(View view) {
            Calendar calendar = Calendar.getInstance();
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            if (  problemlistVoList.get(position).getExtension1()!=null){
                try {
                    Date date = DateFormatter.dateFormat.parse(problemlistVoList.get(position).getExtension1());
                    Calendar calendar1 =Calendar.getInstance();
                    calendar1.setTime(date);
                    year = calendar1.get(Calendar.YEAR);
                    month = calendar1.get(Calendar.MONTH);
                    day = calendar1.get(Calendar.DAY_OF_MONTH);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            DatePickerDialog dp = new DatePickerDialog(promiseActivity, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
                    Calendar calendar2 = Calendar.getInstance();
                    calendar2.set(year,monthOfYear,dayOfMonth);
                    String date = DateFormatter.dateFormat.format(calendar2.getTime());
                    problemlistVoList.get(position).setExtension1(date);
                    ProblemPromiseListAdapter.this.notifyDataSetChanged();
                }
            }, year, month, day);
 
            dp.show();
        }
    }
    //图片1的点击事件
    public class PhotoClickListener1 implements View.OnClickListener{
        private int position;
 
        public void updatePosition(int position) {
            this.position = position;
        }
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(promiseActivity,PhotoViewerActivity.class);
            List<Mediafile> mediaFileList = problemlistVoList.get(position).getMediafileList();
            List<File> files = new ArrayList<>();
            for (Mediafile m : mediaFileList) {
                File file = new File(Environment.getExternalStorageDirectory(), (m.getPath() + m.getDescription()));
                files.add(file);
            }
 
            intent.putExtra("deletable",false);
            intent.putExtra(PhotoViewerActivity.PARA_MEDIAS, (Serializable) mediaFileList);
//            intent.putExtra("mediaFile",mediaFile);
            intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) files);
//            intent.putExtra("file",file);
            intent.putExtra("type",PhotoViewerActivity.PROBLEM_PHOTO);
            promiseActivity.startActivity(intent);
        }
    }
    //图片2的点击事件
    public class PhotoClickListener2 implements View.OnClickListener{
        private int position;
 
        public void updatePosition(int position) {
            this.position = position;
        }
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(promiseActivity,PhotoViewerActivity.class);
            List<Mediafile> mediaFileList = problemlistVoList.get(position).getMediafileList();
            List<File> files = new ArrayList<>();
            for (Mediafile m : mediaFileList) {
                File file = new File(Environment.getExternalStorageDirectory(), (m.getPath() + m.getDescription()));
                files.add(file);
            }
 
            intent.putExtra("deletable",false);
            intent.putExtra(PhotoViewerActivity.PARA_MEDIAS, (Serializable) mediaFileList);
//            intent.putExtra("mediaFile",mediaFile);
            intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) files);
//            intent.putExtra("file",file);
            intent.putExtra("type",PhotoViewerActivity.PROBLEM_PHOTO);
            promiseActivity.startActivity(intent);
        }
    }
 
    //图片3的点击事件
    public class PhotoClickListener3 implements View.OnClickListener{
        private int position;
 
        public void updatePosition(int position) {
            this.position = position;
        }
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(promiseActivity,PhotoViewerActivity.class);
            List<Mediafile> mediaFileList = problemlistVoList.get(position).getMediafileList();
            List<File> files = new ArrayList<>();
            for (Mediafile m : mediaFileList) {
                File file = new File(Environment.getExternalStorageDirectory(), (m.getPath() + m.getDescription()));
                files.add(file);
            }
 
            intent.putExtra("deletable",false);
            intent.putExtra(PhotoViewerActivity.PARA_MEDIAS, (Serializable) mediaFileList);
//            intent.putExtra("mediaFile",mediaFile);
            intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) files);
//            intent.putExtra("file",file);
            intent.putExtra("type",PhotoViewerActivity.PROBLEM_PHOTO);
            promiseActivity.startActivity(intent);
        }
    }
 
}