package kz.arta.synergy.workflow.mobile.android.users.adapters;

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

import java.util.List;

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.users.models.UserItem;

/**
 * Created by neox on 14.04.14.
 * Адаптер списка пользователей
 */
public class AdapterUsers extends ArrayAdapter<UserItem> {

    private List<UserItem> users;

    private Context context;

    public AdapterUsers(Context context, List<UserItem> users) {
        super(context, R.layout.user_chooser_activity, users);
        this.context = context;
        this.users = users;
    }

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

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

        TextView userName = (TextView) someView.findViewById(R.id.item_users_name);
        userName.setText(users.get(position).getName());
        userName.setTypeface(Fonts.getRoman(context));

        TextView userPosition = (TextView) someView.findViewById(R.id.item_users_position);
        userPosition.setText(users.get(position).getPosition());
        userPosition.setTypeface(Fonts.getRoman(context));

        ImageView checker = (ImageView) someView.findViewById(R.id.item_users_checker_image);
        if (users.get(position).isChecked()) {
            checker.setVisibility(View.VISIBLE);
        } else {
            checker.setVisibility(View.GONE);
        }

        return someView;
    }
}