|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|