Exemplo n.º 1
0
  private static void sendMultipleThreadNotification(
      Context context, NotificationState notificationState, boolean signal) {
    MultipleRecipientNotificationBuilder builder =
        new MultipleRecipientNotificationBuilder(
            context, SMSSecurePreferences.getNotificationPrivacy(context));
    List<NotificationItem> notifications = notificationState.getNotifications();

    builder.setMessageCount(
        notificationState.getMessageCount(), notificationState.getThreadCount());
    builder.setMostRecentSender(notifications.get(0).getIndividualRecipient());

    long timestamp = notifications.get(0).getTimestamp();
    if (timestamp != 0) builder.setWhen(timestamp);

    builder.addActions(notificationState.getMarkAsReadIntent(context));

    ListIterator<NotificationItem> iterator = notifications.listIterator(0);

    while (iterator.hasNext()) {
      NotificationItem item = iterator.next();
      builder.addMessageBody(item.getIndividualRecipient(), item.getText());
    }

    if (signal) {
      builder.setAlarms(notificationState.getRingtone(), notificationState.getVibrate());
      builder.setTicker(notifications.get(0).getText());
    }

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
        .notify(NOTIFICATION_ID, builder.build());
  }
Exemplo n.º 2
0
  public static void notifyMessageDeliveryFailed(
      Context context, Recipients recipients, long threadId) {
    if (visibleThread == threadId) {
      sendInThreadNotification(context, recipients);
    } else {
      Intent intent = new Intent(context, ConversationActivity.class);
      intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
      intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
      intent.setData((Uri.parse("custom://" + System.currentTimeMillis())));

      FailedNotificationBuilder builder =
          new FailedNotificationBuilder(
              context, SMSSecurePreferences.getNotificationPrivacy(context), intent);
      ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
          .notify((int) threadId, builder.build());
    }
  }
Exemplo n.º 3
0
  private static void sendSingleThreadNotification(
      Context context,
      MasterSecret masterSecret,
      NotificationState notificationState,
      boolean signal) {
    if (notificationState.getNotifications().isEmpty()) {
      ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
          .cancel(NOTIFICATION_ID);
      return;
    }

    SingleRecipientNotificationBuilder builder =
        new SingleRecipientNotificationBuilder(
            context, masterSecret, SMSSecurePreferences.getNotificationPrivacy(context));
    List<NotificationItem> notifications = notificationState.getNotifications();

    builder.setSender(notifications.get(0).getIndividualRecipient());
    builder.setMessageCount(notificationState.getMessageCount());
    builder.setPrimaryMessageBody(
        notifications.get(0).getText(), notifications.get(0).getSlideDeck());
    builder.setContentIntent(notifications.get(0).getPendingIntent(context));

    long timestamp = notifications.get(0).getTimestamp();
    if (timestamp != 0) builder.setWhen(timestamp);

    builder.addActions(
        masterSecret,
        notificationState.getMarkAsReadIntent(context),
        notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipients()),
        notificationState.getWearableReplyIntent(context, notifications.get(0).getRecipients()));

    ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());

    while (iterator.hasPrevious()) {
      builder.addMessageBody(iterator.previous().getText());
    }

    if (signal) {
      builder.setAlarms(notificationState.getRingtone(), notificationState.getVibrate());
      builder.setTicker(
          notifications.get(0).getIndividualRecipient(), notifications.get(0).getText());
    }

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
        .notify(NOTIFICATION_ID, builder.build());
  }