Search in sources :

Example 1 with NotificationPrivacyPreference

use of org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference in project Signal-Android by signalapp.

the class VoiceNoteMediaItemFactory method buildMediaItem.

private static MediaItem buildMediaItem(@NonNull Context context, @NonNull Recipient threadRecipient, @NonNull Recipient avatarRecipient, @NonNull Recipient sender, int startingPosition, long threadId, long messageId, long dateReceived, @NonNull Uri audioUri) {
    Bundle extras = new Bundle();
    extras.putString(EXTRA_THREAD_RECIPIENT_ID, threadRecipient.getId().serialize());
    extras.putString(EXTRA_AVATAR_RECIPIENT_ID, avatarRecipient.getId().serialize());
    extras.putString(EXTRA_INDIVIDUAL_RECIPIENT_ID, sender.getId().serialize());
    extras.putLong(EXTRA_MESSAGE_POSITION, startingPosition);
    extras.putLong(EXTRA_THREAD_ID, threadId);
    extras.putLong(EXTRA_COLOR, threadRecipient.getChatColors().asSingleColor());
    extras.putLong(EXTRA_MESSAGE_ID, messageId);
    extras.putLong(EXTRA_MESSAGE_TIMESTAMP, dateReceived);
    NotificationPrivacyPreference preference = SignalStore.settings().getMessageNotificationsPrivacy();
    String title = getTitle(context, sender, threadRecipient, preference);
    String subtitle = null;
    if (preference.isDisplayContact()) {
        subtitle = context.getString(R.string.VoiceNoteMediaItemFactory__voice_message, DateUtils.formatDateWithoutDayOfWeek(Locale.getDefault(), dateReceived));
    }
    return new MediaItem.Builder().setUri(audioUri).setMediaMetadata(new MediaMetadata.Builder().setTitle(title).setSubtitle(subtitle).setExtras(extras).build()).setTag(new MediaDescriptionCompat.Builder().setMediaUri(audioUri).setTitle(title).setSubtitle(subtitle).setExtras(extras).build()).build();
}
Also used : Bundle(android.os.Bundle) MediaMetadata(com.google.android.exoplayer2.MediaMetadata) MediaDescriptionCompat(android.support.v4.media.MediaDescriptionCompat) NotificationPrivacyPreference(org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference)

Example 2 with NotificationPrivacyPreference

use of org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference in project Signal-Android by WhisperSystems.

the class BubbleUtil method canBubble.

/**
 * Checks whether we are allowed to create a bubble for the given recipient.
 *
 * In order to Bubble, a recipient must have a thread, be unblocked, and the user must not have
 * notification privacy settings enabled. Furthermore, we check the Notifications system to verify
 * that bubbles are allowed in the first place.
 */
@RequiresApi(CONVERSATION_SUPPORT_VERSION)
@WorkerThread
public static boolean canBubble(@NonNull Context context, @NonNull RecipientId recipientId, @Nullable Long threadId) {
    if (threadId == null) {
        Log.i(TAG, "Cannot bubble recipient without thread");
        return false;
    }
    NotificationPrivacyPreference privacyPreference = SignalStore.settings().getMessageNotificationsPrivacy();
    if (!privacyPreference.isDisplayContact()) {
        Log.i(TAG, "Bubbles are not available when notification privacy settings are enabled.");
        return false;
    }
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isBlocked()) {
        Log.i(TAG, "Cannot bubble blocked recipient");
        return false;
    }
    NotificationManager notificationManager = ServiceUtil.getNotificationManager(context);
    NotificationChannel conversationChannel = notificationManager.getNotificationChannel(ConversationUtil.getChannelId(context, recipient), ConversationUtil.getShortcutId(recipientId));
    return notificationManager.areBubblesAllowed() || (conversationChannel != null && conversationChannel.canBubble());
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) Recipient(org.thoughtcrime.securesms.recipients.Recipient) NotificationPrivacyPreference(org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference) WorkerThread(androidx.annotation.WorkerThread) RequiresApi(androidx.annotation.RequiresApi)

Example 3 with NotificationPrivacyPreference

use of org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference in project Signal-Android by WhisperSystems.

the class VoiceNoteMediaItemFactory method buildMediaItem.

