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);
}
}
}
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);
}
}
}
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);
}
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;
}
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;
}
Aggregations