package com.gaiagps.iburn.adapters;

import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gaiagps.iburn.Constants;
import com.gaiagps.iburn.R;
import com.gaiagps.iburn.database.CampTable;

/**
 * Bind a playa item (camp, art, event) database row to a view with a simple name & distance display,
 * using the device's location and date when the adapter was constructed.
 * <p>
 * TODO: Update device location periodically
 */
public class CampCursorAdapter extends PlayaItemCursorAdapter<CampCursorAdapter.ViewHolder> {

    static final String[] Projection = new String[]{
            CampTable.playaAddress,
    };

    private int addressCol;

    public CampCursorAdapter(Context context, Cursor cursor, AdapterListener listener) {
        super(context, cursor, listener);
    }

    public static class ViewHolder extends PlayaItemCursorAdapter.ViewHolder {
        TextView addressView;

        public ViewHolder(View view) {
            super(view);

            addressView = (TextView) view.findViewById(R.id.address);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.camp_listview_item, parent, false);
        ViewHolder vh = new ViewHolder(itemView);

        setupClickListeners(vh, Constants.PlayaItemType.CAMP);

        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, Cursor cursor) {

        super.onBindViewHolder(viewHolder, cursor);

        if (addressCol == 0) {
            addressCol = cursor.getColumnIndexOrThrow(CampTable.playaAddress);
        }

        String address = cursor.getString(addressCol);
        if (!TextUtils.isEmpty(address)) {
            viewHolder.addressView.setText(cursor.getString(addressCol));
        } else {
            viewHolder.addressView.setVisibility(View.GONE);
        }
    }

    @Override
    public String[] getRequiredProjection() {
        return buildRequiredProjection(Projection);
    }
}
@@ -593,16 +593,37 @@
 dically%0A
+ * TODO: Remove this%0A
  */%0Apubl
@@ -680,20 +680,25 @@
 Adapter%3C
-Camp
+PlayaItem
 CursorAd
@@ -722,134 +722,8 @@
  %7B%0A%0A
-    static final String%5B%5D Projection = new String%5B%5D%7B%0A            CampTable.playaAddress,%0A    %7D;%0A%0A    private int addressCol;%0A%0A
     
@@ -772,21 +772,16 @@
 Cursor c
-ursor
 , Adapte
@@ -826,21 +826,16 @@
 ntext, c
-ursor
 , listen
@@ -850,270 +850,8 @@
  %7D%0A%0A
-    public static class ViewHolder extends PlayaItemCursorAdapter.ViewHolder %7B%0A        TextView addressView;%0A%0A        public ViewHolder(View view) %7B%0A            super(view);%0A%0A            addressView = (TextView) view.findViewById(R.id.address);%0A        %7D%0A    %7D%0A%0A
     
@@ -1215,537 +1215,8 @@
  %7D%0A%0A
-    @Override%0A    public void onBindViewHolder(ViewHolder viewHolder, Cursor cursor) %7B%0A%0A        super.onBindViewHolder(viewHolder, cursor);%0A%0A        if (addressCol == 0) %7B%0A            addressCol = cursor.getColumnIndexOrThrow(CampTable.playaAddress);%0A        %7D%0A%0A        String address = cursor.getString(addressCol);%0A        if (!TextUtils.isEmpty(address)) %7B%0A            viewHolder.addressView.setText(cursor.getString(addressCol));%0A        %7D else %7B%0A            viewHolder.addressView.setVisibility(View.GONE);%0A        %7D%0A    %7D%0A%0A
     
@@ -1290,32 +1290,31 @@
 urn 
-buildRequiredProjection(
+PlayaItemCursorAdapter.
 Proj
@@ -1319,17 +1319,16 @@
 ojection
-)
 ;%0A    %7D%0A

Remove redundant CampCursorAdapter code