From 1149e0ae16782c1a16f5ed27fda8f3d577706327 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Thu, 9 Jul 2020 16:24:46 +0200 Subject: [PATCH] Pass notification vibrate/light/sound settings to channel to fix #548 --- .../transdroid/core/service/AppUpdateJob.java | 6 +++++- .../core/service/NotificationChannels.java | 21 ++++++++++++------- .../core/service/RssCheckerJob.java | 2 +- .../core/service/ServerCheckerJob.java | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/service/AppUpdateJob.java b/app/src/main/java/org/transdroid/core/service/AppUpdateJob.java index cf50c4c7..b3c97011 100644 --- a/app/src/main/java/org/transdroid/core/service/AppUpdateJob.java +++ b/app/src/main/java/org/transdroid/core/service/AppUpdateJob.java @@ -21,6 +21,9 @@ import androidx.annotation.NonNull; import com.evernote.android.job.Job; import com.evernote.android.job.JobManager; import com.evernote.android.job.JobRequest; + +import org.transdroid.core.app.settings.NotificationSettings; +import org.transdroid.core.app.settings.NotificationSettings_; import org.transdroid.core.app.settings.SystemSettings; import org.transdroid.core.app.settings.SystemSettings_; import org.transdroid.core.gui.log.Log_; @@ -35,11 +38,12 @@ public class AppUpdateJob extends Job { private static Integer scheduledJobId; public static void schedule(Context context) { + NotificationSettings notificationSettings = NotificationSettings_.getInstance_(context); SystemSettings systemSettings = SystemSettings_.getInstance_(context); NavigationHelper_ navigationHelper = NavigationHelper_.getInstance_(context); if (systemSettings.checkForUpdates() && navigationHelper.enableUpdateChecker()) { Log_.getInstance_(context).d(TAG, "Schedule app update checker job"); - NotificationChannels.ensureAppUpdateChannel(context); + NotificationChannels.ensureAppUpdateChannel(context, notificationSettings); scheduledJobId = new JobRequest.Builder(AppUpdateJob.TAG) .setPeriodic(TimeUnit.DAYS.toMillis(1)) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED) diff --git a/app/src/main/java/org/transdroid/core/service/NotificationChannels.java b/app/src/main/java/org/transdroid/core/service/NotificationChannels.java index 5f19d810..d8389069 100644 --- a/app/src/main/java/org/transdroid/core/service/NotificationChannels.java +++ b/app/src/main/java/org/transdroid/core/service/NotificationChannels.java @@ -3,9 +3,11 @@ package org.transdroid.core.service; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; +import android.media.AudioAttributes; import android.os.Build; import org.transdroid.R; +import org.transdroid.core.app.settings.NotificationSettings; class NotificationChannels { @@ -13,23 +15,24 @@ class NotificationChannels { public static final String CHANNEL_RSS_CHECKER = "channel_rss_checker"; public static final String CHANNEL_SERVER_CHECKER = "channel_server_checker"; - static void ensureAppUpdateChannel(final Context context) { - createChannel(context, CHANNEL_APP_UPDATE, R.string.pref_checkupdates, R.string.pref_checkupdates_info); + static void ensureAppUpdateChannel(final Context context, NotificationSettings notificationSettings) { + createChannel(context, CHANNEL_APP_UPDATE, R.string.pref_checkupdates, R.string.pref_checkupdates_info, notificationSettings); } - static void ensureRssCheckerChannel(final Context context) { - createChannel(context, CHANNEL_RSS_CHECKER, R.string.pref_notifications_rss, null); + static void ensureRssCheckerChannel(final Context context, NotificationSettings notificationSettings) { + createChannel(context, CHANNEL_RSS_CHECKER, R.string.pref_notifications_rss, null, notificationSettings); } - static void ensureServerCheckerChannel(final Context context) { - createChannel(context, CHANNEL_SERVER_CHECKER, R.string.pref_notifications_torrent, null); + static void ensureServerCheckerChannel(final Context context, NotificationSettings notificationSettings) { + createChannel(context, CHANNEL_SERVER_CHECKER, R.string.pref_notifications_torrent, null, notificationSettings); } private static void createChannel( final Context context, final String channelId, final int name, - final Integer description) { + final Integer description, + final NotificationSettings notificationSettings) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { int importance = NotificationManager.IMPORTANCE_DEFAULT; @@ -37,6 +40,10 @@ class NotificationChannels { if (description != null) { channel.setDescription(context.getString(description)); } + channel.setLightColor(notificationSettings.getDesiredLedColour()); + channel.setSound(notificationSettings.getSound(), new AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_NOTIFICATION).setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build()); + channel.setVibrationPattern(notificationSettings.getDefaultVibratePattern()); final NotificationManager notificationManager = context.getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); } diff --git a/app/src/main/java/org/transdroid/core/service/RssCheckerJob.java b/app/src/main/java/org/transdroid/core/service/RssCheckerJob.java index 066ce99a..8412e998 100644 --- a/app/src/main/java/org/transdroid/core/service/RssCheckerJob.java +++ b/app/src/main/java/org/transdroid/core/service/RssCheckerJob.java @@ -40,7 +40,7 @@ public class RssCheckerJob extends Job { NotificationSettings notificationSettings = NotificationSettings_.getInstance_(context); if (notificationSettings.isEnabledForRss()) { Log_.getInstance_(context).d(TAG, "Schedule rss checker job"); - NotificationChannels.ensureRssCheckerChannel(context); + NotificationChannels.ensureRssCheckerChannel(context, notificationSettings); scheduledJobId = new JobRequest.Builder(RssCheckerJob.TAG) .setPeriodic(notificationSettings.getInvervalInMilliseconds()) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED) diff --git a/app/src/main/java/org/transdroid/core/service/ServerCheckerJob.java b/app/src/main/java/org/transdroid/core/service/ServerCheckerJob.java index 218bc129..346c2ca1 100644 --- a/app/src/main/java/org/transdroid/core/service/ServerCheckerJob.java +++ b/app/src/main/java/org/transdroid/core/service/ServerCheckerJob.java @@ -35,7 +35,7 @@ public class ServerCheckerJob extends Job { NotificationSettings notificationSettings = NotificationSettings_.getInstance_(context); if (notificationSettings.isEnabledForTorrents()) { Log_.getInstance_(context).d(TAG, "Schedule server checker job"); - NotificationChannels.ensureServerCheckerChannel(context); + NotificationChannels.ensureServerCheckerChannel(context, notificationSettings); scheduledJobId = new JobRequest.Builder(ServerCheckerJob.TAG) .setPeriodic(notificationSettings.getInvervalInMilliseconds()) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)