From 433f05aa2e8ec12ea87afe4c5d08649e644a1958 Mon Sep 17 00:00:00 2001 From: Federico Iosue Date: Sun, 12 Jan 2020 18:57:32 +0100 Subject: [PATCH] Fix notification err channel Pull request https://github.com/federicoiosue/Omni-Notes/pull/722/commits/28a9015b101e3eaa939bbe8e001237450c574a33 --- .../android/omninotes/utils/Constants.java | 3 +++ .../android/omninotes/utils/Constants.java | 3 +++ .../android/omninotes/utils/Constants.java | 4 ++++ .../omninotes/utils/ConstantsBase.java | 1 + .../notifications/NotificationChannel.java | 18 +++++++++------- .../notifications/NotificationChannels.java | 21 ++++++++++++------- .../notifications/NotificationsHelper.java | 5 +++-- .../android/omninotes/utils/Constants.java | 4 ++++ 8 files changed, 42 insertions(+), 17 deletions(-) diff --git a/omniNotes/src/alpha/java/it/feio/android/omninotes/utils/Constants.java b/omniNotes/src/alpha/java/it/feio/android/omninotes/utils/Constants.java index f21257a352..0e8fea4899 100644 --- a/omniNotes/src/alpha/java/it/feio/android/omninotes/utils/Constants.java +++ b/omniNotes/src/alpha/java/it/feio/android/omninotes/utils/Constants.java @@ -25,4 +25,7 @@ public interface Constants extends ConstantsBase { String PACKAGE = "it.feio.android.omninotes.alpha"; String PREFS_NAME = PACKAGE + "_preferences"; + String CHANNEL_BACKUPS_ID = PACKAGE + ".backups"; + String CHANNEL_REMINDERS_ID = PACKAGE + ".reminders"; + } diff --git a/omniNotes/src/beta/java/it/feio/android/omninotes/utils/Constants.java b/omniNotes/src/beta/java/it/feio/android/omninotes/utils/Constants.java index 492b9651dd..c4eb43499f 100644 --- a/omniNotes/src/beta/java/it/feio/android/omninotes/utils/Constants.java +++ b/omniNotes/src/beta/java/it/feio/android/omninotes/utils/Constants.java @@ -8,4 +8,7 @@ public interface Constants extends ConstantsBase { String PACKAGE = "it.feio.android.omninotes"; String PREFS_NAME = PACKAGE + "_preferences"; + String CHANNEL_BACKUPS_ID = PACKAGE + ".backups"; + String CHANNEL_REMINDERS_ID = PACKAGE + ".reminders"; + } diff --git a/omniNotes/src/foss/java/it/feio/android/omninotes/utils/Constants.java b/omniNotes/src/foss/java/it/feio/android/omninotes/utils/Constants.java index b4885d69e7..c6f470a854 100644 --- a/omniNotes/src/foss/java/it/feio/android/omninotes/utils/Constants.java +++ b/omniNotes/src/foss/java/it/feio/android/omninotes/utils/Constants.java @@ -22,4 +22,8 @@ public interface Constants extends ConstantsBase { String EXTERNAL_STORAGE_FOLDER = "Omni Notes Foss"; String PACKAGE = "it.feio.android.omninotes.foss"; String PREFS_NAME = PACKAGE + "_preferences"; + + String CHANNEL_BACKUPS_ID = PACKAGE + ".backups"; + String CHANNEL_REMINDERS_ID = PACKAGE + ".reminders"; + } diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java b/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java index 1984d32358..fa65e7e9fd 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java @@ -126,4 +126,5 @@ public interface ConstantsBase { String PROPERTIES_PARAMS_SEPARATOR = ","; String AUTO_BACKUP_DIR = "_autobackup"; + } diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationChannel.java b/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationChannel.java index cd9f308e5a..5519b85fb0 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationChannel.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationChannel.java @@ -19,13 +19,15 @@ public class NotificationChannel { - int importance; - String name; - String description; + int importance; + String name; + String description; + String id; - NotificationChannel (int importance, String name, String description) { - this.importance = importance; - this.name = name; - this.description = description; - } + NotificationChannel(int importance, String name, String description, String id) { + this.importance = importance; + this.name = name; + this.description = description; + this.id = id; + } } \ No newline at end of file diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationChannels.java b/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationChannels.java index a1708da8f4..b104789658 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationChannels.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationChannels.java @@ -17,9 +17,11 @@ package it.feio.android.omninotes.utils.notifications; -import static androidx.core.app.NotificationManagerCompat.IMPORTANCE_DEFAULT; +import static it.feio.android.omninotes.utils.ConstantsBase.CHANNEL_BACKUPS_ID; +import static it.feio.android.omninotes.utils.ConstantsBase.CHANNEL_REMINDERS_ID; import android.annotation.TargetApi; +import android.app.NotificationManager; import android.os.Build; import it.feio.android.omninotes.OmniNotes; import it.feio.android.omninotes.R; @@ -30,12 +32,16 @@ public class NotificationChannels { private static List channels = new ArrayList() {{ - add(new NotificationChannel(IMPORTANCE_DEFAULT, OmniNotes.getAppContext().getString(R.string - .channel_backups_name), OmniNotes.getAppContext().getString(R.string - .channel_backups_description))); - add(new NotificationChannel(IMPORTANCE_DEFAULT, OmniNotes.getAppContext().getString(R.string - .channel_reminders_name), OmniNotes.getAppContext().getString(R.string - .channel_reminders_description))); + add(new NotificationChannel( + NotificationManager.IMPORTANCE_DEFAULT, + OmniNotes.getAppContext().getString(R.string.channel_backups_name), + OmniNotes.getAppContext().getString(R.string.channel_backups_description), + CHANNEL_BACKUPS_ID)); + add(new NotificationChannel( + NotificationManager.IMPORTANCE_DEFAULT, + OmniNotes.getAppContext().getString(R.string.channel_reminders_name), + OmniNotes.getAppContext().getString(R.string.channel_reminders_description), + CHANNEL_REMINDERS_ID)); }}; public static List getChannels () { @@ -45,4 +51,5 @@ public static List getChannels () { public enum NotificationChannelNames { Backups, Reminders } + } diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationsHelper.java b/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationsHelper.java index ac4073a11e..f18f8a9b1b 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationsHelper.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/utils/notifications/NotificationsHelper.java @@ -53,9 +53,9 @@ public NotificationsHelper (Context mContext) { */ @TargetApi(Build.VERSION_CODES.O) public void initNotificationChannels () { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) { for (it.feio.android.omninotes.utils.notifications.NotificationChannel notificationChannel : NotificationChannels.getChannels()) { - NotificationChannel channel = new NotificationChannel(notificationChannel.name, notificationChannel + NotificationChannel channel = new NotificationChannel(notificationChannel.id, notificationChannel .name, notificationChannel.importance); channel.setDescription(notificationChannel.description); mNotificationManager.createNotificationChannel(channel); @@ -187,4 +187,5 @@ public void cancel () { public void cancel (int id) { mNotificationManager.cancel(id); } + } diff --git a/omniNotes/src/play/java/it/feio/android/omninotes/utils/Constants.java b/omniNotes/src/play/java/it/feio/android/omninotes/utils/Constants.java index a8165cdb47..2dd4f2a0f5 100644 --- a/omniNotes/src/play/java/it/feio/android/omninotes/utils/Constants.java +++ b/omniNotes/src/play/java/it/feio/android/omninotes/utils/Constants.java @@ -22,4 +22,8 @@ public interface Constants extends ConstantsBase { String EXTERNAL_STORAGE_FOLDER = "Omni Notes"; String PACKAGE = "it.feio.android.omninotes"; String PREFS_NAME = PACKAGE + "_preferences"; + + String CHANNEL_BACKUPS_ID = PACKAGE + ".backups"; + String CHANNEL_REMINDERS_ID = PACKAGE + ".reminders"; + }