Search in sources :

Example 6 with MessageItem

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;
}
Also used : MessageItem(com.moez.QKSMS.ui.messagelist.MessageItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) MessageColumns(com.moez.QKSMS.ui.messagelist.MessageColumns) MmsException(com.google.android.mms.MmsException)

Aggregations

MessageItem (com.moez.QKSMS.ui.messagelist.MessageItem)6 MessageColumns (com.moez.QKSMS.ui.messagelist.MessageColumns)3 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Cursor (android.database.Cursor)2 Uri (android.net.Uri)2 NotificationCompat (android.support.v4.app.NotificationCompat)2 MmsException (com.google.android.mms.MmsException)2 ContentValues (android.content.ContentValues)1 Bitmap (android.graphics.Bitmap)1 ImageModel (com.moez.QKSMS.model.ImageModel)1 SlideshowModel (com.moez.QKSMS.model.SlideshowModel)1 DefaultSmsHelper (com.moez.QKSMS.ui.dialog.DefaultSmsHelper)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1