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

import java.util.List;

public class AutorenByIDListAdapter extends BaseAdapter {
	private Activity activity;
	private LayoutInflater inflater;
	private List<AutorenByID> autorenItems;
	ImageLoader imageLoader = AppController.getInstance().getImageLoader();

	public AutorenByIDListAdapter(Activity activity, List<AutorenByID> autorenItems) {
		this.activity = activity;
		this.autorenItems = autorenItems;
	}

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

	@Override
	public Object getItem(int location) {
		return autorenItems.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_autorenbyid, 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
		AutorenByID m = autorenItems.get(position);

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

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

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

		return convertView;
	}

}