mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
#1369 Notification alerts. Skip old stories
This commit is contained in:
parent
f118e21936
commit
506666e5f1
2 changed files with 18 additions and 6 deletions
|
@ -9,6 +9,7 @@ import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
import androidx.core.app.NotificationManagerCompat;
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
|
|
||||||
|
@ -44,6 +45,11 @@ public class NotificationUtils {
|
||||||
nm.cancel(story.hashCode());
|
nm.cancel(story.hashCode());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (StoryUtils.hasOldTimestamp(story.timestamp)) {
|
||||||
|
FeedUtils.dbHelper.putStoryDismissed(story.storyHash);
|
||||||
|
nm.cancel(story.hashCode());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (count < MAX_CONCUR_NOTIFY) {
|
if (count < MAX_CONCUR_NOTIFY) {
|
||||||
Notification n = buildStoryNotification(story, storiesFocus, context, iconCache);
|
Notification n = buildStoryNotification(story, storiesFocus, context, iconCache);
|
||||||
nm.notify(story.hashCode(), n);
|
nm.notify(story.hashCode(), n);
|
||||||
|
@ -63,6 +69,11 @@ public class NotificationUtils {
|
||||||
nm.cancel(story.hashCode());
|
nm.cancel(story.hashCode());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (StoryUtils.hasOldTimestamp(story.timestamp)) {
|
||||||
|
FeedUtils.dbHelper.putStoryDismissed(story.storyHash);
|
||||||
|
nm.cancel(story.hashCode());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (count < MAX_CONCUR_NOTIFY) {
|
if (count < MAX_CONCUR_NOTIFY) {
|
||||||
Notification n = buildStoryNotification(story, storiesUnread, context, iconCache);
|
Notification n = buildStoryNotification(story, storiesUnread, context, iconCache);
|
||||||
nm.notify(story.hashCode(), n);
|
nm.notify(story.hashCode(), n);
|
||||||
|
@ -131,15 +142,14 @@ public class NotificationUtils {
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
.setDeleteIntent(dismissPendingIntent)
|
.setDeleteIntent(dismissPendingIntent)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
|
.setOnlyAlertOnce(true)
|
||||||
.setWhen(story.timestamp)
|
.setWhen(story.timestamp)
|
||||||
.addAction(0, "Save", savePendingIntent)
|
.addAction(0, "Save", savePendingIntent)
|
||||||
.addAction(0, "Mark Read", markreadPendingIntent);
|
.addAction(0, "Mark Read", markreadPendingIntent)
|
||||||
|
.setColor(NOTIFY_COLOUR);
|
||||||
if (feedIcon != null) {
|
if (feedIcon != null) {
|
||||||
nb.setLargeIcon(feedIcon);
|
nb.setLargeIcon(feedIcon);
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
nb.setColor(NOTIFY_COLOUR);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nb.build();
|
return nb.build();
|
||||||
}
|
}
|
||||||
|
@ -153,6 +163,4 @@ public class NotificationUtils {
|
||||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
nm.cancel(nid);
|
nm.cancel(nid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,4 +189,8 @@ public class StoryUtils {
|
||||||
return shortDateFormat.get().format(storyDate) +", " + timeFormat.format(storyDate);
|
return shortDateFormat.get().format(storyDate) +", " + timeFormat.format(storyDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasOldTimestamp(long storyTimestamp) {
|
||||||
|
return (System.currentTimeMillis() - storyTimestamp) > (2 * DateUtils.DAY_IN_MILLIS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue