From c473dd7227ac6b593f5c90c2de74ec9f4fcf38c0 Mon Sep 17 00:00:00 2001 From: Amine Date: Wed, 7 Nov 2018 19:32:10 +0100 Subject: [PATCH] Fixes #239. --- .../bou/readerforselfoss/background/background.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt index 8a38e52..daf3ab6 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/background/background.kt @@ -1,7 +1,9 @@ package apps.amine.bou.readerforselfoss.background import android.app.NotificationManager +import android.app.PendingIntent import android.content.Context +import android.content.Intent import android.preference.PreferenceManager import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT @@ -9,6 +11,7 @@ import androidx.core.app.NotificationCompat.PRIORITY_LOW import androidx.room.Room import androidx.work.Worker import androidx.work.WorkerParameters +import apps.amine.bou.readerforselfoss.MainActivity import apps.amine.bou.readerforselfoss.R import apps.amine.bou.readerforselfoss.api.selfoss.Item import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi @@ -85,11 +88,19 @@ class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(con val newSize = apiItems.filter { it.unread }.size if (notifyNewItems && newSize > 0) { + + val intent = Intent(context, MainActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + } + val pendingIntent: PendingIntent = PendingIntent.getActivity(context, 0, intent, 0) + val newItemsNotification = NotificationCompat.Builder(applicationContext, Config.newItemsChannelId) .setContentTitle(context.getString(R.string.new_items_notification_title)) .setContentText(context.getString(R.string.new_items_notification_text, newSize)) .setPriority(PRIORITY_DEFAULT) .setChannelId(Config.newItemsChannelId) + .setContentIntent(pendingIntent) + .setAutoCancel(true) .setSmallIcon(R.drawable.ic_fiber_new_black_24dp) Timer("", false).schedule(4000) {