@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { v = inflater.inflate(R.layout.fragment_card_front, container, false); context = v.getContext(); dbManager = new DBManager(context); mContainerView = (ViewGroup) v.findViewById(R.id.RowsContainer); addButton = (Button) v.findViewById(R.id.add_button); emptyText = (TextView) v.findViewById(android.R.id.empty); allReminders = dbManager.getReminders(); if (allReminders.size() > 0) { emptyText.setVisibility(View.INVISIBLE); for (int i = 0; i < allReminders.size(); i++) { addItem(allReminders.get(i)); } } addButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { flipCard(null); } }); return v; }
private void saveReminder() { int id = reminder.getId(); String newTitle = editTitle.getText().toString(); String newDueDate = editDueDate.getText().toString(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.US); try { sdf.parse(newDueDate); } catch (ParseException e) { return; } double newBilledAmount = Double.parseDouble(editAmount.getText().toString()); double newPaidAmount = Double.parseDouble(editPaid.getText().toString()); boolean repeatAlarm = repeatAlarmBox.isChecked(); DBManager dbManager = new DBManager(context); AlarmManagerBroadcastReceiver alarm = new AlarmManagerBroadcastReceiver(); int repeatedFrequency = TimeUtils.days2sec(TimeUtils.getDaysInMonth()); // ID is -1 if expense was just created?? if (id <= 0) { if (repeatAlarm) alarm.setRepeatedDateAlarm( context, id, newDueDate, repeatedFrequency, "Reminder: " + newTitle + " is due! "); else alarm.setOneTimeDateAlarm(context, id, newDueDate, "Reminder: " + newTitle + " is due! "); if (newRemindDate != TimeUtils.NONE) alarm.setOneTimeDateAlarm( context, id + 42, TimeUtils.getRemindDate(newDueDate, newRemindDate), "Reminder: " + newTitle + " is due in " + String.valueOf(TimeUtils.remindDateStr2Int(newRemindDate)) + " "); dbManager.addReminder( newTitle, newBilledAmount, newPaidAmount, newDueDate, newRemindDate, repeatAlarm); } else { if (newDueDate != dbManager.getReminders().get(id - 1).getDueDate()) { alarm.cancelAlarm(context, id); if (repeatAlarm) alarm.setRepeatedDateAlarm( context, id, newDueDate, repeatedFrequency, "Reminder: " + newTitle + " is due! "); else alarm.setOneTimeDateAlarm( context, id, newDueDate, "Reminder: " + newTitle + " is due! "); } if (newRemindDate != dbManager.getReminders().get(id - 1).getRemindDate()) { alarm.cancelAlarm(context, id + 42); if (newRemindDate != TimeUtils.NONE) alarm.setOneTimeDateAlarm( context, id + 42, TimeUtils.getRemindDate(newDueDate, newRemindDate), "Reminder: " + newTitle + " is due in " + String.valueOf(TimeUtils.remindDateStr2Int(newRemindDate)) + " "); } dbManager.editReminder( id, newTitle, newBilledAmount, newPaidAmount, newDueDate, newRemindDate, repeatAlarm); } }