package com.raataar.sprueche_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.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.raataar.sprueche_sports.R;
import com.raataar.sprueche_sports.app.AppController;
import com.raataar.sprueche_sports.model.Autoren;
import com.raataar.sprueche_sports.util.RoundedTransformation;
import com.squareup.picasso.Picasso;


import java.util.List;

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

	public AutorenListAdapter(Activity activity, List<Autoren> kategorieItems) {
		this.activity = activity;
		this.autorenItems = kategorieItems;
	}

	@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_autoren, null);

		if (imageLoader == null)
			imageLoader = AppController.getInstance().getImageLoader();


		ImageView thumbnail = (ImageView) 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
		Autoren m = autorenItems.get(position);


		Picasso.with(this.activity)
				.load(m.getImage())
				.transform(new RoundedTransformation(8, 0))
				.fit()
				.into(thumbnail);

		// 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;
	}

}