diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 67c75e2b..2add64d9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -73,6 +73,7 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.modules.repos.RepoPagerView"/>
+
-
+
+
+
{
- AppHelper.cancelNotification(this, BundleConstant.REQUEST_CODE);
+ AppHelper.cancelAllNotifications(getApplicationContext());
if (item != null) {
onSave(item.getItems());
}
@@ -100,17 +100,16 @@ public class NotificationSchedulerJobTask extends JobService {
.filter(Notification::isUnread)
.count();
if (count == 0) {
- AppHelper.cancelNotification(this, BundleConstant.REQUEST_CODE);
+ AppHelper.cancelAllNotifications(getApplicationContext());
return;
}
Context context = getApplicationContext();
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher);
-
int accentColor = ViewHelper.getAccentColor(context);
Notification firstNotification = notificationThreadModels.get(0);
android.app.Notification grouped = getSummaryGroupNotification(firstNotification, accentColor, largeIcon);
- showNotification(BundleConstant.REQUEST_CODE, grouped);
+ showNotification((int) firstNotification.getId(), grouped);
Stream.of(notificationThreadModels)
.filter(notification -> notification.isUnread() && notification.getId() != firstNotification.getId())
.limit(10)
@@ -119,35 +118,48 @@ public class NotificationSchedulerJobTask extends JobService {
RestProvider.getNotificationService().getComment(thread.getSubject().getLatestCommentUrl())
.subscribeOn(Schedulers.io())
.subscribe(comment -> {
- android.app.Notification toAdd = getNotification(thread.getSubject().getTitle(),
- thread.getRepository().getFullName())
- .setStyle(new NotificationCompat.BigTextStyle()
- .bigText(comment.getBody())
- .setBigContentTitle(comment.getUser() != null ? comment.getUser().getLogin() : ""))
- .setLargeIcon(largeIcon)
- .setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
- .setGroup(NOTIFICATION_GROUP_ID)
- .setColor(accentColor)
- .addAction(R.drawable.ic_github, context.getString(R.string.open), getPendingIntent(thread.getId(),
- thread.getSubject().getUrl()))
- .build();
+ android.app.Notification toAdd = getNotificationWithComment(context, largeIcon, accentColor, thread, comment);
showNotification((int) thread.getId(), toAdd);
}, Throwable::printStackTrace);
} else {
- android.app.Notification toAdd = getNotification(thread.getSubject().getTitle(),
- thread.getRepository().getFullName())
- .setLargeIcon(largeIcon)
- .setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
- .setGroup(NOTIFICATION_GROUP_ID)
- .setColor(accentColor)
- .addAction(R.drawable.ic_github, context.getString(R.string.open), getPendingIntent(thread.getId(), thread
- .getSubject().getUrl()))
- .build();
- showNotification((int) thread.getId(), toAdd);
+ showNotificationWithoutCommnet(context, largeIcon, accentColor, thread);
}
});
}
+ private void showNotificationWithoutCommnet(Context context, Bitmap largeIcon, int accentColor, Notification thread) {
+ android.app.Notification toAdd = getNotification(thread.getSubject().getTitle(),
+ thread.getRepository().getFullName())
+ .setLargeIcon(largeIcon)
+ .setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
+ .setGroup(NOTIFICATION_GROUP_ID)
+ .setColor(accentColor)
+ .addAction(R.drawable.ic_github, context.getString(R.string.open), getPendingIntent(thread.getId(), thread
+ .getSubject().getUrl()))
+ .addAction(R.drawable.ic_eye_off, context.getString(R.string.mark_as_read), getReadOnlyPendingIntent(thread.getId(), thread
+ .getSubject().getUrl()))
+ .build();
+ showNotification((int) thread.getId(), toAdd);
+ }
+
+ private android.app.Notification getNotificationWithComment(Context context, Bitmap largeIcon, int accentColor,
+ Notification thread, Comment comment) {
+ return getNotification(thread.getSubject().getTitle(),
+ thread.getRepository().getFullName())
+ .setStyle(new NotificationCompat.BigTextStyle()
+ .bigText(comment.getBody())
+ .setBigContentTitle(comment.getUser() != null ? comment.getUser().getLogin() : ""))
+ .setLargeIcon(largeIcon)
+ .setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
+ .setGroup(NOTIFICATION_GROUP_ID)
+ .setColor(accentColor)
+ .addAction(R.drawable.ic_github, context.getString(R.string.open), getPendingIntent(thread.getId(),
+ thread.getSubject().getUrl()))
+ .addAction(R.drawable.ic_eye_off, context.getString(R.string.mark_as_read), getReadOnlyPendingIntent(thread.getId(),
+ thread.getSubject().getUrl()))
+ .build();
+ }
+
private android.app.Notification getSummaryGroupNotification(@NonNull Notification notification, int accentColor, Bitmap largeIcon) {
return getNotification(notification.getSubject().getTitle(), notification.getRepository().getFullName())
.setLargeIcon(largeIcon)
@@ -155,6 +167,10 @@ public class NotificationSchedulerJobTask extends JobService {
.setGroupSummary(true)
.setColor(accentColor)
.setContentIntent(getPendingIntent(notification.getId(), notification.getSubject().getUrl()))
+ .addAction(R.drawable.ic_github, getString(R.string.open),
+ getPendingIntent(notification.getId(), notification.getSubject().getUrl()))
+ .addAction(R.drawable.ic_eye_off, getString(R.string.mark_as_read), getReadOnlyPendingIntent(notification.getId(),
+ notification.getSubject().getUrl()))
.setAutoCancel(true)
.build();
}
@@ -171,6 +187,12 @@ public class NotificationSchedulerJobTask extends JobService {
mNotificationManager.notify(id, notification);
}
+ private PendingIntent getReadOnlyPendingIntent(long id, @NonNull String url) {
+ Intent intent = ReadNotificationService.start(this, id, url, true);
+ return PendingIntent.getService(this, (int) id, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ }
+
private PendingIntent getPendingIntent(long id, @NonNull String url) {
Intent intent = ReadNotificationService.start(this, id, url);
return PendingIntent.getService(this, (int) id, intent,
diff --git a/app/src/main/java/com/fastaccess/provider/tasks/notification/ReadNotificationService.java b/app/src/main/java/com/fastaccess/provider/tasks/notification/ReadNotificationService.java
index 26240bbe..b364fd47 100644
--- a/app/src/main/java/com/fastaccess/provider/tasks/notification/ReadNotificationService.java
+++ b/app/src/main/java/com/fastaccess/provider/tasks/notification/ReadNotificationService.java
@@ -43,11 +43,16 @@ public class ReadNotificationService extends IntentService {
}
public static Intent start(@NonNull Context context, long id, @NonNull String url) {
+ return start(context, id, url, false);
+ }
+
+ public static Intent start(@NonNull Context context, long id, @NonNull String url, boolean onlyRead) {
Intent intent = new Intent(context.getApplicationContext(), ReadNotificationService.class);
intent.putExtras(Bundler.start()
.put(BundleConstant.EXTRA_TYPE, OPEN_NOTIFICATIO)
.put(BundleConstant.EXTRA, url)
.put(BundleConstant.ID, id)
+ .put(BundleConstant.YES_NO_EXTRA, onlyRead)
.end());
return intent;
}
@@ -74,18 +79,19 @@ public class ReadNotificationService extends IntentService {
} else if (type == READ_ALL) {
markMultiAsRead(bundle.getLongArray(BundleConstant.ID));
} else if (type == OPEN_NOTIFICATIO) {
- openNotification(bundle.getLong(BundleConstant.ID), bundle.getString(BundleConstant.EXTRA));
+ openNotification(bundle.getLong(BundleConstant.ID), bundle.getString(BundleConstant.EXTRA),
+ bundle.getBoolean(BundleConstant.YES_NO_EXTRA));
}
}
}
- private void openNotification(long id, @Nullable String url) {
+ private void openNotification(long id, @Nullable String url, boolean readOnly) {
if (id > 0 && url != null) {
AppHelper.cancelNotification(this, (int) id);
- if (!PrefGetter.isMarkAsReadEnabled()) {
+ if (!PrefGetter.isMarkAsReadEnabled() || readOnly) {
markSingleAsRead(id);
}
- SchemeParser.launchUri(this, Uri.parse(url), true);
+ if (!readOnly) SchemeParser.launchUri(this, Uri.parse(url), true);
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9e39f354..4b56a5d1 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -337,4 +337,5 @@
No members
No teams
No Organizations
+ Mark as read
\ No newline at end of file