package se.dat255.grupp12;

import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;

/**
 * Created by David on 10/2/13.
 * This class listens for clicks in the listview. If an item in the listview is clicked
 * a corresponding action is executed.
 */
public class ListViewItemClickListener implements AdapterView.OnItemClickListener {
    private MainActivity activity;

    /**
     * Constructor that ties the acticity in which it was called to the soon to be object
     * @param activity the activity in which the constructor was called
     */
    public ListViewItemClickListener(MainActivity activity){
        this.activity = activity;
    }

    /**
     * The actual method that is called when an item is clicked in the listview
     * @param adapterView   i.e the listview
     * @param view          parent view of the listview
     * @param i             the listindex of the item that has been clicked
     * @param l             not used
     */
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

        Task task = (Task) adapterView.getItemAtPosition(i);
        activity.showDetailedView(task, adapterView, i);

    }
}
