예제 #1
0
 private void handleCommand(Intent intent) {
   Task task = TaskHelper.getTaskFromIntent(intent);
   if (task == null) return;
   if (intent.getAction() == TASK_DONE) {
     task.setDone(true);
     task.safeSave();
     Toast.makeText(
             this, getString(R.string.reminder_notification_done_confirm), Toast.LENGTH_LONG)
         .show();
   } else if (intent.getAction() == TASK_LATER && !task.hasRecurringReminder()) {
     GregorianCalendar reminder = new GregorianCalendar();
     int addMinutes = MirakelCommonPreferences.getAlarmLater();
     reminder.add(Calendar.MINUTE, addMinutes);
     task.setReminder(reminder);
     task.safeSave();
     Toast.makeText(
             this,
             getString(R.string.reminder_notification_later_confirm, addMinutes),
             Toast.LENGTH_LONG)
         .show();
   }
   ReminderAlarm.closeNotificationFor(this, task.getId());
   ReminderAlarm.updateAlarms(this);
   stopSelf();
 }
예제 #2
0
  public static void undoLast() {
    String last = MirakelCommonPreferences.getFromLog(0);
    if (last != null && !last.equals("")) {
      short type = Short.parseShort(last.charAt(0) + "");
      if (last.charAt(1) != '{') {
        try {
          long id = Long.parseLong(last.substring(1));
          switch (type) {
            case TASK:
              Task.get(id).destroy(true);
              break;
            case LIST:
              ListMirakel.getList((int) id).destroy(true);
              break;
            default:
              Log.wtf(TAG, "unkown Type");
              break;
          }
        } catch (Exception e) {
          Log.e(TAG, "cannot parse String");
        }

      } else {
        JsonObject json = new JsonParser().parse(last.substring(1)).getAsJsonObject();
        switch (type) {
          case TASK:
            Task t = Task.parse_json(json, AccountMirakel.getLocal(), false);
            if (Task.get(t.getId()) != null) {
              t.safeSave(false);
            } else {
              try {
                MirakelContentProvider.getWritableDatabase()
                    .insert(Task.TABLE, null, t.getContentValues());
              } catch (Exception e) {
                Log.e(TAG, "cannot restore Task");
              }
            }
            break;
          case LIST:
            ListMirakel l = ListMirakel.parseJson(json);
            if (ListMirakel.getList(l.getId()) != null) {
              l.save(false);
            } else {
              try {
                MirakelContentProvider.getWritableDatabase()
                    .insert(ListMirakel.TABLE, null, l.getContentValues());
              } catch (Exception e) {
                Log.e(TAG, "cannot restore List");
              }
            }
            break;
          default:
            Log.wtf(TAG, "unkown Type");
            break;
        }
      }
    }
    SharedPreferences.Editor editor = MirakelCommonPreferences.getEditor();
    for (int i = 0; i < MirakelCommonPreferences.getUndoNumber(); i++) {
      String old = MirakelCommonPreferences.getFromLog(i + 1);
      editor.putString(UNDO + i, old);
    }
    editor.putString(UNDO + 10, "");
    editor.commit();
  }