diff --git a/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/IrcNotificationManager.java b/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/IrcNotificationManager.java
index ecaecd6..8d404d5 100644
--- a/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/IrcNotificationManager.java
+++ b/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/IrcNotificationManager.java
@@ -135,7 +135,6 @@ public void handle(Context context, IrcMessage msg) {
builder.setAutoCancel(true);
builder.setContentText(notificationMessage);
builder.setContentTitle(titleText);
- builder.setChannelId(NotificationChannelCreator.CHANNEL_ID);
if (currentUnreadCount > 1) {
builder.setNumber(currentUnreadCount);
@@ -151,9 +150,10 @@ public void handle(Context context, IrcMessage msg) {
}
}
- if ((!prefs.isSpamFilterEnabled() || new Date().getTime() > IrcNotificationManager
- .getInstance().getLastSoundDate()
- + (1000L * prefs.getSpamFilterTime()))) {
+ if ((!prefs.isSpamFilterEnabled() || new Date().getTime() > IrcNotificationManager.getInstance().getLastSoundDate() + (1000L * prefs.getSpamFilterTime()))) {
+ // no spam filter going on
+
+ // legacy, this stuff affects only pre-android 8 phones
if (prefs.isSoundEnabled()) {
builder.setSound(prefs.getNotificationSound());
}
@@ -163,6 +163,9 @@ public void handle(Context context, IrcMessage msg) {
}
lastSoundDate = new Date().getTime();
+ builder.setChannelId(NotificationChannelCreator.CHANNEL_DEFAULT_ID);
+ } else {
+ builder.setChannelId(NotificationChannelCreator.CHANNEL_LOWPRIO_ID);
}
builder.setDefaults(defaults);
diff --git a/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/IrssiNotifierActivity.java b/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/IrssiNotifierActivity.java
index 07dd8eb..01b82bf 100644
--- a/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/IrssiNotifierActivity.java
+++ b/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/IrssiNotifierActivity.java
@@ -97,7 +97,7 @@ public void onCreate(Bundle savedInstanceState) {
channelToView = savedInstanceState.getString("channelToView");
}
- NotificationChannelCreator.createNotificationChannel(this);
+ NotificationChannelCreator.createNotificationChannels(this);
IrcNotificationManager.getInstance().mainActivityOpened(this);
startMainApp(b);
diff --git a/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/NotificationChannelCreator.java b/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/NotificationChannelCreator.java
index b5cc979..4c0ccc8 100644
--- a/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/NotificationChannelCreator.java
+++ b/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/NotificationChannelCreator.java
@@ -3,42 +3,84 @@
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
+import android.content.Intent;
+import android.media.AudioAttributes;
import android.os.Build;
+import android.provider.Settings;
+import android.widget.Toast;
public class NotificationChannelCreator {
- public static final String CHANNEL_ID = "IrssiNotifierDefaultChannel";
+ public static final String CHANNEL_DEFAULT_ID = "IrssiNotifierDefaultChannel";
+ public static final String CHANNEL_LOWPRIO_ID = "IrssiNotifierLowPriorityChannel";
- public static void createNotificationChannel(Context ctx) {
+ public static void createNotificationChannels(Context ctx) {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- CharSequence name = "IrssiNotifier default";
- String description = "Default notifications from Irssi hilights.";
- int importance = NotificationManager.IMPORTANCE_HIGH;
- NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
- channel.setDescription(description);
-
- Preferences prefs = new Preferences(ctx);
- channel.enableLights(prefs.isLightsEnabled());
- channel.setLightColor(prefs.getCustomLightColor());
- channel.enableVibration(prefs.isVibrationEnabled());
-
- // Register the channel with the system; you can't change the importance
- // or other notification behaviors after this
- NotificationManager notificationManager = ctx.getSystemService(NotificationManager.class);
- notificationManager.createNotificationChannel(channel);
+ {
+ CharSequence name = "IrssiNotifier default";
+ String description = "Default notifications for Irssi hilights.";
+ int importance = NotificationManager.IMPORTANCE_DEFAULT;
+ NotificationChannel channel = new NotificationChannel(CHANNEL_DEFAULT_ID, name, importance);
+ channel.setDescription(description);
+
+ Preferences prefs = new Preferences(ctx);
+ channel.enableLights(prefs.isLightsEnabled());
+ channel.setLightColor(prefs.getCustomLightColor());
+ channel.enableVibration(prefs.isVibrationEnabled());
+
+ if (prefs.isSoundEnabled()) {
+ AudioAttributes att = new AudioAttributes.Builder()
+ .setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
+ .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
+ .build();
+ channel.setSound(prefs.getNotificationSound(), att);
+ } else {
+ channel.setSound(null, null);
+ }
+
+ // Register the channel with the system; you can't change the importance
+ // or other notification behaviors after this
+ NotificationManager notificationManager = ctx.getSystemService(NotificationManager.class);
+ notificationManager.createNotificationChannel(channel);
+ }
+
+ {
+ CharSequence name = "IrssiNotifier low priority";
+ String description = "Repeated hilights, you can set spam filter duration in app settings.";
+ int importance = NotificationManager.IMPORTANCE_LOW;
+ NotificationChannel channel = new NotificationChannel(CHANNEL_LOWPRIO_ID, name, importance);
+ channel.setDescription(description);
+
+ NotificationManager notificationManager = ctx.getSystemService(NotificationManager.class);
+ notificationManager.createNotificationChannel(channel);
+ }
}
}
- private static void deleteNotificationChannel(Context ctx) {
+ private static void deleteNotificationChannels(Context ctx) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = ctx.getSystemService(NotificationManager.class);
- notificationManager.deleteNotificationChannel(CHANNEL_ID);
+ notificationManager.deleteNotificationChannel(CHANNEL_DEFAULT_ID);
+ notificationManager.deleteNotificationChannel(CHANNEL_LOWPRIO_ID);
}
}
public static void recreateNotificationChannel(Context ctx) {
- deleteNotificationChannel(ctx);
- createNotificationChannel(ctx);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ deleteNotificationChannels(ctx);
+ createNotificationChannels(ctx);
+
+ Toast.makeText(ctx, "Notification Channel settings applied", Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ public static void openNotificationChannelSettings(Context ctx) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
+ intent.putExtra(Settings.EXTRA_APP_PACKAGE, ctx.getPackageName());
+ intent.putExtra(Settings.EXTRA_CHANNEL_ID, CHANNEL_DEFAULT_ID);
+ ctx.startActivity(intent);
+ }
}
}
diff --git a/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/Preferences.java b/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/Preferences.java
index 72a94f1..1cd12ad 100644
--- a/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/Preferences.java
+++ b/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/Preferences.java
@@ -147,14 +147,11 @@ public boolean isSoundEnabled() {
}
public boolean isSpamFilterEnabled() {
- long time = Long.parseLong(sharedPreferences.getString(
- SPAM_FILTER_TIME, "-1"));
- return time >= 0;
+ return getSpamFilterTime() >= 0;
}
public long getSpamFilterTime() {
- return Long.parseLong(sharedPreferences.getString(SPAM_FILTER_TIME,
- "-1"));
+ return Long.parseLong(sharedPreferences.getString(SPAM_FILTER_TIME, "60"));
}
public boolean isNotificationsEnabled() {
@@ -256,6 +253,6 @@ public boolean isPullMechanismInUse() {
}
public boolean isPebbleEnabled() {
- return sharedPreferences.getBoolean(PEBBLE_ENABLED, true);
+ return sharedPreferences.getBoolean(PEBBLE_ENABLED, false);
}
}
diff --git a/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/SettingsActivity.java b/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/SettingsActivity.java
index 374830a..a23020b 100644
--- a/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/SettingsActivity.java
+++ b/Android/mobile/src/main/java/fi/iki/murgo/irssinotifier/SettingsActivity.java
@@ -109,6 +109,22 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
});
+ Preference openNotificationChannelSettings = findPreference("openNotificationChannelSettings");
+ openNotificationChannelSettings.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
+ NotificationChannelCreator.openNotificationChannelSettings(SettingsActivity.this);
+ return true;
+ }
+ });
+
+ Preference applyNotificationSettings = findPreference("applyNotificationSettings");
+ applyNotificationSettings.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
+ NotificationChannelCreator.recreateNotificationChannel(SettingsActivity.this);
+ return true;
+ }
+ });
+
Preference initialSettingsPref = findPreference("redoInitialSettings");
initialSettingsPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
diff --git a/Android/mobile/src/main/res/xml/preference_screen.xml b/Android/mobile/src/main/res/xml/preference_screen.xml
index af79546..11ddc83 100644
--- a/Android/mobile/src/main/res/xml/preference_screen.xml
+++ b/Android/mobile/src/main/res/xml/preference_screen.xml
@@ -42,6 +42,10 @@
+
+
+ android:defaultValue="false"
+ android:key="PebbleEnabled"
+ android:title="Send notifications to Pebble" />