public void reset() {
    try {
      leaveStartCalendar = Calendar.getInstance();
      leaveStartCalendar.setTime(app.dateFormatDefault.parse(leave.getStartDate()));
      leaveEndCalendar = Calendar.getInstance();
      leaveEndCalendar.setTime(app.dateFormatDefault.parse(leave.getEndDate()));
      tempEndLeaveEndCalendar = null;
      if (Math.abs(leave.getDays() - 0.1) < 0.00001) tvNumDays.setText("AM");
      else if (Math.abs(leave.getDays() - 0.2) < 0.00001) tvNumDays.setText("PM");
      else tvNumDays.setText((int) leave.getDays() + ((leave.getDays() > 1) ? " Days" : " Day"));

      tvDurations.setText(
          app.dateFormatDefault.format(leaveStartCalendar.getTime())
              + ((leave.getDays() > 1)
                  ? " - " + app.dateFormatDefault.format(leaveEndCalendar.getTime())
                  : ""));
      tvRemDays.setText(remBalance + " Days Remaining");

      tempLeaveDuration = leave.getDays();
      tempRemBalance = remBalance;
      adapter.notifyDataSetChanged();
    } catch (Exception e) {
      e.printStackTrace();
      Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
    }
  }
 @Override
 public void onClick(View v) {
   if (v instanceof ImageView) {
     manageSelection((ImageView) v);
   } else if (v == actionbarButtonClear) {
     reset();
   } else if (v == tvHeader) {
     if (!tvDurations.getText().toString().equals(NO_SELECTION)
         && tempEndLeaveEndCalendar != null) {
       if (((leave.getTypeID() == Leave.LEAVETYPEVACATIONKEY
                   || leave.getTypeID() == Leave.LEAVETYPESICKKEY)
               && tempRemBalance >= 0)
           || !(leave.getTypeID() == Leave.LEAVETYPEVACATIONKEY
               || leave.getTypeID() == Leave.LEAVETYPESICKKEY)) submitDialog.show();
     } else
       Toast.makeText(getActivity(), "Please chose an updated date!", Toast.LENGTH_SHORT).show();
   } else if (v == actionbarButtonBack || v == actionbarTitle) {
     linearNavFragmentActivity.onBackPressed();
   }
 }
    @Override
    public void run() {
      String tempResult;
      String startDateStr = app.dateFormatDefault.format(leaveStartCalendar.getTime());
      String oldEndDateStr = app.dateFormatDefault.format(leaveEndCalendar.getTime());
      String newEndDateStr = app.dateFormatDefault.format(tempEndLeaveEndCalendar.getTime());

      try {
        String oldLeaveJSON = leave.getJSONStringForEditingLeave();
        newLeave = new Leave(leave.getMap());
        newLeave.editLeave(
            (leave.getTypeID() == Leave.LEAVETYPEVACATIONKEY)
                ? tempRemBalance
                : app.staffLeaveCounter.getRemainingVLDays(),
            (leave.getTypeID() == Leave.LEAVETYPESICKKEY)
                ? tempRemBalance
                : app.staffLeaveCounter.getRemainingSLDays(),
            newEndDateStr,
            tempLeaveDuration,
            (tvNumDays.getText().toString().equals("AM")
                    || tvNumDays.getText().toString().equals("PM"))
                ? 0.5f
                : Float.parseFloat(tvNumDays.getText().toString().split(" ")[0]),
            etNotes.getText().toString(),
            app.dateFormatDefault.format(new Date()));
        tempResult =
            app.onlineGateway.saveLeave(newLeave.getJSONStringForEditingLeave(), oldLeaveJSON);
      } catch (Exception e) {
        e.printStackTrace();
        tempResult = e.getMessage();
      }

      final String result = tempResult;
      new Handler(Looper.getMainLooper())
          .post(
              new Runnable() {
                @Override
                public void run() {
                  if (result == null) {
                    new Thread(
                            new Runnable() {

                              @Override
                              public void run() {
                                String tempFollowUpLeaveResult;

                                try {
                                  tempFollowUpLeaveResult =
                                      app.onlineGateway.followUpLeave(
                                          newLeave.getJSONStringForEditingLeave());
                                } catch (Exception e) {
                                  e.printStackTrace();
                                  tempFollowUpLeaveResult = e.getMessage();
                                }

                                final String followUpLeaveResult = tempFollowUpLeaveResult;
                                new Handler(Looper.getMainLooper())
                                    .post(
                                        new Runnable() {

                                          @Override
                                          public void run() {
                                            if (followUpLeaveResult != null)
                                              Toast.makeText(
                                                      linearNavFragmentActivity,
                                                      "Failed to send email to approver(s): "
                                                          + followUpLeaveResult,
                                                      Toast.LENGTH_SHORT)
                                                  .show();
                                          }
                                        });
                              }
                            })
                        .start();

                    ParsePush parsePush = new ParsePush();
                    ParseQuery parseQuery = ParseInstallation.getQuery();
                    parseQuery.whereEqualTo("staffID", app.getStaff().getLeaveApprover1ID());
                    parsePush.sendMessageInBackground(
                        ParseReceiver.createLeaveApprovalMessage(newLeave, app), parseQuery);
                    Toast.makeText(getActivity(), "Leave Updated Successfully!", Toast.LENGTH_SHORT)
                        .show();
                    LeaveListFragment.getInstance().sync();
                    linearNavFragmentActivity.finishLoading();
                    linearNavFragmentActivity.finish();
                  } else {
                    app.showMessageDialog(getActivity(), result);
                    linearNavFragmentActivity.finishLoading();
                  }
                }
              });
    }
  @Override
  protected View createView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_leaveinput_dates, null);
    perWeekItems = new HashMap<Integer, HashMap<Integer, Item>>();
    nonworkingDays = new ArrayList<String>();
    leaveDays = new HashMap<String, Float>();

    lv = (ListView) view.findViewById(R.id.lists_lv);
    adapter = new ListAdapter(this);
    lv.setAdapter(adapter);

    tvHeader = (RelativeLayout) view.findViewById(R.id.fragment_leaveinput_dates_header);
    tvLeaveType = (TextView) view.findViewById(R.id.fragment_leaveinput_dates_headerleavetype);
    tvDurations = (TextView) view.findViewById(R.id.fragment_leaveinput_dates_headerdates);
    tvRemDays = (TextView) view.findViewById(R.id.fragment_leaveinput_dates_remdays);
    tvNumDays = (TextView) view.findViewById(R.id.fragment_leaveinput_dates_numdays);
    tvMonthYearHeader = (TextView) view.findViewById(R.id.fragment_leaveinput_monthyearheader);

    monthYearFormat = new SimpleDateFormat("MMMM yyyy");
    startCalendar = Calendar.getInstance();
    endCalendar = Calendar.getInstance();
    tvLeaveType.setText(leave.getTypeDescription());
    tvDurations.setText(NO_SELECTION);
    tvRemDays.setText("");
    tvNumDays.setText("");

    if (leave.getTypeID() == Leave.LEAVETYPEVACATIONKEY
        || leave.getTypeID() == Leave.LEAVETYPEUNPAIDKEY
        || leave.getTypeID() == Leave.LEAVETYPEBUSINESSTRIPKEY
        || leave.getTypeID() == Leave.LEAVETYPEBIRTHDAYKEY) {
      endCalendar.set(Calendar.YEAR, startCalendar.get(Calendar.YEAR));
      endCalendar.set(Calendar.MONTH, startCalendar.get(Calendar.MONTH) + 11);
      endCalendar.set(Calendar.DAY_OF_MONTH, 31);
    } else {
      // get 3 months of leave data to current date
      startCalendar.set(Calendar.MONTH, endCalendar.get(Calendar.MONTH) - 2);
      startCalendar.set(Calendar.DAY_OF_MONTH, 1);
    }

    linearNavFragmentActivity.startLoading();
    new Thread(new MyLeavesAndHolidaysUpdater()).start();

    dialogView = (RelativeLayout) inflater.inflate(R.layout.dialog_textinput, null);
    etNotes = (EditText) dialogView.findViewById(R.id.etexts_dialogs_textinput);
    ((TextView) dialogView.findViewById(R.id.tviews_dialogs_textinput)).setText("Notes");
    submitDialog =
        new AlertDialog.Builder(linearNavFragmentActivity)
            .setTitle("")
            .setView(dialogView)
            .setPositiveButton(
                "Submit",
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    linearNavFragmentActivity.startLoading();
                    new SubmitNewLeaveRequest().start();
                  }
                })
            .setNegativeButton(
                "Close",
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                  }
                })
            .create();

    return view;
  }