Search in sources :

Example 6 with TextMessage

use of cx.ring.model.TextMessage in project ring-client-android by savoirfairelinux.

the class ConversationFacade method parseHistoryTexts.

private void parseHistoryTexts(List<HistoryText> historyTexts, boolean acceptAllMessages) {
    for (HistoryText htext : historyTexts) {
        TextMessage msg = new TextMessage(htext);
        CallContact contact = mContactService.findContact(htext.getContactID(), htext.getContactKey(), new Uri(htext.getNumber()));
        String key = contact.getIds().get(0);
        String phone = contact.getPhones().get(0).getNumber().getRawUriString();
        if (mConversationMap.containsKey(key) || mConversationMap.containsKey(phone)) {
            mConversationMap.get(key).addTextMessage(msg);
        } else if (acceptAllMessages) {
            Conversation conversation = new Conversation(contact);
            conversation.addTextMessage(msg);
            mConversationMap.put(key, conversation);
        }
    }
}
Also used : HistoryText(cx.ring.model.HistoryText) Conversation(cx.ring.model.Conversation) Uri(cx.ring.model.Uri) TextMessage(cx.ring.model.TextMessage) CallContact(cx.ring.model.CallContact)

Example 7 with TextMessage

use of cx.ring.model.TextMessage in project ring-client-android by savoirfairelinux.

the class HistoryService method readMessages.

public void readMessages(Conversation conversation) {
    for (HistoryEntry h : conversation.getRawHistory().values()) {
        NavigableMap<Long, TextMessage> messages = h.getTextMessages();
        for (TextMessage message : messages.descendingMap().values()) {
            if (message.isRead()) {
                break;
            }
            message.read();
            HistoryText ht = new HistoryText(message);
            updateTextMessage(ht);
        }
    }
}
Also used : HistoryText(cx.ring.model.HistoryText) HistoryEntry(cx.ring.model.HistoryEntry) TextMessage(cx.ring.model.TextMessage)

Example 8 with TextMessage

use of cx.ring.model.TextMessage in project ring-client-android by savoirfairelinux.

the class NotificationServiceImpl method showTextNotification.

@Override
public void showTextNotification(CallContact contact, Conversation conversation, TreeMap<Long, TextMessage> texts) {
    if (texts.isEmpty()) {
        cancelTextNotification(contact);
        return;
    }
    TextMessage last = texts.lastEntry().getValue();
    Intent intentConversation = new Intent(DRingService.ACTION_CONV_ACCEPT).setClass(mContext, DRingService.class).putExtra(ConversationFragment.KEY_ACCOUNT_ID, conversation.getLastAccountUsed()).putExtra(ConversationFragment.KEY_CONTACT_RING_ID, contact.getPhones().get(0).getNumber().toString());
    Intent intentDelete = new Intent(DRingService.ACTION_CONV_DISMISS).setClass(mContext, DRingService.class).putExtra(ConversationFragment.KEY_ACCOUNT_ID, conversation.getLastAccountUsed()).putExtra(ConversationFragment.KEY_CONTACT_RING_ID, contact.getPhones().get(0).getNumber().toString());
    NotificationCompat.Builder messageNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIF_CHANNEL_MESSAGE).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(Notification.PRIORITY_HIGH).setDefaults(NotificationCompat.DEFAULT_ALL).setSmallIcon(R.drawable.ic_ring_logo_white).setContentTitle(contact.getDisplayName()).setContentText(last.getMessage()).setWhen(last.getDate()).setContentIntent(PendingIntent.getService(mContext, random.nextInt(), intentConversation, 0)).setDeleteIntent(PendingIntent.getService(mContext, random.nextInt(), intentDelete, 0)).setAutoCancel(true).setColor(ResourcesCompat.getColor(mContext.getResources(), R.color.color_primary_dark, null));
    setContactPicture(contact, messageNotificationBuilder);
    if (texts.size() == 1) {
        last.setNotified(true);
        messageNotificationBuilder.setStyle(null);
    } else {
        ArrayList<Spanned> txts = new ArrayList<>(3);
        int i = 0;
        for (TextMessage textMessage : texts.descendingMap().values()) {
            if (i == 5)
                break;
            txts.add(0, Html.fromHtml("<b>" + DateUtils.formatDateTime(mContext, textMessage.getDate(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL) + "</b> " + textMessage.getMessage()));
            textMessage.setNotified(true);
            i++;
        }
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        for (Spanned spanned : txts) {
            inboxStyle.addLine(spanned);
        }
        messageNotificationBuilder.setStyle(inboxStyle);
    }
    Intent intentRead = new Intent(DRingService.ACTION_CONV_READ).setClass(mContext, DRingService.class).putExtra(ConversationFragment.KEY_ACCOUNT_ID, conversation.getLastAccountUsed()).putExtra(ConversationFragment.KEY_CONTACT_RING_ID, contact.getPhones().get(0).getNumber().toString());
    messageNotificationBuilder.addAction(0, mContext.getString(R.string.notif_mark_as_read), PendingIntent.getService(mContext, Long.valueOf(System.currentTimeMillis()).intValue(), intentRead, 0));
    int notificationId = getTextNotificationId(contact);
    notificationManager.notify(notificationId, messageNotificationBuilder.build());
    mNotificationBuilders.put(notificationId, messageNotificationBuilder);
}
Also used : ArrayList(java.util.ArrayList) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Spanned(android.text.Spanned) TextMessage(cx.ring.model.TextMessage)

