package com.raataar.sprueche_tvstar.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.sprueche_tvstar.R;
import com.raataar.sprueche_tvstar.app.AppController;
import com.raataar.sprueche_tvstar.model.KategorieByID;

import java.util.List;

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

	public KategorieByIDListAdapter(Activity activity, List<KategorieByID> 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_kategoriebyid, null);

		if (imageLoader == null)
			imageLoader = AppController.getInstance().getImageLoader();
		NetworkImageView thumbNail = (NetworkImageView) convertView
				.findViewById(R.id.thumbnail);
		TextView zitat = (TextView) convertView.findViewById(R.id.zitat);
		TextView objectid = (TextView) convertView.findViewById(R.id.objectid);
		TextView zitatfooter = (TextView) convertView.findViewById(R.id.zitatfooter);
		TextView autoren_id = (TextView) convertView.findViewById(R.id.autoren_id);
		TextView kategorie_id = (TextView) convertView.findViewById(R.id.kategorie_id);


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

		// thumbnail image
		thumbNail.setImageUrl(m.getImage(), imageLoader);
		
		// Zitat
		zitat.setText(m.getZitat());
		
		// Zitatfooter
		zitatfooter.setText("Autor: " + m.getAutoren_text());

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

		autoren_id.setText(m.getAutor_id());
		kategorie_id.setText(m.getKategorie_id());

		return convertView;
	}

}