From 237a758425b1c202929b9ad3b3e3de75c5a9427e Mon Sep 17 00:00:00 2001 From: Minori Hiraoka Date: Sun, 12 Jun 2016 11:32:03 +0900 Subject: [PATCH] When DM, show message content instead of '~ new notification from ~' in pebble notification. --- .../twidere/provider/TwidereDataProvider.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java b/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java index e7f5933aa..18e4419e0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java +++ b/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java @@ -1570,6 +1570,9 @@ public final class TwidereDataProvider extends ContentProvider implements Consta final Cursor userCursor = mDatabaseWrapper.query(DirectMessages.Inbox.TABLE_NAME, userProjection, filteredSelection, selectionArgs, DirectMessages.SENDER_ID, null, DirectMessages.DEFAULT_SORT_ORDER); + + final StringBuilder pebbleNotificationBuilder = new StringBuilder(); + //noinspection TryFinallyCanBeTryWithResources try { final int usersCount = userCursor.getCount(); @@ -1617,6 +1620,12 @@ public final class TwidereDataProvider extends ContentProvider implements Consta sb.append(' '); sb.append(messageCursor.getString(messageIndices.text_unescaped)); style.addLine(sb); + pebbleNotificationBuilder.append(mUserColorNameManager.getUserNickname(messageCursor.getString(idxUserId), + mNameFirst ? messageCursor.getString(messageIndices.sender_name) : + messageCursor.getString(messageIndices.sender_screen_name))); + pebbleNotificationBuilder.append(": "); + pebbleNotificationBuilder.append(messageCursor.getString(messageIndices.text_unescaped)); + pebbleNotificationBuilder.append("\n"); } final long userId = messageCursor.getLong(messageIndices.sender_id); final long messageId = messageCursor.getLong(messageIndices.id); @@ -1651,14 +1660,9 @@ public final class TwidereDataProvider extends ContentProvider implements Consta applyNotificationPreferences(builder, pref, pref.getDirectMessagesNotificationType()); try { nm.notify("messages_" + accountKey, NOTIFICATION_ID_DIRECT_MESSAGES, builder.build()); - if ( messagesCount == 1 && usersCount == 1 ) - { - // Single message, display content instead saying 'one message from foo' - //TODO: Which variable contains message content? - //Utils.sendPebbleNotification(context, ); - } - else // Do in the traditional way - Utils.sendPebbleNotification(context, notificationContent); + + //TODO: Pebble notification - Only notify about recently added DMs, not previous ones? + Utils.sendPebbleNotification(context, pebbleNotificationBuilder.toString()); } catch (SecurityException e) { // Silently ignore }