package de.apps4ics.mountainnavigation.pois;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.EditText;

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

/**
 * Created by Vinz on 03.11.2015.
 */
public class AddPeakDialog extends DialogFragment {
    PoiHandler poiHandler;

    public AddPeakDialog(PoiHandler poiHandler){
        this.poiHandler = poiHandler;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        final EditText input = new EditText(poiHandler.getContext());
        builder.setTitle(R.string.peak_dialog_title)
                .setMessage(R.string.peak_dialog_msg)
                .setView(input)
                .setPositiveButton(R.string.ok_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String name = input.getText().toString().trim();
                        if (name != null && !name.equals("")) {
                            poiHandler.addPoi(new Peak(0, name, null));
                        }
                    }
                })
                .setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        return builder.create();
    }
}
