Browse Source

Pass notification vibrate/light/sound settings to channel to fix #548

pull/565/head
Eric Kok 4 years ago
parent
commit
1149e0ae16
  1. 6
      app/src/main/java/org/transdroid/core/service/AppUpdateJob.java
  2. 21
      app/src/main/java/org/transdroid/core/service/NotificationChannels.java
  3. 2
      app/src/main/java/org/transdroid/core/service/RssCheckerJob.java
  4. 2
      app/src/main/java/org/transdroid/core/service/ServerCheckerJob.java

6
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.Job;
import com.evernote.android.job.JobManager; import com.evernote.android.job.JobManager;
import com.evernote.android.job.JobRequest; 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.app.settings.SystemSettings_; import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.gui.log.Log_; import org.transdroid.core.gui.log.Log_;
@ -35,11 +38,12 @@ public class AppUpdateJob extends Job {
private static Integer scheduledJobId; private static Integer scheduledJobId;
public static void schedule(Context context) { public static void schedule(Context context) {
NotificationSettings notificationSettings = NotificationSettings_.getInstance_(context);
SystemSettings systemSettings = SystemSettings_.getInstance_(context); SystemSettings systemSettings = SystemSettings_.getInstance_(context);
NavigationHelper_ navigationHelper = NavigationHelper_.getInstance_(context); NavigationHelper_ navigationHelper = NavigationHelper_.getInstance_(context);
if (systemSettings.checkForUpdates() && navigationHelper.enableUpdateChecker()) { if (systemSettings.checkForUpdates() && navigationHelper.enableUpdateChecker()) {
Log_.getInstance_(context).d(TAG, "Schedule app update checker job"); Log_.getInstance_(context).d(TAG, "Schedule app update checker job");
NotificationChannels.ensureAppUpdateChannel(context); NotificationChannels.ensureAppUpdateChannel(context, notificationSettings);
scheduledJobId = new JobRequest.Builder(AppUpdateJob.TAG) scheduledJobId = new JobRequest.Builder(AppUpdateJob.TAG)
.setPeriodic(TimeUnit.DAYS.toMillis(1)) .setPeriodic(TimeUnit.DAYS.toMillis(1))
.setRequiredNetworkType(JobRequest.NetworkType.CONNECTED) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)

21
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.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.media.AudioAttributes;
import android.os.Build; import android.os.Build;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.core.app.settings.NotificationSettings;
class NotificationChannels { class NotificationChannels {
@ -13,23 +15,24 @@ class NotificationChannels {
public static final String CHANNEL_RSS_CHECKER = "channel_rss_checker"; public static final String CHANNEL_RSS_CHECKER = "channel_rss_checker";
public static final String CHANNEL_SERVER_CHECKER = "channel_server_checker"; public static final String CHANNEL_SERVER_CHECKER = "channel_server_checker";
static void ensureAppUpdateChannel(final Context context) { static void ensureAppUpdateChannel(final Context context, NotificationSettings notificationSettings) {
createChannel(context, CHANNEL_APP_UPDATE, R.string.pref_checkupdates, R.string.pref_checkupdates_info); createChannel(context, CHANNEL_APP_UPDATE, R.string.pref_checkupdates, R.string.pref_checkupdates_info, notificationSettings);
} }
static void ensureRssCheckerChannel(final Context context) { static void ensureRssCheckerChannel(final Context context, NotificationSettings notificationSettings) {
createChannel(context, CHANNEL_RSS_CHECKER, R.string.pref_notifications_rss, null); createChannel(context, CHANNEL_RSS_CHECKER, R.string.pref_notifications_rss, null, notificationSettings);
} }
static void ensureServerCheckerChannel(final Context context) { static void ensureServerCheckerChannel(final Context context, NotificationSettings notificationSettings) {
createChannel(context, CHANNEL_SERVER_CHECKER, R.string.pref_notifications_torrent, null); createChannel(context, CHANNEL_SERVER_CHECKER, R.string.pref_notifications_torrent, null, notificationSettings);
} }
private static void createChannel( private static void createChannel(
final Context context, final Context context,
final String channelId, final String channelId,
final int name, final int name,
final Integer description) { final Integer description,
final NotificationSettings notificationSettings) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_DEFAULT; int importance = NotificationManager.IMPORTANCE_DEFAULT;
@ -37,6 +40,10 @@ class NotificationChannels {
if (description != null) { if (description != null) {
channel.setDescription(context.getString(description)); 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); final NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(channel);
} }

2
app/src/main/java/org/transdroid/core/service/RssCheckerJob.java

@ -40,7 +40,7 @@ public class RssCheckerJob extends Job {
NotificationSettings notificationSettings = NotificationSettings_.getInstance_(context); NotificationSettings notificationSettings = NotificationSettings_.getInstance_(context);
if (notificationSettings.isEnabledForRss()) { if (notificationSettings.isEnabledForRss()) {
Log_.getInstance_(context).d(TAG, "Schedule rss checker job"); Log_.getInstance_(context).d(TAG, "Schedule rss checker job");
NotificationChannels.ensureRssCheckerChannel(context); NotificationChannels.ensureRssCheckerChannel(context, notificationSettings);
scheduledJobId = new JobRequest.Builder(RssCheckerJob.TAG) scheduledJobId = new JobRequest.Builder(RssCheckerJob.TAG)
.setPeriodic(notificationSettings.getInvervalInMilliseconds()) .setPeriodic(notificationSettings.getInvervalInMilliseconds())
.setRequiredNetworkType(JobRequest.NetworkType.CONNECTED) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)

2
app/src/main/java/org/transdroid/core/service/ServerCheckerJob.java

@ -35,7 +35,7 @@ public class ServerCheckerJob extends Job {
NotificationSettings notificationSettings = NotificationSettings_.getInstance_(context); NotificationSettings notificationSettings = NotificationSettings_.getInstance_(context);
if (notificationSettings.isEnabledForTorrents()) { if (notificationSettings.isEnabledForTorrents()) {
Log_.getInstance_(context).d(TAG, "Schedule server checker job"); Log_.getInstance_(context).d(TAG, "Schedule server checker job");
NotificationChannels.ensureServerCheckerChannel(context); NotificationChannels.ensureServerCheckerChannel(context, notificationSettings);
scheduledJobId = new JobRequest.Builder(ServerCheckerJob.TAG) scheduledJobId = new JobRequest.Builder(ServerCheckerJob.TAG)
.setPeriodic(notificationSettings.getInvervalInMilliseconds()) .setPeriodic(notificationSettings.getInvervalInMilliseconds())
.setRequiredNetworkType(JobRequest.NetworkType.CONNECTED) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)

Loading…
Cancel
Save