Merge remote-tracking branch 'origin/master' into develop
This commit is contained in:
commit
da62d40487
|
@ -1382,6 +1382,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
|||
new OrderBy(Activities.TIMESTAMP, false).getSQL());
|
||||
if (c == null) return;
|
||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||
final StringBuilder pebbleNotificationStringBuilder = new StringBuilder();
|
||||
try {
|
||||
final int count = c.getCount();
|
||||
if (count == 0) return;
|
||||
|
@ -1404,6 +1405,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
|||
while (c.moveToNext()) {
|
||||
if (messageLines == 5) {
|
||||
style.addLine(resources.getString(R.string.and_N_more, count - c.getPosition()));
|
||||
pebbleNotificationStringBuilder.append(resources.getString(R.string.and_N_more, count - c.getPosition()));
|
||||
break;
|
||||
}
|
||||
final ParcelableActivity activity = ci.newObject(c);
|
||||
|
@ -1434,9 +1436,15 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
|||
final CharSequence summary = message.getSummary();
|
||||
if (TextUtils.isEmpty(summary)) {
|
||||
style.addLine(message.getTitle());
|
||||
pebbleNotificationStringBuilder.append(message.getTitle());
|
||||
pebbleNotificationStringBuilder.append("\n");
|
||||
} else {
|
||||
style.addLine(SpanFormatter.format(resources.getString(R.string.title_summary_line_format),
|
||||
message.getTitle(), summary));
|
||||
pebbleNotificationStringBuilder.append(message.getTitle());
|
||||
pebbleNotificationStringBuilder.append(": ");
|
||||
pebbleNotificationStringBuilder.append(message.getSummary());
|
||||
pebbleNotificationStringBuilder.append("\n");
|
||||
}
|
||||
messageLines++;
|
||||
}
|
||||
|
@ -1460,6 +1468,9 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
|||
final int notificationId = Utils.getNotificationId(NOTIFICATION_ID_INTERACTIONS_TIMELINE,
|
||||
accountKey);
|
||||
mNotificationManager.notify("interactions", notificationId, builder.build());
|
||||
|
||||
Utils.sendPebbleNotification(context, context.getResources().getString(R.string.interactions), pebbleNotificationStringBuilder.toString());
|
||||
|
||||
}
|
||||
|
||||
private PendingIntent getContentIntent(final Context context, @CustomTabType final String type,
|
||||
|
@ -1562,6 +1573,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();
|
||||
|
@ -1609,6 +1623,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);
|
||||
|
@ -1643,7 +1663,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());
|
||||
Utils.sendPebbleNotification(context, notificationContent);
|
||||
|
||||
//TODO: Pebble notification - Only notify about recently added DMs, not previous ones?
|
||||
Utils.sendPebbleNotification(context, "DM", pebbleNotificationBuilder.toString());
|
||||
} catch (SecurityException e) {
|
||||
// Silently ignore
|
||||
}
|
||||
|
|
|
@ -2227,13 +2227,34 @@ public final class Utils implements Constants {
|
|||
* @param message String
|
||||
*/
|
||||
public static void sendPebbleNotification(final Context context, final String message) {
|
||||
sendPebbleNotification(context, null, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Notifications to Pebble smartwatches
|
||||
*
|
||||
* @param context Context
|
||||
* @param title String
|
||||
* @param message String
|
||||
*/
|
||||
public static void sendPebbleNotification(final Context context, final String title, final String message)
|
||||
{
|
||||
String appName;
|
||||
|
||||
if ( title == null)
|
||||
{
|
||||
appName = context.getString(R.string.app_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
appName = context.getString(R.string.app_name) + " - " + title;
|
||||
}
|
||||
|
||||
if (context == null || TextUtils.isEmpty(message)) return;
|
||||
final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
|
||||
if (prefs.getBoolean(KEY_PEBBLE_NOTIFICATIONS, false)) {
|
||||
|
||||
final String appName = context.getString(R.string.app_name);
|
||||
|
||||
final List<PebbleMessage> messages = new ArrayList<>();
|
||||
messages.add(new PebbleMessage(appName, message));
|
||||
|
||||
|
@ -2244,6 +2265,7 @@ public final class Utils implements Constants {
|
|||
|
||||
context.getApplicationContext().sendBroadcast(intent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
Loading…
Reference in New Issue