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

import java.util.List;

public class MainmenueListAdapter extends BaseAdapter {
	private Activity activity;
	private LayoutInflater inflater;
	private List<Mainmenue> mainmenueItems;
	ImageLoader imageLoader = AppController.getInstance().getImageLoader();

	public MainmenueListAdapter(Activity activity, List<Mainmenue> mainmenueItems) {
		this.activity = activity;
		this.mainmenueItems = mainmenueItems;
	}

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

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

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

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

		beschreibung.setText(m.getBeschreibung());

		return convertView;
	}

}