package com.example.wallpapermagazine.adapter.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.TextView;

import androidx.core.content.ContextCompat;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.example.wallpapermagazine.R;
import com.example.wallpapermagazine.ReadFile;
import com.example.wallpapermagazine.WallPaperSelect;
import com.example.wallpapermagazine.json.Info_data;

import java.util.Collections;
import java.util.List;

public class MycataAdapter extends BaseAdapter {
    private final Context context;
    private final List<Info_data> img_list;

    public MycataAdapter(Context context,  List<Info_data> img_list) {
        this.context = context;
        this.img_list = img_list;
    }

    @Override
    public int getCount() {
        return img_list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.listview_lay, parent, false);
        }

        TextView textView = convertView.findViewById(R.id.item_text);
        ImageView imageView = convertView.findViewById(R.id.item_img);
        textView.setText(WallPaperSelect.getCataName().get(position).getName());
        Info_data info = img_list.get(position);
        while (info.getDatas().get(position).getBanner()==null){
            Collections.shuffle(info.getDatas());
        }
        Glide.with(convertView)
                .load(info.getDatas().get(position).getBanner())
                .transform(new RoundedCorners(20))
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageView);



        return convertView;
    }




}
