public void onTouch(Cell cell) { selectedCell = cell; mStateHolder.mSavedSelectedCell = cell; if (cell.getOvertime().equals("") && cell.getShift().equals("") && !cell.existsDailyNote()) { Toast.makeText(getApplicationContext(), R.string.long_press_help, Toast.LENGTH_SHORT).show(); return; } Bundle data = new Bundle(); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, mCalendarView.getYear()); c.set(Calendar.MONTH, mCalendarView.getMonth()); c.set(Calendar.DAY_OF_MONTH, cell.getDayOfMonth()); data.putSerializable("date", df.format(c.getTime())); float totalHours = 0; if (!cell.getOvertime().equals("")) { mDatabase = mDatabase.open(); long overtimeMinutes = mDatabase.getOvertime(c); mDatabase.close(); data.putString("overtime", Helper.formatInterval(overtimeMinutes)); totalHours += overtimeMinutes / 60f; } else { data.putString("overtime", getString(R.string.unknown)); } if (cell.existsDailyNote()) { mDatabase = mDatabase.open(); String dailyNotes = mDatabase.getDailyNote(c); mDatabase.close(); data.putString("dailyNotes", dailyNotes); } else { data.putString("dailyNotes", getString(R.string.unknown)); } if (!cell.getShift().equals("")) { Shift s = mShiftTable.get(selectedCell.getShift()); if (s == null) { mDatabase = mDatabase.open(); s = mDatabase.getShiftObject(c); mDatabase.close(); data.putString("shift", selectedCell.getShift()); } data.putString("shift", s.getName()); totalHours += s.getHours(); } else { data.putString("shift", getString(R.string.unknown)); } String totalHoursString = Helper.formatInterval(totalHours); data.putString("hours", totalHoursString); showDialog(DIALOG_DAY_DETAIL, data); }
private void setDailyNotes(Dialog dialog) { if (selectedCell == null) { Toast.makeText(this, R.string.error_generic, Toast.LENGTH_SHORT).show(); return; } EditText dailyNotesEditText = (EditText) dialog.findViewById(R.id.dailynotes_edit_text); String dailyNotes = dailyNotesEditText.getText().toString(); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, mCalendarView.getYear()); c.set(Calendar.MONTH, mCalendarView.getMonth()); c.set(Calendar.DAY_OF_MONTH, selectedCell.getDayOfMonth()); try { mDatabase = mDatabase.open(); if (dailyNotes.length() == 0) mDatabase.deleteDailyNotes(c); else mDatabase.setDailyNote(c, dailyNotes); Toast.makeText(this, R.string.daily_notes_saved_toast, Toast.LENGTH_LONG).show(); mDatabase.close(); mCalendarView.invalidate(); } catch (Exception e) { Toast.makeText(this, R.string.error_generic, Toast.LENGTH_SHORT).show(); return; } }
private void setOvertime(Dialog dialog) { if (selectedCell == null) { Toast.makeText(this, R.string.error_generic, Toast.LENGTH_SHORT).show(); return; } EditText hoursEditText = (EditText) dialog.findViewById(R.id.overtime_hours_edit_text); EditText minutesEditText = (EditText) dialog.findViewById(R.id.overtime_minutes_edit_text); String hours = hoursEditText.getText().toString(); String minutes = minutesEditText.getText().toString(); if (hours.equals("") && minutes.equals("")) { Toast.makeText(this, R.string.error_form_complete_something, Toast.LENGTH_SHORT).show(); return; } Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, mCalendarView.getYear()); c.set(Calendar.MONTH, mCalendarView.getMonth()); c.set(Calendar.DAY_OF_MONTH, selectedCell.getDayOfMonth()); try { hours = hours.equals("") ? "0" : hours; minutes = minutes.equals("") ? "0" : minutes; long hoursFloat = Long.valueOf(hours); long minutesFloat = Long.valueOf(minutes); long overtimeMinutes = hoursFloat * 60 + minutesFloat; mDatabase = mDatabase.open(); mDatabase.setOvertime(c, overtimeMinutes); mDatabase.close(); mCalendarView.invalidate(); Toast.makeText(this, R.string.overtime_show_tip, Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(this, R.string.error_generic, Toast.LENGTH_SHORT).show(); return; } }