package bhouse.travellist_starterproject;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

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

    Context mContext;

    public TravelListAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_places, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final Place place = new PlaceData().placeList().get(position);
        holder.placeName.setText(place.name);
        Picasso.with(mContext).load(place.getImageResourceId(mContext)).into(holder.placeImage);
    }

    @Override
    public int getItemCount() {
        return new PlaceData().placeList().size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public LinearLayout placeHolder;
        public LinearLayout placeNameHolder;
        public TextView placeName;
        public ImageView placeImage;

        public ViewHolder(View itemView) {
            super(itemView);
            placeHolder = (LinearLayout) itemView.findViewById(R.id.mainHolder);
            placeName = (TextView) itemView.findViewById(R.id.placeName);
            placeNameHolder = (LinearLayout) itemView.findViewById(R.id.placeNameHolder);
            placeImage = (ImageView) itemView.findViewById(R.id.placeImage);
        }
    }
}
@@ -462,16 +462,60 @@
 Context;
+%0A    OnItemClickListener mItemClickListener;
 %0A%0A    pu
@@ -1302,16 +1302,48 @@
 wHolder 
+implements View.OnClickListener 
 %7B%0A      
@@ -1893,17 +1893,517 @@
 e);%0A
-        %7D
+%0A            placeHolder.setOnClickListener(this);%0A        %7D%0A%0A        @Override%0A        public void onClick(View v) %7B%0A            if (mItemClickListener != null) %7B%0A                mItemClickListener.onItemClick(itemView, getPosition());%0A            %7D%0A        %7D%0A    %7D%0A%0A    public interface OnItemClickListener %7B%0A        void onItemClick(View view, int position);%0A    %7D%0A%0A    public void setOnItemClickListener(final OnItemClickListener mItemClickListener) %7B%0A        this.mItemClickListener = mItemClickListener;
 %0A   

set on item click listener