package com.rehome.filesync.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.rehome.filesync.R;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Q4UploadGridAdapter extends BaseAdapter {
    private List<File> files;
    private LayoutInflater inflater;
    Context context;


    public Q4UploadGridAdapter(List<File> files, Context context) {
        this.files = files;
        this.context=context;
        //这个意思就是 如果最后返回的列表有7哥 就把最后一个移除了
        inflater = LayoutInflater.from(context);
    }

    public int getCount() {
        return files.size();
    }

    @Override
    public String getItem(int position) {
        return files.get(position).getAbsolutePath();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.sblcsave_item, parent, false);
            holder.image = (ImageView) convertView.findViewById(R.id.imageView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final String path = files.get(position).getAbsolutePath();
        //这里是如果取到path的值是paizhao  就显示加好  如果不是  就是返回的那个图片
        RequestOptions options = new RequestOptions()
                .centerCrop()
                .placeholder(R.color.color_f6)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(context)
                .load(path)
                .apply(options)
                .into(holder.image);
        return convertView;
    }

    class ViewHolder {
        ImageView image;
    }
}