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); } }
private void addItem(final Reminder reminder) { final int reminderID = reminder.getId(); String title = reminder.getTitle(); String billedAmt = String.valueOf(reminder.getBilledAmount()); String paidAmt = String.valueOf(reminder.getPaidAmount()); String unpaidAmt = String.valueOf(Double.valueOf(billedAmt) - Double.valueOf(paidAmt)); String dueDate = reminder.getDueDate(); int days = Integer.parseInt(TimeUtils.getDateDiffStr(dueDate)); // Instantiate a new "row" view. final ViewGroup newView = (ViewGroup) LayoutInflater.from(context) .inflate(R.layout.layoutchange_list_item, mContainerView, false); newView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { flipCard(reminder); return true; } }); // Set the text in the new row to a random country. TextView reminderTitleView = (TextView) newView.findViewById(R.id.reminderTitle); reminderTitleView.setText(title); reminderTitleView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { flipCard(reminder); return true; } }); TextView reminderAmtView = (TextView) newView.findViewById(R.id.reminderAmtInfo); reminderAmtView.setText("$" + unpaidAmt + " out of " + billedAmt + " unpaid"); reminderAmtView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { flipCard(reminder); return true; } }); TextView reminderDateView = (TextView) newView.findViewById(R.id.reminderDateInfo); if (days <= 1) reminderDateView.setText(days + " day unitl " + dueDate); else reminderDateView.setText(days + " days unitl " + dueDate); reminderDateView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { flipCard(reminder); return true; } }); // Set a click listener for the "X" button in the row that will remove the row. newView .findViewById(R.id.delete_button) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { AlarmManagerBroadcastReceiver alarm = new AlarmManagerBroadcastReceiver(); alarm.cancelAlarm(context, reminderID); dbManager.deleteReminder(reminderID); // Remove the row from its parent (the container view). // Because mContainerView has android:animateLayoutChanges set to true, // this removal is automatically animated. mContainerView.removeView(newView); // If there are no rows remaining, show the empty view. if (mContainerView.getChildCount() == 0) emptyText.setVisibility(View.VISIBLE); } }); // Because mContainerView has android:animateLayoutChanges set to true, // adding this view is automatically animated. mContainerView.addView(newView, 0); }