package kz.arta.synergy.workflow.mobile.android.documents.route.adapters;

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 kz.arta.synergy.workflow.mobile.android.R;
import kz.arta.synergy.workflow.mobile.android.common.utils.Fonts;
import kz.arta.synergy.workflow.mobile.android.documents.route.models.RouteListItem;

/**
 * Created by neox on 31.07.15.
 * Адаптер маршрутов доступных пользователю
 */
public class AdapterRoutesList extends ArrayAdapter<RouteListItem> {

    private RouteListItem[] items;
    private Context context;

    public AdapterRoutesList(Context context, RouteListItem[] items) {
        super(context, R.layout.route_list_activity_item, items);
        this.context = context;
        this.items = items;
    }

    @Override
    public View getView(int position, View someView, ViewGroup arg2) {

        LayoutInflater inflater = LayoutInflater.from(context);
        if (someView == null) {
            someView = inflater.inflate(R.layout.route_list_activity_item, arg2, false);
        }

        TextView userName = (TextView) someView.findViewById(R.id.route_list_item_user);
        userName.setText(items[position].getAuthorName());
        userName.setTypeface(Fonts.getMedium(context));

        TextView routeName = (TextView) someView.findViewById(R.id.route_list_item_name);
        routeName.setText(items[position].getRouteName());
        routeName.setTypeface(Fonts.getRoman(context));

        View background = someView.findViewById(R.id.background_item_route_list);
        if (items[position].isSelected()) {
            background.setBackgroundColor(context.getResources().getColor(R.color.selected_item_list_color));
        } else {
            background.setBackgroundColor(context.getResources().getColor(R.color.item_list_attachment_color));
        }

        return someView;
    }

}
