package com.viaccessorca.voplayerdemo.adapters;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.viaccessorca.voplayerdemo.R;
import com.viaccessorca.voplayerdemo.downloader.DLVariantListItem;

public class DlVariantsAdapter extends ArrayAdapter<DLVariantListItem> {

    private List<DLVariantListItem> items;

    public DlVariantsAdapter(Context context, int textViewResourceId, List<DLVariantListItem> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    public DlVariantsAdapter(Context context, int textViewResourceId, DLVariantListItem items[]) {
        super(context, textViewResourceId, items);
        this.items = new ArrayList<DLVariantListItem>();
        for(DLVariantListItem s: items) {
            this.items.add(s);
        }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (null == convertView) {
            LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = vi.inflate(R.layout.download_variant_item, null);
        }
        DLVariantListItem item = items.get(position);
        if (null != item) {
            TextView alternateBitrateText = (TextView)convertView.findViewById(R.id.alternateTxt);
            TextView alternateBitrateText2 = (TextView)convertView.findViewById(R.id.alternateTxt2);

            alternateBitrateText.setText("Variant bitrate: " + (item.bitrate/1000) + " kbps " + item.resolution[0] + "x" + item.resolution[1]);
            alternateBitrateText2.setText("Estimated size: " + item.estimatedSizeInMB + " MB");
        }
        return convertView;
    }
}
