Permalink
Browse files

Set notification channel ID

  • Loading branch information...
QuantumBadger committed Feb 2, 2019
1 parent 4653951 commit 74793065ea5045416d59b930b75a1b3727f4b722
Showing with 14 additions and 4 deletions.
  1. +14 −4 src/main/java/org/quantumbadger/redreader/receivers/NewMessageChecker.java
@@ -17,14 +17,14 @@

package org.quantumbadger.redreader.receivers;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.account.RedditAccount;
@@ -48,6 +48,8 @@

public class NewMessageChecker extends BroadcastReceiver {

private static final String TAG = "NewMessageChecker";

private static final String PREFS_SAVED_MESSAGE_ID = "LastMessageId";
private static final String PREFS_SAVED_MESSAGE_TIMESTAMP = "LastMessageTimestamp";

@@ -99,7 +101,7 @@ protected void onCallbackException(final Throwable t) {

@Override
protected void onFailure(final @CacheRequest.RequestFailureType int type, final Throwable t, final Integer status, final String readableMessage) {
Log.e("NewMessageChecker", "Request failed", t);
Log.e(TAG, "Request failed", t);
}

@Override
@@ -120,6 +122,8 @@ public void onJsonParseStarted(final JsonValue value, final long timestamp, fina
children.join();
final int messageCount = children.getCurrentItemCount();

Log.e(TAG, "Got response. Message count = " + messageCount);

if(messageCount < 1) {
return;
}
@@ -162,6 +166,8 @@ public void onJsonParseStarted(final JsonValue value, final long timestamp, fina

if(oldMessageId == null || (!messageID.equals(oldMessageId) && oldMessageTimestamp <= messageTimestamp)) {

Log.e(TAG, "New messages detected. Showing notification.");

prefs.edit()
.putString(PREFS_SAVED_MESSAGE_ID, messageID)
.putLong(PREFS_SAVED_MESSAGE_TIMESTAMP, messageTimestamp)
@@ -172,6 +178,9 @@ public void onJsonParseStarted(final JsonValue value, final long timestamp, fina
}

createNotification(title, text, context);

} else {
Log.e(TAG, "All messages have been previously seen.");
}

} catch(Throwable t) {
@@ -185,11 +194,12 @@ public void onJsonParseStarted(final JsonValue value, final long timestamp, fina

private static void createNotification(String title, String text, Context context) {

final Notification.Builder notification = new Notification.Builder(context)
final NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.icon_notif)
.setContentTitle(title)
.setContentText(text)
.setAutoCancel(true);
.setAutoCancel(true)
.setChannelId("RRNewMessageChecker");

final Intent intent = new Intent(context, InboxListingActivity.class);
notification.setContentIntent(PendingIntent.getActivity(context, 0, intent, 0));

0 comments on commit 7479306

Please sign in to comment.