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.TextView;

import de.apps4ics.mountainnavigation.MainActivity;
import de.apps4ics.mountainnavigation.R;

/**
 * Created by Vinz on 12.03.2016.
 */
public class WarningListAdapter extends ArrayAdapter<String> {

    private final Activity context;
    private final String[] texts;
    private final String[] descs;
    private final String[] infos;

    public WarningListAdapter(Activity context, String[] texts, String[] descs, String[] additionalInfos) {
        super(context, R.layout.warning_list_item, texts);
        this.context = context;
        this.texts = texts;
        this.descs = descs;
        this.infos = additionalInfos;
    }

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

        TextView txtDesc = (TextView) rowView.findViewById(R.id.warning_text_desc);
        txtTitle.setText(texts[position]);
        txtDesc.setText(descs[position]);
        final String info = (infos[position] != null && !infos[position].equals("")) ? infos[position] : MainActivity.getRes().getString(R.string.hint_dialog_info_none);
        txtDesc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity.Toaster(info, true, context);
            }
        });
        return rowView;
    }
}
