//旧コードは念の為コメントアウトしています。
//package com.example.tampopo_client.views;
//
//import android.view.LayoutInflater;
//import android.view.ViewGroup;
//import android.widget.TextView;
//
//import com.example.tampopo_client.databinding.FragmentFriendListBinding;
//import com.example.tampopo_client.views.placeholder.FriendContent;
//
//import java.util.List;
//
//import androidx.recyclerview.widget.RecyclerView;
//
///**
// * {@link RecyclerView.Adapter} that can display a {@link FriendContent.FriendItem}.
// * TODO: Replace the implementation with code for your data type.
// */
//public class MyFriendRecyclerViewAdapter extends RecyclerView.Adapter<MyFriendRecyclerViewAdapter.ViewHolder> {
//
//    private final List<FriendContent.FriendItem> mValues;
//
//    public MyFriendRecyclerViewAdapter(List<FriendContent.FriendItem> items) {
//        mValues = items;
//    }
//
//    @Override
//    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//
//        return new ViewHolder(FragmentFriendListBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
//
//    }
//
//    @Override
//    public void onBindViewHolder(final ViewHolder holder, int position) {
//        holder.mItem = mValues.get(position);
//        //holder.mIdView.setText(mValues.get(position).id);
//        holder.mContentView.setText(mValues.get(position).name);
//    }
//
//    @Override
//    public int getItemCount() {
//        return mValues.size();
//    }
//
//    public class ViewHolder extends RecyclerView.ViewHolder {
//        //public final TextView mIdView;
//        public final TextView mContentView;
//        public FriendContent.FriendItem mItem;
//
//        public ViewHolder(FragmentFriendListBinding binding) {
//            super(binding.getRoot());
//            //mIdView = binding.itemNumber;
//            mContentView = binding.content;
//        }
//
//        @Override
//        public String toString() {
//            return super.toString() + " '" + mContentView.getText() + "'";
//        }
//    }
//}

package com.example.tampopo_client.views;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.tampopo_client.R;
import com.example.tampopo_client.views.placeholder.FriendContent.FriendItem;

import java.util.List;

public class MyFriendRecyclerViewAdapter extends RecyclerView.Adapter<MyFriendRecyclerViewAdapter.ViewHolder> {

    private final List<FriendItem> mValues;

    public MyFriendRecyclerViewAdapter(List<FriendItem> items) {
        mValues = items;
    }

    //各行のビューを作成する
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.fragment_friend_list, parent, false);
        return new ViewHolder(view);
    }


    //データをビューに紐付ける
    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        FriendItem item = mValues.get(position);
        holder.userIdView.setText(item.id);
        holder.contentView.setText(item.name);
        holder.userIcon.setImageResource(R.drawable.friend);
    }

    @Override
    public int getItemCount() {
        return mValues.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public final ImageView userIcon;
        public final TextView contentView;
        public final TextView userIdView;

        public ViewHolder(View view) {
            super(view);
            userIcon = view.findViewById(R.id.usericon);
            contentView = view.findViewById(R.id.content);
            userIdView = view.findViewById(R.id.userId);
        }
    }
}