Example 9 with TextMessage

use of cx.ring.model.TextMessage in project ring-client-android by savoirfairelinux.

the class ConversationAdapter method shouldSeparateByDetails.

/**
 * Helper used to determine if a text details string should be displayed under a message at a
 * certain position.
 *
 * @param ht       The conversationElement at the given position
 * @param position The position of the current message
 * @return true if a text details string should be displayed under the message
 */
private boolean shouldSeparateByDetails(final TextMessage ht, int position) {
    if (ht == null) {
        return false;
    }
    boolean shouldSeparateMsg = false;
    TextMessage previousTextMessage = getPreviousMessageFromPosition(position);
    if (previousTextMessage != null) {
        shouldSeparateMsg = true;
        TextMessage nextTextMessage = getNextMessageFromPosition(position);
        if (nextTextMessage != null) {
            long diff = nextTextMessage.getDate() - ht.getDate();
            if (diff < MINUTE) {
                shouldSeparateMsg = false;
            }
        }
    }
    return shouldSeparateMsg;
}
Also used : TextMessage(cx.ring.model.TextMessage)

Example 10 with TextMessage

use of cx.ring.model.TextMessage in project ring-client-android by savoirfairelinux.

the class ConversationAdapter method isMessageConfigSameAsPrevious.

/**
 * Helper method determining if a given conversationElement should be distinguished from the
 * previous ie. if their configuration is not the same.
 *
 * @param textMessage The conversationElement at the given position
 * @param position    The position of the current message
 * @return true if the configuration is the same as the previous message, false otherwise.
 */
private boolean isMessageConfigSameAsPrevious(final TextMessage textMessage, int position) {
    if (textMessage == null) {
        return false;
    }
    boolean sameConfig = false;
    TextMessage previousMessage = getPreviousMessageFromPosition(position);
    if (previousMessage != null && previousMessage.isIncoming() && textMessage.isIncoming() && previousMessage.getNumber().equals(textMessage.getNumber())) {
        sameConfig = true;
    }
    return sameConfig;
}
Also used : TextMessage(cx.ring.model.TextMessage)

Aggregations

TextMessage (cx.ring.model.TextMessage)15 HistoryText (cx.ring.model.HistoryText)5 ServiceEvent (cx.ring.model.ServiceEvent)4 SipCall (cx.ring.model.SipCall)4 CallContact (cx.ring.model.CallContact)3 Conversation (cx.ring.model.Conversation)3 Uri (cx.ring.model.Uri)3 ArrayList (java.util.ArrayList)3 Conference (cx.ring.model.Conference)2 DataTransfer (cx.ring.model.DataTransfer)2 HistoryCall (cx.ring.model.HistoryCall)2 HistoryEntry (cx.ring.model.HistoryEntry)2 SecureSipCall (cx.ring.model.SecureSipCall)2 CallService (cx.ring.services.CallService)2 HistoryService (cx.ring.services.HistoryService)2 SQLException (java.sql.SQLException)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 NotificationCompat (android.support.v4.app.NotificationCompat)1