package hh.michelson;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;

import hh.lib.D;

class Windrover extends BaseAdapter implements ListAdapter {
	D d;
	Context c;
	int rowViewRes;
	Handle[] handles;

	Windrover(D d, String label, Context c, int rowViewRes, Handle[] handles) {
		this.d = d.klon(getClass().getSimpleName() + "." + label);
		this.c = c;
		this.rowViewRes = rowViewRes;
		this.handles = handles;
	}

	public Object getItem(int pos) {
		if(d.ll(4)) d.l(String.format("getItem=%s", handles[pos]));
		return handles[pos];
	}

	public long getItemId(int pos) {
		if(d.ll(4)) d.l(String.format(A.lo, "getItemId=%d", pos));
		return pos;
	}

	public int getCount() {
		if(d.ll(4)) d.l(String.format(A.lo, "getCount=%d", handles.length));
		return handles.length;
	}

	public View getView(int pos, View handleView, ViewGroup parent) {
		View v = ((LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(rowViewRes, null);
		handles[pos].infillView(v, pos);
		return v;
	}
}