private static MediaItem buildMediaItem(@NonNull Context context, @NonNull Recipient threadRecipient, @NonNull Recipient avatarRecipient, @NonNull Recipient sender, int startingPosition, long threadId, long messageId, long dateReceived, @NonNull Uri audioUri) {
    Bundle extras = new Bundle();
    extras.putString(EXTRA_THREAD_RECIPIENT_ID, threadRecipient.getId().serialize());
    extras.putString(EXTRA_AVATAR_RECIPIENT_ID, avatarRecipient.getId().serialize());
    extras.putString(EXTRA_INDIVIDUAL_RECIPIENT_ID, sender.getId().serialize());
    extras.putLong(EXTRA_MESSAGE_POSITION, startingPosition);
    extras.putLong(EXTRA_THREAD_ID, threadId);
    extras.putLong(EXTRA_COLOR, threadRecipient.getChatColors().asSingleColor());
    extras.putLong(EXTRA_MESSAGE_ID, messageId);
    extras.putLong(EXTRA_MESSAGE_TIMESTAMP, dateReceived);
    NotificationPrivacyPreference preference = SignalStore.settings().getMessageNotificationsPrivacy();
    String title = getTitle(context, sender, threadRecipient, preference);
    String subtitle = null;
    if (preference.isDisplayContact()) {
        subtitle = context.getString(R.string.VoiceNoteMediaItemFactory__voice_message, DateUtils.formatDateWithoutDayOfWeek(Locale.getDefault(), dateReceived));
    }
    return new MediaItem.Builder().setUri(audioUri).setMediaMetadata(new MediaMetadata.Builder().setTitle(title).setSubtitle(subtitle).setExtras(extras).build()).setTag(new MediaDescriptionCompat.Builder().setMediaUri(audioUri).setTitle(title).setSubtitle(subtitle).setExtras(extras).build()).build();
}
Also used : Bundle(android.os.Bundle) MediaMetadata(com.google.android.exoplayer2.MediaMetadata) MediaDescriptionCompat(android.support.v4.media.MediaDescriptionCompat) NotificationPrivacyPreference(org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference)

Example 4 with NotificationPrivacyPreference

use of org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference in project Signal-Android by signalapp.

the class BubbleUtil method canBubble.

/**
 * Checks whether we are allowed to create a bubble for the given recipient.
 *
 * In order to Bubble, a recipient must have a thread, be unblocked, and the user must not have
 * notification privacy settings enabled. Furthermore, we check the Notifications system to verify
 * that bubbles are allowed in the first place.
 */
@RequiresApi(CONVERSATION_SUPPORT_VERSION)
@WorkerThread
public static boolean canBubble(@NonNull Context context, @NonNull RecipientId recipientId, @Nullable Long threadId) {
    if (threadId == null) {
        Log.i(TAG, "Cannot bubble recipient without thread");
        return false;
    }
    NotificationPrivacyPreference privacyPreference = SignalStore.settings().getMessageNotificationsPrivacy();
    if (!privacyPreference.isDisplayContact()) {
        Log.i(TAG, "Bubbles are not available when notification privacy settings are enabled.");
        return false;
    }
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isBlocked()) {
        Log.i(TAG, "Cannot bubble blocked recipient");
        return false;
    }
    NotificationManager notificationManager = ServiceUtil.getNotificationManager(context);
    NotificationChannel conversationChannel = notificationManager.getNotificationChannel(ConversationUtil.getChannelId(context, recipient), ConversationUtil.getShortcutId(recipientId));
    return notificationManager.areBubblesAllowed() || (conversationChannel != null && conversationChannel.canBubble());
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) Recipient(org.thoughtcrime.securesms.recipients.Recipient) NotificationPrivacyPreference(org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference) WorkerThread(androidx.annotation.WorkerThread) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

NotificationPrivacyPreference (org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference)4 NotificationChannel (android.app.NotificationChannel)2 NotificationManager (android.app.NotificationManager)2 Bundle (android.os.Bundle)2 MediaDescriptionCompat (android.support.v4.media.MediaDescriptionCompat)2 RequiresApi (androidx.annotation.RequiresApi)2 WorkerThread (androidx.annotation.WorkerThread)2 MediaMetadata (com.google.android.exoplayer2.MediaMetadata)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2