Search in sources :

Example 1 with MessageItem

use of com.moez.QKSMS.ui.messagelist.MessageItem in project qksms by moezbhatti.

the class ConversationLegacy method markUnread.

public void markUnread() {
    new DefaultSmsHelper(context, R.string.not_default_mark_unread).showIfNotDefault(null);
    try {
        cursor = context.getContentResolver().query(getUri(), MessageColumns.PROJECTION, null, null, SmsHelper.sortDateDesc);
        cursor.moveToFirst();
        MessageColumns.ColumnsMap columnsMap = new MessageColumns.ColumnsMap(cursor);
        MessageItem message = new MessageItem(context, cursor.getString(columnsMap.mColumnMsgType), cursor, columnsMap, null, true);
        if (message.isMe()) {
            while (cursor.moveToNext()) {
                MessageItem message2 = new MessageItem(context, cursor.getString(columnsMap.mColumnMsgType), cursor, columnsMap, null, true);
                if (!message2.isMe()) {
                    message = message2;
                    break;
                }
            }
        }
        ContentValues cv = new ContentValues();
        cv.put("read", false);
        cv.put("seen", false);
        context.getContentResolver().update(message.mMessageUri, cv, null, null);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    NotificationManager.create(context);
}
Also used : MessageItem(com.moez.QKSMS.ui.messagelist.MessageItem) ContentValues(android.content.ContentValues) DefaultSmsHelper(com.moez.QKSMS.ui.dialog.DefaultSmsHelper) MessageColumns(com.moez.QKSMS.ui.messagelist.MessageColumns)

Example 2 with MessageItem

use of com.moez.QKSMS.ui.messagelist.MessageItem in project qksms by moezbhatti.

the class NotificationManager method buildSingleMessageNotification.

/**
 * Builds the actual notification for the single message. This code can be called at different points in execution
 * depending on whether or not the MMS data has been downloaded
 */
private static void buildSingleMessageNotification(final Context context, ArrayList<MessageItem> messages, long threadId, final NotificationCompat.Builder builder, ConversationPrefsHelper conversationPrefs, final Integer privateNotifications) {
    MessageItem message = messages.get(0);
    Intent threadIntent = new Intent(context, MainActivity.class);
    threadIntent.putExtra(MessageListActivity.ARG_THREAD_ID, threadId);
    final PendingIntent threadPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 1), threadIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent readIntent = new Intent(ACTION_MARK_READ);
    readIntent.putExtra("thread_id", threadId);
    final PendingIntent readPI = PendingIntent.getBroadcast(context, buildRequestCode(threadId, 2), readIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent seenIntent = new Intent(ACTION_MARK_SEEN);
    final PendingIntent seenPI = PendingIntent.getBroadcast(context, buildRequestCode(threadId, 4), seenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    int unreadMessageCount = SmsHelper.getUnreadMessageCount(context);
    String body;
    String title;
    NotificationCompat.Style nstyle = null;
    switch(privateNotifications) {
        case // Hide nothing
        0:
            body = message.mBody;
            title = message.mContact;
            nstyle = new NotificationCompat.BigTextStyle().bigText(message.mBody);
            break;
        case // Hide message
        1:
            body = sRes.getString(R.string.new_message);
            title = message.mContact;
            break;
        case // Hide sender & message
        2:
            body = sRes.getString(R.string.new_message);
            title = "QKSMS";
            break;
        default:
            body = message.mBody;
            title = message.mContact;
            nstyle = null;
    }
    builder.setContentTitle(title).setContentText(body).setLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false), privateNotifications)).setContentIntent(threadPI).setNumber(unreadMessageCount).setStyle(nstyle).setColor(ThemeManager.getColor()).addAction(R.drawable.ic_accept, sRes.getString(R.string.read), readPI).extend(RemoteMessagingReceiver.getConversationExtender(context, message.mContact, message.mAddress, threadId)).setDeleteIntent(seenPI);
    if (Build.VERSION.SDK_INT < 24) {
        Intent replyIntent = new Intent(context, QKReplyActivity.class);
        replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        replyIntent.putExtra(QKReplyActivity.EXTRA_THREAD_ID, threadId);
        replyIntent.putExtra(QKReplyActivity.EXTRA_SHOW_KEYBOARD, true);
        PendingIntent replyPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 0), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.ic_reply, sRes.getString(R.string.reply), replyPI);
    } else {
        builder.addAction(RemoteMessagingReceiver.getReplyAction(context, message.mAddress, threadId));
    }
    if (conversationPrefs.getDimissedReadEnabled()) {
        builder.setDeleteIntent(readPI);
    }
    if (conversationPrefs.getCallButtonEnabled()) {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:" + message.mAddress));
        PendingIntent callPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 3), callIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.ic_call, sRes.getString(R.string.call), callPI);
    }
    if (message.isMms()) {
        Log.d(TAG, "Message is MMS");
        SlideshowModel model = message.mSlideshow;
        if (model != null && model.isSimple() && model.get(0).getImage() != null) {
            Log.d(TAG, "MMS type: image");
            ImageModel imageModel = model.get(0).getImage();
            Bitmap image = imageModel.getBitmap(imageModel.getWidth(), imageModel.getHeight());
            NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle().setBigContentTitle(message.mContact).setSummaryText(message.mBody).bigLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false), privateNotifications)).bigPicture(image);
            if (privateNotifications == 0)
                builder.setStyle(style);
            else
                builder.setStyle(null);
        } else {
            Log.d(TAG, "MMS Type: not an image lol");
            if (privateNotifications == 0)
                builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message.mBody));
            else
                builder.setStyle(null);
        }
    }
    NotificationManager.notify(context, (int) threadId, builder.build());
}
Also used : MessageItem(com.moez.QKSMS.ui.messagelist.MessageItem) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Bitmap(android.graphics.Bitmap) SlideshowModel(com.moez.QKSMS.model.SlideshowModel) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) ImageModel(com.moez.QKSMS.model.ImageModel)

