/**
*	AutoCompleteAdapter.java
*
*	@author Johan Brook
*	@copyright (c) 2012 Johan Brook
*	@license MIT
*/

package se.chalmers.watchme.activity;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.json.JSONObject;

import se.chalmers.watchme.R;
import se.chalmers.watchme.model.Movie;
import se.chalmers.watchme.utils.DateConverter;
import se.chalmers.watchme.utils.MovieHelper;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AutoCompleteAdapter extends ArrayAdapter<Movie> {

	private LayoutInflater inflater;
	
	public AutoCompleteAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
		
		this.inflater = LayoutInflater.from(getContext());
	}
	
	
	private void sortItemsByRating(List<JSONObject> res) {
		Collections.sort(res, Collections.reverseOrder(new Comparator<JSONObject>() {

			public int compare(JSONObject lhs, JSONObject rhs) {
				return Double.compare(lhs.optDouble("rating"), rhs.optDouble("rating"));
			}
			
		}));
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		Log.i("Custom", "GET_VIEW");
		
		ViewHolder holder;
		Movie suggestion = this.getItem(position);
		
		if(convertView == null) {
			convertView = this.inflater.inflate(R.layout.auto_complete_item, null);
			holder = new ViewHolder();
			holder.title = (TextView) convertView.findViewById(R.id.autocomplete_title);
			holder.year = (TextView) convertView.findViewById(R.id.autocomplete_year);
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.title.setText(suggestion.getTitle());
		holder.year.setText(DateConverter.toSimpleDate(suggestion.getDate()));
		
		return convertView;
	}
	
	static class ViewHolder {
		TextView title;
		TextView year;
		int position;
	}

}

@@ -1290,42 +1290,8 @@
 %0A%09%09%0A
-%09%09Log.i(%22Custom%22, %22GET_VIEW%22);%0A%09%09%0A
 %09%09Vi
@@ -1383,16 +1383,47 @@
 null) %7B%0A
+%09%09%09Log.i(%22Custom%22, %22INFLATE%22);%0A
 %09%09%09conve
@@ -1721,16 +1721,47 @@
 %09else %7B%0A
+%09%09%09Log.i(%22Custom%22, %22GET TAG%22);%0A
 %09%09%09holde

Debug logging in autocomplete adapter