package de.apps4ics.mountainnavigation.adapters;

import android.app.Activity;
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 de.apps4ics.mountainnavigation.R;

/**
 * This file is part of MountainNavigation.
 *
 * MountainNavigation is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MountainNavigation is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MountainNavigation.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @copyright Copyright (c) 2016 Vinzenz Rosenkanz <vinzenz.rosenkranz@gmail.com>
 *
 * @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
 */
public class ImageListAdapter extends ArrayAdapter<String> {

    private final Activity context;
    private final String[] texts;
    private final Integer[] imgs;
    private final boolean selected;

    public ImageListAdapter(Activity context, String[] texts, Integer[] imgs, boolean selected) {
        super(context, R.layout.drawer_list_item, texts);
        this.context = context;
        this.texts = texts;
        this.imgs = imgs;
        this.selected = selected;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        LayoutInflater inflater = context.getLayoutInflater();
        View rowView= inflater.inflate(R.layout.drawer_list_item, null, true);
        TextView txtTitle = (TextView) rowView.findViewById(R.id.toggleEntryDesc);

        ImageView imageView = (ImageView) rowView.findViewById(R.id.toggleEntryImg);
        txtTitle.setText(texts[position]);

        imageView.setImageResource(imgs[position]);
        if(!selected) imageView.setColorFilter(context.getResources().getColor(R.color.icon_unselected_gray));
        return rowView;
    }
}
