@Override
  public void onClick(DialogInterface dialogInterface, int i) {
    switch (i) {
      case DialogInterface.BUTTON_POSITIVE:
        User user = mUser.isPresent() ? mUser.get() : new User();
        user.setName(mName.getText().toString())
            .setSpecialty(mSpecialty.getText().toString())
            .setSponsor(mSponsorAdapter.getItem(mSponsor.getSelectedItemPosition()))
            .saveLater();

        dismiss();
        break;
      case DialogInterface.BUTTON_NEUTRAL:
        getDialog().cancel();
        break;
      case DialogInterface.BUTTON_NEGATIVE:
        new AlertDialog.Builder(getActivity())
            .setTitle(R.string.confirm_delete)
            .setMessage(R.string.confirm_delete_message)
            .setPositiveButton(
                android.R.string.yes,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i) {
                    mUser.get().deleteEventually();
                    dialogInterface.dismiss();
                  }
                })
            .setNegativeButton(android.R.string.cancel, null)
            .show();
        break;
    }
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View view = inflater.inflate(R.layout.dialog_user_edit, null);

    mName = (EditText) view.findViewById(R.id.user_name);
    mSpecialty = (EditText) view.findViewById(R.id.user_position);
    mSponsor = (Spinner) view.findViewById(R.id.user_sponsor);

    mSponsor.setAdapter(mSponsorAdapter);

    if (mUser.isPresent()) {
      mName.setText(mUser.get().getName());
      mSpecialty.setText(mUser.get().getSpecialty());
      mSponsor.setSelection(mSponsorAdapter.indexOf(mUser.get().getSponsor()));
    }

    AlertDialog.Builder builder =
        new AlertDialog.Builder(getActivity())
            .setTitle(R.string.user_new)
            .setView(view)
            .setPositiveButton(android.R.string.ok, this)
            .setNeutralButton(android.R.string.cancel, this);
    if (mUser.isPresent()) builder.setNegativeButton(R.string.delete, this);

    return builder.create();
  }