use of com.moez.QKSMS.ui.messagelist.MessageItem in project qksms by moezbhatti.
the class SmsHelper method getUnreadUnseenConversations.
/**
* List of messages grouped by thread id, used for showing notifications
*/
public static HashMap<Long, ArrayList<MessageItem>> getUnreadUnseenConversations(Context context) {
HashMap<Long, ArrayList<MessageItem>> result = new HashMap<>();
String selection = SmsHelper.UNSEEN_SELECTION + " AND " + SmsHelper.UNREAD_SELECTION;
// Create a cursor for the conversation list
Cursor conversationCursor = context.getContentResolver().query(SmsHelper.CONVERSATIONS_CONTENT_PROVIDER, Conversation.ALL_THREADS_PROJECTION, SmsHelper.UNREAD_SELECTION, null, SmsHelper.sortDateAsc);
if (conversationCursor != null && conversationCursor.moveToFirst()) {
do {
ArrayList<MessageItem> messages = new ArrayList<>();
long threadId = conversationCursor.getLong(Conversation.ID);
Uri threadUri = Uri.withAppendedPath(Message.MMS_SMS_CONTENT_PROVIDER, Long.toString(threadId));
Cursor messageCursor = context.getContentResolver().query(threadUri, MessageColumns.PROJECTION, selection, null, SmsHelper.sortDateAsc);
if (messageCursor != null && messageCursor.moveToFirst()) {
do {
MessageColumns.ColumnsMap columnsMap = new MessageColumns.ColumnsMap(messageCursor);
MessageItem message = null;
try {
message = new MessageItem(context, messageCursor.getString(columnsMap.mColumnMsgType), messageCursor, columnsMap, null, true);
} catch (MmsException e) {
e.printStackTrace();
}
messages.add(message);
} while (messageCursor.moveToNext());
messageCursor.close();
result.put(threadId, messages);
}
} while (conversationCursor.moveToNext());
conversationCursor.close();
}
return result;
}
Aggregations