From 40be73bd9b27c2e672c04feb26b85a6ee65daf55 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 6 Oct 2022 10:25:36 +0200 Subject: [PATCH] Fix issue #342 --- .../android/jobs/NotificationsWorker.java | 25 +++++++++++++++++++ .../android/jobs/ScheduleBoostWorker.java | 25 +++++++++++++++++++ .../android/jobs/ScheduleThreadWorker.java | 24 ++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/app/src/main/java/app/fedilab/android/jobs/NotificationsWorker.java b/app/src/main/java/app/fedilab/android/jobs/NotificationsWorker.java index a84d9c7a..7b773592 100644 --- a/app/src/main/java/app/fedilab/android/jobs/NotificationsWorker.java +++ b/app/src/main/java/app/fedilab/android/jobs/NotificationsWorker.java @@ -28,6 +28,9 @@ import androidx.work.ForegroundInfo; import androidx.work.Worker; import androidx.work.WorkerParameters; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; + import java.util.List; import app.fedilab.android.R; @@ -47,6 +50,28 @@ public class NotificationsWorker extends Worker { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } + + @NonNull + @Override + public ListenableFuture getForegroundInfoAsync() { + if (Build.VERSION.SDK_INT >= 26) { + String channelName = "Notification"; + String channelDescription = "Fetched notifications"; + NotificationChannel notifChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH); + notifChannel.setDescription(channelDescription); + notificationManager.createNotificationChannel(notifChannel); + + } + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID); + notificationBuilder.setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher_foreground)) + .setContentTitle(getApplicationContext().getString(R.string.scheduled_toots)) + .setContentText(getApplicationContext().getString(R.string.scheduled_toots)) + .setDefaults(NotificationCompat.DEFAULT_ALL) + .setPriority(Notification.PRIORITY_DEFAULT); + return Futures.immediateFuture(new ForegroundInfo(FETCH_NOTIFICATION_CHANNEL_ID, notificationBuilder.build())); + } + @NonNull private ForegroundInfo createForegroundInfo() { if (Build.VERSION.SDK_INT >= 26) { diff --git a/app/src/main/java/app/fedilab/android/jobs/ScheduleBoostWorker.java b/app/src/main/java/app/fedilab/android/jobs/ScheduleBoostWorker.java index ee6c077c..bf7fe38f 100644 --- a/app/src/main/java/app/fedilab/android/jobs/ScheduleBoostWorker.java +++ b/app/src/main/java/app/fedilab/android/jobs/ScheduleBoostWorker.java @@ -28,6 +28,9 @@ import androidx.work.ForegroundInfo; import androidx.work.Worker; import androidx.work.WorkerParameters; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; + import java.io.IOException; import java.util.concurrent.TimeUnit; @@ -54,6 +57,28 @@ public class ScheduleBoostWorker extends Worker { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } + + @NonNull + @Override + public ListenableFuture getForegroundInfoAsync() { + if (Build.VERSION.SDK_INT >= 26) { + String channelName = "Boost messages"; + String channelDescription = "Schedule boosts channel"; + NotificationChannel notifChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH); + notifChannel.setDescription(channelDescription); + notificationManager.createNotificationChannel(notifChannel); + + } + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID); + notificationBuilder.setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher_foreground)) + .setContentTitle(getApplicationContext().getString(R.string.schedule_boost)) + .setContentText(getApplicationContext().getString(R.string.schedule_boost)) + .setDefaults(NotificationCompat.DEFAULT_ALL) + .setPriority(Notification.PRIORITY_DEFAULT); + return Futures.immediateFuture(new ForegroundInfo(NOTIFICATION_INT_CHANNEL_ID, notificationBuilder.build())); + } + @NonNull private ForegroundInfo createForegroundInfo() { if (Build.VERSION.SDK_INT >= 26) { diff --git a/app/src/main/java/app/fedilab/android/jobs/ScheduleThreadWorker.java b/app/src/main/java/app/fedilab/android/jobs/ScheduleThreadWorker.java index 741eb49a..e348f928 100644 --- a/app/src/main/java/app/fedilab/android/jobs/ScheduleThreadWorker.java +++ b/app/src/main/java/app/fedilab/android/jobs/ScheduleThreadWorker.java @@ -29,6 +29,9 @@ import androidx.work.ForegroundInfo; import androidx.work.Worker; import androidx.work.WorkerParameters; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; + import app.fedilab.android.R; import app.fedilab.android.client.entities.app.StatusDraft; import app.fedilab.android.exception.DBException; @@ -45,6 +48,27 @@ public class ScheduleThreadWorker extends Worker { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } + @NonNull + @Override + public ListenableFuture getForegroundInfoAsync() { + if (Build.VERSION.SDK_INT >= 26) { + String channelName = "Scheduled threads"; + String channelDescription = "Scheduled threads channel"; + NotificationChannel notifChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH); + notifChannel.setDescription(channelDescription); + notificationManager.createNotificationChannel(notifChannel); + + } + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID); + notificationBuilder.setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher_foreground)) + .setContentTitle(getApplicationContext().getString(R.string.scheduled_toots)) + .setContentText(getApplicationContext().getString(R.string.scheduled_toots)) + .setDefaults(NotificationCompat.DEFAULT_ALL) + .setPriority(Notification.PRIORITY_DEFAULT); + return Futures.immediateFuture(new ForegroundInfo(NOTIFICATION_INT_CHANNEL_ID, notificationBuilder.build())); + } + @NonNull private ForegroundInfo createForegroundInfo() { if (Build.VERSION.SDK_INT >= 26) {