package com.raataar.zitate_soccer.adater;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.raataar.zitate_soccer.R;
import com.raataar.zitate_soccer.app.AppController;
import com.raataar.zitate_soccer.model.Kategorie;

import java.util.List;

public class KategorieListAdapter extends BaseAdapter {
	private Activity activity;
	private LayoutInflater inflater;
	private List<Kategorie> kategorieItems;
	ImageLoader imageLoader = AppController.getInstance().getImageLoader();

	public KategorieListAdapter(Activity activity, List<Kategorie> kategorieItems) {
		this.activity = activity;
		this.kategorieItems = kategorieItems;
	}

	@Override
	public int getCount() {
		return kategorieItems.size();
	}

	@Override
	public Object getItem(int location) {
		return kategorieItems.get(location);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (inflater == null)
			inflater = (LayoutInflater) activity
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (convertView == null)
			convertView = inflater.inflate(R.layout.list_kategorie, null);

		if (imageLoader == null)
			imageLoader = AppController.getInstance().getImageLoader();
		NetworkImageView thumbNail = (NetworkImageView) convertView
				.findViewById(R.id.thumbnail);
		TextView title = (TextView) convertView.findViewById(R.id.title);
		TextView objectid = (TextView) convertView.findViewById(R.id.objectid);
		TextView anzahl = (TextView) convertView.findViewById(R.id.anzahl);
		TextView beschreibung = (TextView) convertView.findViewById(R.id.beschreibung);


		// getting movie data for the row
		Kategorie m = kategorieItems.get(position);

		// thumbnail image
		thumbNail.setImageUrl(m.getImage(), imageLoader);
		
		// title
		title.setText(m.getTitle());
		
		// anzahl
		anzahl.setText("Erfasste Weisheiten: " + String.valueOf(m.getAnzahl()));

		// objectid
		objectid.setText(m.getObjectId());

		beschreibung.setText(m.getBeschreibung());

		return convertView;
	}

}