Example 3 with MessageItem

use of com.moez.QKSMS.ui.messagelist.MessageItem in project qksms by moezbhatti.

the class AirplaneModeReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    // If we're going into airplane mode, no need to do anything
    if (intent.getBooleanExtra("state", true)) {
        return;
    }
    // Cursor to find the conversations that contain failed messages
    Cursor conversationCursor = context.getContentResolver().query(SmsHelper.CONVERSATIONS_CONTENT_PROVIDER, Conversation.ALL_THREADS_PROJECTION, Conversation.FAILED_SELECTION, null, SmsHelper.sortDateDesc);
    // Loop through each of the conversations
    while (conversationCursor.moveToNext()) {
        Uri uri = ContentUris.withAppendedId(SmsHelper.MMS_SMS_CONTENT_PROVIDER, conversationCursor.getLong(Conversation.ID));
        // Find the failed messages within the conversation
        Cursor cursor = context.getContentResolver().query(uri, MessageColumns.PROJECTION, SmsHelper.FAILED_SELECTION, null, SmsHelper.sortDateAsc);
        // Map the cursor row to a MessageItem, then re-send it
        MessageColumns.ColumnsMap columnsMap = new MessageColumns.ColumnsMap(cursor);
        while (cursor.moveToNext()) {
            try {
                MessageItem message = new MessageItem(context, cursor.getString(columnsMap.mColumnMsgType), cursor, columnsMap, null, true);
                sendSms(context, message);
            } catch (MmsException e) {
                e.printStackTrace();
            }
        }
        cursor.close();
    }
    conversationCursor.close();
}
Also used : MessageItem(com.moez.QKSMS.ui.messagelist.MessageItem) MmsException(com.google.android.mms.MmsException) Cursor(android.database.Cursor) Uri(android.net.Uri) MessageColumns(com.moez.QKSMS.ui.messagelist.MessageColumns)

Example 4 with MessageItem

use of com.moez.QKSMS.ui.messagelist.MessageItem in project qksms by moezbhatti.

the class NotificationManager method singleMessage.

/**
 * Displays a notification for a single message
 */
