package com.simplicityapks.reminderdatepicker.lib;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.SpinnerAdapter;

import java.util.List;

/**
 * Serves as Adapter for all PickerSpinner Views and deals with the extra lastItem and its layout.
 */
public class PickerSpinnerAdapter<T> extends ArrayAdapter
        implements SpinnerAdapter, ListAdapter{ // TODO: check if instead should use ArrayAdapter<Object>

    /**
     * Resource for the last item in the Spinner, which will be inflated at the last position in dropdown/dialog.
     * Set to 0 for use of normal dropDownResource
     */
    private int lastItemResource;

    /**
     * The last item, set to null to disable custom layouts
     */
    private T lastItem;

    public PickerSpinnerAdapter(Context context, int dropDownResource, int lastItemResource) {
        super(context, dropDownResource);
        this.lastItemResource = lastItemResource;
    }

    public PickerSpinnerAdapter(Context context, int dropDownResource, List<T> objects,
                                int lastItemResource, T lastItem) {
        super(context, dropDownResource, objects);
        this.lastItemResource = lastItemResource;
        this.lastItem = lastItem;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // depending on the position, use super method or create our own
        if(position != getCount()-1)
            return super.getView(position, convertView, parent);
        View lastView = null;
        if(lastItemResource == 0)
            lastView = super.getView(position, convertView, parent);

        return lastView;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getCount() {
        // we need one extra item which is not in the array.
        return super.getCount() + (lastItem==null? 0 : 1);
    }

    public void setLastItem(T lastItem) {
        this.lastItem = lastItem;
    }
}

@@ -346,24 +346,22 @@
 e extra 
-lastItem
+footer
  and its
@@ -731,32 +731,30 @@
 private int 
-lastItem
+footer
 Resource;%0A%0A 
@@ -842,24 +842,22 @@
 ivate T 
-lastItem
+footer
 ;%0A%0A    p
@@ -922,32 +922,30 @@
 source, int 
-lastItem
+footer
 Resource) %7B%0A
@@ -995,32 +995,30 @@
        this.
-lastItem
+footer
 Resource = l
@@ -1012,32 +1012,30 @@
 rResource = 
-lastItem
+footer
 Resource;%0A  
@@ -1163,24 +1163,22 @@
     int 
-lastItem
+footer
 Resource
@@ -1181,24 +1181,22 @@
 urce, T 
-lastItem
+footer
 ) %7B%0A    
@@ -1255,24 +1255,22 @@
    this.
-lastItem
+footer
 Resource
@@ -1272,24 +1272,22 @@
 ource = 
-lastItem
+footer
 Resource
@@ -1301,35 +1301,31 @@
    this.
-lastItem = lastItem
+footer = footer
 ;%0A    %7D%0A
@@ -1668,24 +1668,22 @@
      if(
-lastItem
+footer
 Resource
@@ -1966,24 +1966,22 @@
 nt() + (
-lastItem
+footer
 ==null? 
@@ -2018,27 +2018,23 @@
  set
-LastItem(T lastItem
+footer(T footer
 ) %7B%0A
@@ -2050,27 +2050,23 @@
 his.
-lastItem = lastItem
+footer = footer
 ;%0A  

Rename lastItem to footer