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
package cn.flightfeather.thirdapp.adapter;
 
import android.content.Context;
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.thirdapp.R;
import cn.flightfeather.thirdapp.bean.Mediafile;
import cn.flightfeather.thirdapp.task.DownloadAndSetImageTask;
 
/**
 * Created by note_ff_1602 on 2018/1/30.
 */
 
public class PhotoListAdapter extends RecyclerView.Adapter<PhotoListAdapter.PhotoListHolder> {
    private List<Mediafile> mediafileList;
    private Context context;
    private LayoutInflater layoutInflater;
 
    public PhotoListAdapter(List<Mediafile> mediafileList, Context context) {
        this.mediafileList = mediafileList;
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
    }
 
    @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);
//        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(context)
                    .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,context);
            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);
        }
    }
}