riku
2025-10-31 1897c4ad5fa73b3f0a36e1aa0e1e9000302a6ace
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
package cn.flightfeather.thirdappmodule.adapter;
 
import android.app.Activity;
import android.os.Environment;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
 
import com.bumptech.glide.Glide;
 
import java.io.File;
import java.util.List;
 
import cn.flightfeather.thirdappmodule.R;
import cn.flightfeather.thirdappmodule.bean.entity.Mediafile;
import cn.flightfeather.thirdappmodule.task.DownloadAndSetImageTask;
 
/**
 * Created by note_ff_1602 on 2018/1/30.
 */
 
public class PhotoListAdapter extends RecyclerView.Adapter<PhotoListAdapter.PhotoListHolder> {
    private List<Mediafile> mediafileList;
    private Activity activity;
    private LayoutInflater layoutInflater;
 
    public PhotoListAdapter(List<Mediafile> mediafileList, Activity activity) {
        this.mediafileList = mediafileList;
        this.activity = activity;
        layoutInflater = LayoutInflater.from(activity);
    }
 
    @Override
    public PhotoListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.item_square_photo, parent, false);
        return new PhotoListHolder(view);
    }
 
    @Override
    public void onBindViewHolder(PhotoListHolder holder, int position) {
        Mediafile mediafile = mediafileList.get(position);
 
        if (mediafile.getGuid() == null) {
            Glide.with(activity)
                    .load(R.drawable.icon_add_photo)
                    .into(holder.iv_photo);
        } else {
//        String url = CommonApplication.getInstance().ROOT_URL_RELEASE_IMAGE + mediafile.getExtension1() + mediafile.getGuid() + ".jpg";
//        Glide.with(context).asDrawable().load(url).override(100,100).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.iv_photo);
 
            File file = new File(Environment.getExternalStorageDirectory(), mediafile.getPath() + mediafile.getDescription());
            if (file.exists()) {
//            SetImageTask task = new SetImageTask(file,holder.iv_photo);
//            task.execute();
//            String url = CommonApplication.getInstance().ROOT_URL_RELEASE_IMAGE + mediafile.getExtension1() + mediafile.getGuid() + ".jpg";
                Glide.with(activity)
                        .load(file)
                        .placeholder(R.drawable.icon_add_photo_waite)
                        .override(100, 100)
                        .into(holder.iv_photo);
            } else {
                DownloadAndSetImageTask task = new DownloadAndSetImageTask(mediafile, holder.iv_photo, activity);
                task.execute();
                Log.e("photolist", position + " no image found");
            }
        }
    }
 
    @Override
    public int getItemCount() {
        return mediafileList.size();
    }
 
    public class PhotoListHolder extends RecyclerView.ViewHolder {
        ImageView iv_photo;
 
        public PhotoListHolder(View itemView) {
            super(itemView);
            iv_photo = (ImageView) itemView.findViewById(R.id.iv_photo);
        }
    }
}