package com.example.cloudmusic.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.cloudmusic.R;

import java.util.List;

public class GecAdapter extends RecyclerView.Adapter<GecAdapter.InnerHolder> {

    private final List<String> mList;
    private final Context mContext;

    public GecAdapter(List<String> list, Context context) {
        mList = list;
        mContext = context;
    }

    @NonNull
    @Override
    public GecAdapter.InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new GecAdapter.InnerHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.gec_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull GecAdapter.InnerHolder holder, int position) {
        holder.setData(mList.get(position));
    }

    @Override
    public int getItemCount() {
        if (mList != null)
            return mList.size();
        return 0;
    }

    public class InnerHolder extends RecyclerView.ViewHolder {

        private final TextView gec;

        public InnerHolder(@NonNull View itemView) {
            super(itemView);
            gec = itemView.findViewById(R.id.gec_text);
        }

        public void setData(String s) {
            gec.setText(s);
        }
    }
}
