From 17f5a5d1b85f07bada36abe6541ed0fc1e1d83a2 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 17 Mar 2024 12:06:41 +0100 Subject: Move notification icons and widget icons to separate modules (#6995) --- .../ui/notifications/NotificationUtils.java | 118 +++++++++++++++++++++ .../res/drawable/ic_notification_fast_forward.xml | 5 + .../res/drawable/ic_notification_fast_rewind.xml | 5 + .../res/drawable/ic_notification_next_chapter.xml | 7 ++ .../main/res/drawable/ic_notification_pause.xml | 5 + .../src/main/res/drawable/ic_notification_play.xml | 5 + .../drawable/ic_notification_playback_speed.xml | 8 ++ .../src/main/res/drawable/ic_notification_skip.xml | 5 + .../main/res/drawable/ic_notification_sleep.xml | 5 + .../res/drawable/ic_notification_sleep_off.xml | 5 + .../main/res/drawable/ic_notification_stream.xml | 14 +++ .../src/main/res/drawable/ic_notification_sync.xml | 5 + .../res/drawable/ic_notification_sync_error.xml | 5 + 13 files changed, 192 insertions(+) create mode 100644 ui/notifications/src/main/java/de/danoeh/antennapod/ui/notifications/NotificationUtils.java create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_fast_forward.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_fast_rewind.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_next_chapter.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_pause.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_play.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_playback_speed.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_skip.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_sleep.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_sleep_off.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_stream.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_sync.xml create mode 100644 ui/notifications/src/main/res/drawable/ic_notification_sync_error.xml (limited to 'ui/notifications/src') diff --git a/ui/notifications/src/main/java/de/danoeh/antennapod/ui/notifications/NotificationUtils.java b/ui/notifications/src/main/java/de/danoeh/antennapod/ui/notifications/NotificationUtils.java new file mode 100644 index 000000000..93cf6baf1 --- /dev/null +++ b/ui/notifications/src/main/java/de/danoeh/antennapod/ui/notifications/NotificationUtils.java @@ -0,0 +1,118 @@ +package de.danoeh.antennapod.ui.notifications; + +import android.content.Context; + +import androidx.core.app.NotificationChannelCompat; +import androidx.core.app.NotificationChannelGroupCompat; +import androidx.core.app.NotificationManagerCompat; + +import java.util.Arrays; +import java.util.List; + +import de.danoeh.antennapod.storage.preferences.UserPreferences; + +public class NotificationUtils { + public static final String CHANNEL_ID_USER_ACTION = "user_action"; + public static final String CHANNEL_ID_DOWNLOADING = "downloading"; + public static final String CHANNEL_ID_PLAYING = "playing"; + public static final String CHANNEL_ID_DOWNLOAD_ERROR = "error"; + public static final String CHANNEL_ID_SYNC_ERROR = "sync_error"; + public static final String CHANNEL_ID_EPISODE_NOTIFICATIONS = "episode_notifications"; + + public static final String GROUP_ID_ERRORS = "group_errors"; + public static final String GROUP_ID_NEWS = "group_news"; + + public static void createChannels(final Context context) { + final NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context); + + final List channelGroups = Arrays.asList( + createGroupErrors(context), + createGroupNews(context)); + mNotificationManager.createNotificationChannelGroupsCompat(channelGroups); + + final List channels = Arrays.asList( + createChannelUserAction(context), + createChannelDownloading(context), + createChannelPlaying(context), + createChannelError(context), + createChannelSyncError(context), + createChannelEpisodeNotification(context)); + mNotificationManager.createNotificationChannelsCompat(channels); + } + + private static NotificationChannelCompat createChannelUserAction(final Context c) { + return new NotificationChannelCompat.Builder( + CHANNEL_ID_USER_ACTION, NotificationManagerCompat.IMPORTANCE_HIGH) + .setName(c.getString(R.string.notification_channel_user_action)) + .setDescription(c.getString(R.string.notification_channel_user_action_description)) + .setGroup(GROUP_ID_ERRORS) + .build(); + } + + private static NotificationChannelCompat createChannelDownloading(final Context c) { + return new NotificationChannelCompat.Builder( + CHANNEL_ID_DOWNLOADING, NotificationManagerCompat.IMPORTANCE_LOW) + .setName(c.getString(R.string.notification_channel_downloading)) + .setDescription(c.getString(R.string.notification_channel_downloading_description)) + .setShowBadge(false) + .build(); + } + + private static NotificationChannelCompat createChannelPlaying(final Context c) { + return new NotificationChannelCompat.Builder( + CHANNEL_ID_PLAYING, NotificationManagerCompat.IMPORTANCE_LOW) + .setName(c.getString(R.string.notification_channel_playing)) + .setDescription(c.getString(R.string.notification_channel_playing_description)) + .setShowBadge(false) + .build(); + } + + private static NotificationChannelCompat createChannelError(final Context c) { + final NotificationChannelCompat.Builder notificationChannel = new NotificationChannelCompat.Builder( + CHANNEL_ID_DOWNLOAD_ERROR, NotificationManagerCompat.IMPORTANCE_HIGH) + .setName(c.getString(R.string.notification_channel_download_error)) + .setDescription(c.getString(R.string.notification_channel_download_error_description)) + .setGroup(GROUP_ID_ERRORS); + + if (!UserPreferences.getShowDownloadReportRaw()) { + // Migration from app managed setting: disable notification + notificationChannel.setImportance(NotificationManagerCompat.IMPORTANCE_NONE); + } + return notificationChannel.build(); + } + + private static NotificationChannelCompat createChannelSyncError(final Context c) { + final NotificationChannelCompat.Builder notificationChannel = new NotificationChannelCompat.Builder( + CHANNEL_ID_SYNC_ERROR, NotificationManagerCompat.IMPORTANCE_HIGH) + .setName(c.getString(R.string.notification_channel_sync_error)) + .setDescription(c.getString(R.string.notification_channel_sync_error_description)) + .setGroup(GROUP_ID_ERRORS); + + if (!UserPreferences.getGpodnetNotificationsEnabledRaw()) { + // Migration from app managed setting: disable notification + notificationChannel.setImportance(NotificationManagerCompat.IMPORTANCE_NONE); + } + return notificationChannel.build(); + } + + private static NotificationChannelCompat createChannelEpisodeNotification(final Context c) { + return new NotificationChannelCompat.Builder( + CHANNEL_ID_EPISODE_NOTIFICATIONS, NotificationManagerCompat.IMPORTANCE_DEFAULT) + .setName(c.getString(R.string.notification_channel_new_episode)) + .setDescription(c.getString(R.string.notification_channel_new_episode_description)) + .setGroup(GROUP_ID_NEWS) + .build(); + } + + private static NotificationChannelGroupCompat createGroupErrors(final Context c) { + return new NotificationChannelGroupCompat.Builder(GROUP_ID_ERRORS) + .setName(c.getString(R.string.notification_group_errors)) + .build(); + } + + private static NotificationChannelGroupCompat createGroupNews(final Context c) { + return new NotificationChannelGroupCompat.Builder(GROUP_ID_NEWS) + .setName(c.getString(R.string.notification_group_news)) + .build(); + } +} diff --git a/ui/notifications/src/main/res/drawable/ic_notification_fast_forward.xml b/ui/notifications/src/main/res/drawable/ic_notification_fast_forward.xml new file mode 100644 index 000000000..8ee82f4ed --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_fast_forward.xml @@ -0,0 +1,5 @@ + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_fast_rewind.xml b/ui/notifications/src/main/res/drawable/ic_notification_fast_rewind.xml new file mode 100644 index 000000000..261ed7e6f --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_fast_rewind.xml @@ -0,0 +1,5 @@ + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_next_chapter.xml b/ui/notifications/src/main/res/drawable/ic_notification_next_chapter.xml new file mode 100644 index 000000000..cb55e93a9 --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_next_chapter.xml @@ -0,0 +1,7 @@ + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_pause.xml b/ui/notifications/src/main/res/drawable/ic_notification_pause.xml new file mode 100644 index 000000000..16ebd4eab --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_pause.xml @@ -0,0 +1,5 @@ + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_play.xml b/ui/notifications/src/main/res/drawable/ic_notification_play.xml new file mode 100644 index 000000000..eb4acd983 --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_play.xml @@ -0,0 +1,5 @@ + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_playback_speed.xml b/ui/notifications/src/main/res/drawable/ic_notification_playback_speed.xml new file mode 100644 index 000000000..5aad5031a --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_playback_speed.xml @@ -0,0 +1,8 @@ + + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_skip.xml b/ui/notifications/src/main/res/drawable/ic_notification_skip.xml new file mode 100644 index 000000000..6bf03002a --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_skip.xml @@ -0,0 +1,5 @@ + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_sleep.xml b/ui/notifications/src/main/res/drawable/ic_notification_sleep.xml new file mode 100644 index 000000000..60cfbb616 --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_sleep.xml @@ -0,0 +1,5 @@ + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_sleep_off.xml b/ui/notifications/src/main/res/drawable/ic_notification_sleep_off.xml new file mode 100644 index 000000000..8cb32124b --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_sleep_off.xml @@ -0,0 +1,5 @@ + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_stream.xml b/ui/notifications/src/main/res/drawable/ic_notification_stream.xml new file mode 100644 index 000000000..aca761365 --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_stream.xml @@ -0,0 +1,14 @@ + + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_sync.xml b/ui/notifications/src/main/res/drawable/ic_notification_sync.xml new file mode 100644 index 000000000..c42a78d7d --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_sync.xml @@ -0,0 +1,5 @@ + + + diff --git a/ui/notifications/src/main/res/drawable/ic_notification_sync_error.xml b/ui/notifications/src/main/res/drawable/ic_notification_sync_error.xml new file mode 100644 index 000000000..b5be1b747 --- /dev/null +++ b/ui/notifications/src/main/res/drawable/ic_notification_sync_error.xml @@ -0,0 +1,5 @@ + + + -- cgit v1.2.3