package com.github.mobile.ui;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * List adapter for items of a specific type
 *
 * @param <I>
 * @param <V>
 */
public abstract class ItemListAdapter<I, V extends ItemView> extends BaseAdapter {

    private final LayoutInflater inflater;

    private final int viewId;

    private Object[] elements;

    /**
     * Create empty adapter
     *
     * @param viewId
     * @param inflater
     */
    public ItemListAdapter(final int viewId, final LayoutInflater inflater) {
        this(viewId, inflater, null);
    }

    /**
     * Create adapter
     *
     * @param viewId
     * @param inflater
     * @param elements
     */
    public ItemListAdapter(final int viewId, final LayoutInflater inflater, final I[] elements) {
        this.viewId = viewId;
        this.inflater = inflater;
        if (elements != null)
            this.elements = elements;
        else
            this.elements = new Object[0];
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    /**
     * @return items
     */
    @SuppressWarnings("unchecked")
    protected I[] getItems() {
        return (I[]) elements;
    }

    public int getCount() {
        return elements.length;
    }

    @SuppressWarnings("unchecked")
    public I getItem(int position) {
        return (I) elements[position];
    }

    public long getItemId(int position) {
        return elements[position].hashCode();
    }

    /**
     * Set items
     *
     * @param items
     * @return items
     */
    public ItemListAdapter<I, V> setItems(final Object[] items) {
        if (items != null)
            elements = items;
        else
            elements = new Object[0];
        notifyDataSetChanged();
        return this;
    }

    /**
     * Update view to display item
     *
     * @param view
     * @param item
     */
    protected abstract void update(V view, I item);

    /**
     * Create empty item view
     *
     * @param view
     * @return item
     */
    protected abstract V createView(View view);

    @SuppressWarnings("unchecked")
    public View getView(final int position, View convertView, final ViewGroup parent) {
        I item = getItem(position);
        V view = null;
        if (convertView != null)
            view = (V) convertView.getTag();
        if (view == null) {
            convertView = inflater.inflate(viewId, null);
            view = createView(convertView);
            convertView.setTag(view);
        }
        update(view, item);
        return convertView;
    }
}

@@ -2290,110 +2290,38 @@
     
-I item = getItem(position);%0A        V view = null;%0A        if (convertView != null)%0A            view =
+V view = convertView != null ?
  (V)
@@ -2341,16 +2341,23 @@
 getTag()
+ : null
 ;%0A      
@@ -2549,20 +2549,33 @@
 e(view, 
-item
+getItem(position)
 );%0A     

Remove unneeded item variable