Search in sources :

Example 1 with ImageModel

use of com.moez.QKSMS.model.ImageModel 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)

Aggregations

PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 ImageModel (com.moez.QKSMS.model.ImageModel)1 SlideshowModel (com.moez.QKSMS.model.SlideshowModel)1 MessageItem (com.moez.QKSMS.ui.messagelist.MessageItem)1