Пример #1
0
    @Override
    public void onReceive(Context context, Intent intent) {
      switch (intent.getAction()) {
        case NotificationUtil.BROADCAST_ACTION_NEW_REMIND:
          int id = intent.getIntExtra(DatabaseHelper.COLUMN_ID, 0);
          Remind remind = RemindDatabase.getInstance().get(id);
          switch (mFragmentType) {
            case FRAGMENT_TYPE_CURRENT:
              if (remind.getStatus() == RemindUtil.STATUS_WAIT) {
                mAdapter.add(id);
              } else {
                mAdapter.remove(id);
              }
              break;

            case FRAGMENT_TYPE_DONE:
              if (remind.getStatus() == RemindUtil.STATUS_DONE) {
                mAdapter.add(id);
              } else {
                mAdapter.remove(id);
              }
              break;
          }

        case NotificationUtil.BROADCAST_ACTION_REMIND_GONE:
          if (mFragmentType == FRAGMENT_TYPE_CURRENT) {
            int goneItemId = intent.getIntExtra(DatabaseHelper.COLUMN_ID, 0);
            mAdapter.updateItem(goneItemId);
          }
          break;

        case NotificationUtil.BROADCAST_ACTION_SORT_MODE:
          if (mFragmentType == FRAGMENT_TYPE_CURRENT) {
            mAdapter.updateData(
                RemindDatabase.getInstance().getStoredData(DatabaseHelper.FILTER_WAITING_REMINDS));
          } else {
            mAdapter.updateData(
                RemindDatabase.getInstance().getStoredData(DatabaseHelper.FILTER_DONE_REMINDS));
          }
          break;
      }
    }
Пример #2
0
  private void updateAlarm(int id) {
    Remind remind = RemindDatabase.getInstance().get(id);
    Intent pendingOperationContent = new Intent(mContext, AlarmService.class);
    PendingIntent pendingOperation =
        PendingIntent.getService(mContext, id, pendingOperationContent, 0);

    mAlarmManager.cancel(pendingOperation);
    pendingOperation.cancel();

    switch (remind.getStatus()) {
      case RemindUtil.STATUS_DONE:
        Log.i(TAG, "Dismiss alarm, id: " + id);
        break;

      case RemindUtil.STATUS_WAIT:
        if (remind.getNotificationMillis() > System.currentTimeMillis()) {
          setAlarm(id, remind.getNotificationMillis(), remind.getTitle());
          Log.i(TAG, "Set removed alarm back, id: " + id);
        }
        break;
    }
  }