/*
 * Copyright (C) 2014 Ribot Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.co.ribot.easyadapterdemo;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import uk.co.ribot.easyadapter.ItemViewHolder;
import uk.co.ribot.easyadapter.PositionInfo;
import uk.co.ribot.easyadapter.annotations.LayoutId;
import uk.co.ribot.easyadapter.annotations.ViewId;

/**
 * Created by ivan on 14/02/2014.
 * <p/>
 * The extension of ItemViewHolder for the ListView of Person.
 */

//Annotate the class with the layout ID of the item.
@LayoutId(R.layout.person_item_layout)
public class PersonViewHolder extends ItemViewHolder<Person> {

    //Annotate every field with the ID of the view in the layout.
    //The views will automatically be assigned to the fields.
    @ViewId(R.id.image_view_person)
    ImageView imageViewPerson;

    @ViewId(R.id.text_view_name)
    TextView textViewName;

    @ViewId(R.id.text_view_phone)
    TextView textViewPhone;

    //Extend ItemViewHolder and call super(view)
    public PersonViewHolder(View view) {
        super(view);
    }

    //Override onSetValues() to set the values of the items in the views.
    @Override
    public void onSetValues(Person person, PositionInfo positionInfo) {
        imageViewPerson.setImageResource(person.getResDrawableId());
        textViewName.setText(person.getName());
        textViewPhone.setText(person.getPhoneNumber());
    }

    //Optionally override onSetListeners to add listeners to the views.
    @Override
    public void onSetListeners(final Person item, PositionInfo positionInfo) {
        imageViewPerson.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), getContext().getString(R.string.my_name_string, item.getName()), Toast.LENGTH_LONG).show();
            }
        });
    }
}

@@ -2117,56 +2117,12 @@
 ers(
-final Person item, PositionInfo positionInfo
 ) %7B%0A
+
     
@@ -2249,24 +2249,196 @@
 k(View v) %7B%0A
+                //To access the item data object from inside listeners, call getItem()%0A                Person person = getItem();%0A                if (person != null) %7B%0A    
             
@@ -2518,20 +2518,22 @@
 string, 
-item
+person
 .getName
@@ -2560,24 +2560,42 @@
 NG).show();%0A
+                %7D%0A
             

Update demo app to support changes in onSetListeners() method