Example #1
0
  @Override
  protected void onHandleIntent(Intent intent) {
    int serviceMode = intent.getIntExtra(SERVICE_MODE, MODE_ALL_REMINDS);
    switch (serviceMode) {
      case MODE_ALL_REMINDS:
        Log.i(TAG, "NotificationService called to update alarm");

        List<Remind> waitingReminds =
            RemindDatabase.getInstance().getStoredData(DatabaseHelper.FILTER_WAITING_REMINDS);
        for (Remind remind : waitingReminds) {
          if (remind.getNotificationMillis() >= System.currentTimeMillis()) {
            setAlarm(remind.getId(), remind.getNotificationMillis(), remind.getTitle());
          }
        }
        break;

      case MODE_ONE_REMIND:
        Log.i(TAG, "NotificationService called to set one alarm");

        int setAlarmId = intent.getIntExtra(DatabaseHelper.COLUMN_ID, 0);
        long alarmMillis = intent.getLongExtra(DatabaseHelper.COLUMN_MILLIS, 0);
        String alarmMessage = intent.getStringExtra(DatabaseHelper.COLUMN_TITLE);
        setAlarm(setAlarmId, alarmMillis, alarmMessage);
        break;

      case MODE_UPDATE_ALARM:
        Log.i(TAG, "NotificationService called to update alarm");

        int updateAlarmId = intent.getIntExtra(DatabaseHelper.COLUMN_ID, 0);
        updateAlarm(updateAlarmId);
        break;
    }
  }
Example #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    RelativeLayout view =
        (RelativeLayout) inflater.inflate(R.layout.fragment_list, container, false);
    tvListEmptyNotifier = (TextView) view.findViewById(R.id.emptyLayout);

    RecyclerView rvContent = (RecyclerView) view.findViewById(R.id.rvContent);
    rvContent.setLayoutManager(new LinearLayoutManager(view.getContext()));
    mAdapter = new RemindAdapter(getActivity(), new ArrayList<Remind>());
    mAdapter.setOnListChangesListener(
        new RemindAdapter.ListChangesListener() {
          @Override
          public void onListSizeChanged() {
            if (mAdapter.getItemCount() == 0) {
              tvListEmptyNotifier.setVisibility(View.VISIBLE);
            } else {
              tvListEmptyNotifier.setVisibility(View.INVISIBLE);
            }
          }
        });
    switch (mFragmentType) {
      case FRAGMENT_TYPE_CURRENT:
        mAdapter.updateData(
            RemindDatabase.getInstance().getStoredData(DatabaseHelper.FILTER_WAITING_REMINDS));
        mAdapter.setItemEditable(true);
        rvContent.setItemAnimator(new FadeInRightAnimator());
        break;

      case FRAGMENT_TYPE_DONE:
        mAdapter.updateData(
            RemindDatabase.getInstance().getStoredData(DatabaseHelper.FILTER_DONE_REMINDS));
        mAdapter.setItemEditable(false);
        rvContent.setItemAnimator(new FadeInLeftAnimator());

        rvContent.setAlpha((float) FRAGMENT_DONE_ITEM_ALPHA);
        ((TextView) view.findViewById(R.id.emptyLayout))
            .setText(R.string.empty_layout_no_done_reminds);
        break;
    }
    rvContent.setAdapter(mAdapter);

    return view;
  }
Example #3
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;
      }
    }
Example #4
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;
    }
  }