private static void singleMessage(final Context context, final ArrayList<MessageItem> messages, final long threadId, final NotificationCompat.Builder builder, final ConversationPrefsHelper conversationPrefs, final Integer privateNotifications) {
    MessageItem message = messages.get(0);
    if (message.isMms()) {
        Log.d(TAG, "Message is MMS");
        if (message.mSlideshow != null) {
            Log.d(TAG, "Woah! Slideshow not null");
            buildSingleMessageNotification(context, messages, threadId, builder, conversationPrefs, privateNotifications);
        } else {
            Log.d(TAG, "Listening for PDU");
            message.setOnPduLoaded(new MessageItem.PduLoadedCallback() {

                @Override
                public void onPduLoaded(MessageItem messageItem) {
                    Log.d(TAG, "PDU Loaded");
                    buildSingleMessageNotification(context, messages, threadId, builder, conversationPrefs, privateNotifications);
                }
            });
        }
    } else {
        buildSingleMessageNotification(context, messages, threadId, builder, conversationPrefs, privateNotifications);
    }
}
Also used : MessageItem(com.moez.QKSMS.ui.messagelist.MessageItem)

Example 5 with MessageItem

use of com.moez.QKSMS.ui.messagelist.MessageItem in project qksms by moezbhatti.

the class NotificationManager method singleSender.

/**
 * Creates a notification that contains several messages that are all part of the same conversation
 */
private static void singleSender(final Context context, ArrayList<MessageItem> messages, long threadId, final NotificationCompat.Builder builder, ConversationPrefsHelper conversationPrefs, final Integer privateNotifications) {
    MessageItem message = messages.get(0);
    Intent threadIntent = new Intent(context, MainActivity.class);
    threadIntent.putExtra(MessageListActivity.ARG_THREAD_ID, threadId);
    PendingIntent threadPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 1), threadIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent readIntent = new Intent(ACTION_MARK_READ);
    readIntent.putExtra("thread_id", threadId);
    PendingIntent readPI = PendingIntent.getBroadcast(context, buildRequestCode(threadId, 2), readIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent seenIntent = new Intent(ACTION_MARK_SEEN);
    PendingIntent seenPI = PendingIntent.getBroadcast(context, buildRequestCode(threadId, 4), seenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    for (MessageItem message1 : messages) {
        inboxStyle.addLine(message1.mBody);
    }
    String notificationTitle = message.mContact;
    if (!(privateNotifications == 0))
        inboxStyle = null;
    if (privateNotifications == 2)
        notificationTitle = "QKSMS";
    int unreadMessageCount = SmsHelper.getUnreadMessageCount(context);
    builder.setContentTitle(notificationTitle).setContentText(SmsHelper.getUnseenSMSCount(context, threadId) + " " + sRes.getString(R.string.new_messages)).setLargeIcon(getLargeIcon(context, Contact.get(message.mAddress, false), privateNotifications)).setContentIntent(threadPI).setNumber(unreadMessageCount).setStyle(inboxStyle).setColor(ThemeManager.getColor()).addAction(R.drawable.ic_accept, sRes.getString(R.string.read), readPI).extend(RemoteMessagingReceiver.getConversationExtender(context, message.mContact, message.mAddress, threadId)).setDeleteIntent(seenPI);
    if (Build.VERSION.SDK_INT < 24) {
        Intent replyIntent = new Intent(context, QKReplyActivity.class);
        replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        replyIntent.putExtra(QKReplyActivity.EXTRA_THREAD_ID, threadId);
        replyIntent.putExtra(QKReplyActivity.EXTRA_SHOW_KEYBOARD, true);
        PendingIntent replyPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 0), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.ic_reply, sRes.getString(R.string.reply), replyPI);
    } else {
        builder.addAction(RemoteMessagingReceiver.getReplyAction(context, message.mAddress, threadId));
    }
    if (conversationPrefs.getCallButtonEnabled()) {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:" + message.mAddress));
        PendingIntent callPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 3), callIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.ic_call, sRes.getString(R.string.call), callPI);
    }
    notify(context, (int) threadId, builder.build());
}
Also used : MessageItem(com.moez.QKSMS.ui.messagelist.MessageItem) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

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