diff options
Diffstat (limited to 'core/src/main/java/de/danoeh/antennapod')
12 files changed, 116 insertions, 73 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/DBTasksCallbacks.java b/core/src/main/java/de/danoeh/antennapod/core/DBTasksCallbacks.java deleted file mode 100644 index 11a6b2c9f..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/DBTasksCallbacks.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.danoeh.antennapod.core; - -import de.danoeh.antennapod.core.storage.AutomaticDownloadAlgorithm; -import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm; - -/** - * Callbacks for the DBTasks class of the storage module. - */ -public interface DBTasksCallbacks { - - /** - * Returns the client's implementation of the AutomaticDownloadAlgorithm interface. - */ - AutomaticDownloadAlgorithm getAutomaticDownloadAlgorithm(); - - /** - * Returns the client's implementation of the EpisodeCacheCleanupAlgorithm interface. - */ - EpisodeCleanupAlgorithm getEpisodeCacheCleanupAlgorithm(); -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java b/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java index ad3fb8d42..ae9b47629 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java @@ -37,7 +37,7 @@ public interface DownloadServiceCallbacks { * <p/> * The PendingIntent takes users to an activity where they can look at all successful and failed downloads. * - * @return A non-null PendingIntent for the notification or null if shouldCreateReport()==false + * @return A non-null PendingIntent for the notification */ PendingIntent getReportNotificationContentIntent(Context context); @@ -47,14 +47,8 @@ public interface DownloadServiceCallbacks { * <p/> * The PendingIntent takes users to an activity where they can look at their episode queue. * - * @return A non-null PendingIntent for the notification or null if shouldCreateReport()==false + * @return A non-null PendingIntent for the notification */ PendingIntent getAutoDownloadReportNotificationContentIntent(Context context); - - /** - * Returns true if the DownloadService should create a report that shows the number of failed - * downloads when the service shuts down. - */ - boolean shouldCreateReport(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/PlaybackServiceCallbacks.java b/core/src/main/java/de/danoeh/antennapod/core/PlaybackServiceCallbacks.java index 194ee65ae..3dcaac4dc 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/PlaybackServiceCallbacks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/PlaybackServiceCallbacks.java @@ -19,11 +19,4 @@ public interface PlaybackServiceCallbacks { * @return A non-null activity intent. */ Intent getPlayerActivityIntent(Context context, MediaType mediaType, boolean remotePlayback); - - /** - * Returns true if the PlaybackService should load new episodes from the queue when playback ends - * and false if the PlaybackService should ignore the queue and load no more episodes when playback - * finishes. - */ - boolean useQueue(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java index 88945b930..4857e899d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java @@ -5,6 +5,7 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.database.Cursor; import android.media.MediaMetadataRetriever; +import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; import androidx.annotation.Nullable; @@ -165,13 +166,20 @@ public class FeedMedia extends FeedFile implements Playable { */ public MediaBrowserCompat.MediaItem getMediaItem() { Playable p = this; - MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() + MediaDescriptionCompat.Builder builder = new MediaDescriptionCompat.Builder() .setMediaId(String.valueOf(id)) .setTitle(p.getEpisodeTitle()) .setDescription(p.getFeedTitle()) - .setSubtitle(p.getFeedTitle()) - .build(); - return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_PLAYABLE); + .setSubtitle(p.getFeedTitle()); + if (item != null) { + // getImageLocation() also loads embedded images, which we can not send to external devices + if (item.getImageUrl() != null) { + builder.setIconUri(Uri.parse(item.getImageUrl())); + } else if (item.getFeed() != null && item.getFeed().getImageLocation() != null) { + builder.setIconUri(Uri.parse(item.getFeed().getImageLocation())); + } + } + return new MediaBrowserCompat.MediaItem(builder.build(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE); } /** diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 56dd95fe6..ed9c519a6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -301,10 +301,30 @@ public class UserPreferences { * @return {@code true} if download reports are shown, {@code false} otherwise */ public static boolean showDownloadReport() { + if (Build.VERSION.SDK_INT >= 26) { + return true; // System handles notification preferences + } + return prefs.getBoolean(PREF_SHOW_DOWNLOAD_REPORT, true); + } + + /** + * Used for migration of the preference to system notification channels. + */ + public static boolean getShowDownloadReportRaw() { return prefs.getBoolean(PREF_SHOW_DOWNLOAD_REPORT, true); } public static boolean showAutoDownloadReport() { + if (Build.VERSION.SDK_INT >= 26) { + return true; // System handles notification preferences + } + return prefs.getBoolean(PREF_SHOW_AUTO_DOWNLOAD_REPORT, false); + } + + /** + * Used for migration of the preference to system notification channels. + */ + public static boolean getShowAutoDownloadReportRaw() { return prefs.getBoolean(PREF_SHOW_AUTO_DOWNLOAD_REPORT, false); } @@ -728,6 +748,16 @@ public class UserPreferences { } public static boolean gpodnetNotificationsEnabled() { + if (Build.VERSION.SDK_INT >= 26) { + return true; // System handles notification preferences + } + return prefs.getBoolean(PREF_GPODNET_NOTIFICATIONS, true); + } + + /** + * Used for migration of the preference to system notification channels. + */ + public static boolean getGpodnetNotificationsEnabledRaw() { return prefs.getBoolean(PREF_GPODNET_NOTIFICATIONS, true); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 1df873e14..b8bad7c0a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -206,8 +206,7 @@ public class DownloadService extends Service { isRunning = false; boolean showAutoDownloadReport = UserPreferences.showAutoDownloadReport(); - if (ClientConfig.downloadServiceCallbacks.shouldCreateReport() - && (UserPreferences.showDownloadReport() || showAutoDownloadReport)) { + if (UserPreferences.showDownloadReport() || showAutoDownloadReport) { notificationManager.updateReport(reportQueue, showAutoDownloadReport); reportQueue.clear(); } @@ -430,7 +429,7 @@ public class DownloadService extends Service { + ", cleanupMedia=" + cleanupMedia); if (cleanupMedia) { - ClientConfig.dbTasksCallbacks.getEpisodeCacheCleanupAlgorithm() + UserPreferences.getEpisodeCleanupAlgorithm() .makeRoomForEpisodes(getApplicationContext(), requests.size()); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 0715d50dd..fb6009c02 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -148,7 +148,7 @@ public class DownloadServiceNotification { id = R.id.notification_auto_download_report; content = createAutoDownloadNotificationContent(reportQueue); } else { - channelId = NotificationUtils.CHANNEL_ID_ERROR; + channelId = NotificationUtils.CHANNEL_ID_DOWNLOAD_ERROR; titleId = R.string.download_report_title; iconId = R.drawable.ic_notification_sync_error; intent = ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 69b35bff5..92fd9cb55 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -973,10 +973,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { Log.d(TAG, "getNextInQueue(), but playable not an instance of FeedMedia, so not proceeding"); return null; } - if (!ClientConfig.playbackServiceCallbacks.useQueue()) { - Log.d(TAG, "getNextInQueue(), but queue not in use by this app"); - return null; - } Log.d(TAG, "getNextInQueue()"); FeedMedia media = (FeedMedia) currentMedia; try { diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java index 3f6a56fc8..4a0583ff4 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java @@ -290,7 +290,7 @@ public final class DBTasks { */ public static Future<?> autodownloadUndownloadedItems(final Context context) { Log.d(TAG, "autodownloadUndownloadedItems"); - return autodownloadExec.submit(ClientConfig.dbTasksCallbacks.getAutomaticDownloadAlgorithm() + return autodownloadExec.submit(ClientConfig.automaticDownloadAlgorithm .autoDownloadUndownloadedItems(context)); } @@ -304,7 +304,7 @@ public final class DBTasks { * @param context Used for accessing the DB. */ public static void performAutoCleanup(final Context context) { - ClientConfig.dbTasksCallbacks.getEpisodeCacheCleanupAlgorithm().performCleanup(context); + UserPreferences.getEpisodeCleanupAlgorithm().performCleanup(context); } /** diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index ad7f40700..fc431d25d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -195,11 +195,11 @@ public class PodDBAdapter { + TABLE_NAME_FEED_ITEMS + "_" + KEY_FEED + " ON " + TABLE_NAME_FEED_ITEMS + " (" + KEY_FEED + ")"; - static final String CREATE_INDEX_FEEDITEMS_PUBDATE = "CREATE INDEX IF NOT EXISTS " + static final String CREATE_INDEX_FEEDITEMS_PUBDATE = "CREATE INDEX " + TABLE_NAME_FEED_ITEMS + "_" + KEY_PUBDATE + " ON " + TABLE_NAME_FEED_ITEMS + " (" + KEY_PUBDATE + ")"; - static final String CREATE_INDEX_FEEDITEMS_READ = "CREATE INDEX IF NOT EXISTS " + static final String CREATE_INDEX_FEEDITEMS_READ = "CREATE INDEX " + TABLE_NAME_FEED_ITEMS + "_" + KEY_READ + " ON " + TABLE_NAME_FEED_ITEMS + " (" + KEY_READ + ")"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java b/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java index 1f5d9b75f..ffe90eee2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java @@ -485,7 +485,11 @@ public class SyncService extends Worker { } private void updateErrorNotification(SyncServiceException exception) { - Log.d(TAG, "Posting error notification"); + if (!UserPreferences.gpodnetNotificationsEnabled()) { + Log.d(TAG, "Skipping sync error notification because of user setting"); + return; + } + Log.d(TAG, "Posting sync error notification"); final String description = getApplicationContext().getString(R.string.gpodnetsync_error_descr) + exception.getMessage(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java index ddbe68938..3101eac34 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java @@ -2,28 +2,36 @@ package de.danoeh.antennapod.core.util.gui; import android.app.NotificationChannel; +import android.app.NotificationChannelGroup; import android.app.NotificationManager; import android.content.Context; import android.os.Build; import androidx.annotation.RequiresApi; import de.danoeh.antennapod.core.R; +import de.danoeh.antennapod.core.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_ERROR = "error"; + 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_AUTO_DOWNLOAD = "auto_download"; + public static final String GROUP_ID_ERRORS = "group_errors"; + public static final String GROUP_ID_NEWS = "group_news"; + public static void createChannels(Context context) { - if (android.os.Build.VERSION.SDK_INT < 26) { + if (Build.VERSION.SDK_INT < 26) { return; } NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (mNotificationManager != null) { + mNotificationManager.createNotificationChannelGroup(createGroupErrors(context)); + mNotificationManager.createNotificationChannelGroup(createGroupNews(context)); + mNotificationManager.createNotificationChannel(createChannelUserAction(context)); mNotificationManager.createNotificationChannel(createChannelDownloading(context)); mNotificationManager.createNotificationChannel(createChannelPlaying(context)); @@ -35,36 +43,43 @@ public class NotificationUtils { @RequiresApi(api = Build.VERSION_CODES.O) private static NotificationChannel createChannelUserAction(Context c) { - NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_USER_ACTION, + NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID_USER_ACTION, c.getString(R.string.notification_channel_user_action), NotificationManager.IMPORTANCE_HIGH); - mChannel.setDescription(c.getString(R.string.notification_channel_user_action_description)); - return mChannel; + notificationChannel.setDescription(c.getString(R.string.notification_channel_user_action_description)); + notificationChannel.setGroup(GROUP_ID_ERRORS); + return notificationChannel; } @RequiresApi(api = Build.VERSION_CODES.O) private static NotificationChannel createChannelDownloading(Context c) { - NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_DOWNLOADING, + NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID_DOWNLOADING, c.getString(R.string.notification_channel_downloading), NotificationManager.IMPORTANCE_LOW); - mChannel.setDescription(c.getString(R.string.notification_channel_downloading_description)); - mChannel.setShowBadge(false); - return mChannel; + notificationChannel.setDescription(c.getString(R.string.notification_channel_downloading_description)); + notificationChannel.setShowBadge(false); + return notificationChannel; } @RequiresApi(api = Build.VERSION_CODES.O) private static NotificationChannel createChannelPlaying(Context c) { - NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_PLAYING, + NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID_PLAYING, c.getString(R.string.notification_channel_playing), NotificationManager.IMPORTANCE_LOW); - mChannel.setDescription(c.getString(R.string.notification_channel_playing_description)); - mChannel.setShowBadge(false); - return mChannel; + notificationChannel.setDescription(c.getString(R.string.notification_channel_playing_description)); + notificationChannel.setShowBadge(false); + return notificationChannel; } @RequiresApi(api = Build.VERSION_CODES.O) private static NotificationChannel createChannelError(Context c) { - NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_ERROR, - c.getString(R.string.notification_channel_error), NotificationManager.IMPORTANCE_HIGH); - mChannel.setDescription(c.getString(R.string.notification_channel_error_description)); - return mChannel; + NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID_DOWNLOAD_ERROR, + c.getString(R.string.notification_channel_download_error), NotificationManager.IMPORTANCE_HIGH); + notificationChannel.setDescription(c.getString(R.string.notification_channel_download_error_description)); + notificationChannel.setGroup(GROUP_ID_ERRORS); + + if (!UserPreferences.getShowDownloadReportRaw()) { + // Migration from app managed setting: disable notification + notificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE); + } + return notificationChannel; } @RequiresApi(api = Build.VERSION_CODES.O) @@ -72,14 +87,38 @@ public class NotificationUtils { NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID_SYNC_ERROR, c.getString(R.string.notification_channel_sync_error), NotificationManager.IMPORTANCE_HIGH); notificationChannel.setDescription(c.getString(R.string.notification_channel_sync_error_description)); + notificationChannel.setGroup(GROUP_ID_ERRORS); + + if (!UserPreferences.getGpodnetNotificationsEnabledRaw()) { + // Migration from app managed setting: disable notification + notificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE); + } return notificationChannel; } @RequiresApi(api = Build.VERSION_CODES.O) private static NotificationChannel createChannelAutoDownload(Context c) { - NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_AUTO_DOWNLOAD, - c.getString(R.string.notification_channel_auto_download), NotificationManager.IMPORTANCE_DEFAULT); - mChannel.setDescription(c.getString(R.string.notification_channel_episode_auto_download)); - return mChannel; + NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID_AUTO_DOWNLOAD, + c.getString(R.string.notification_channel_auto_download), NotificationManager.IMPORTANCE_NONE); + notificationChannel.setDescription(c.getString(R.string.notification_channel_episode_auto_download)); + notificationChannel.setGroup(GROUP_ID_NEWS); + + if (UserPreferences.getShowAutoDownloadReportRaw()) { + // Migration from app managed setting: enable notification + notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT); + } + return notificationChannel; + } + + @RequiresApi(api = Build.VERSION_CODES.O) + private static NotificationChannelGroup createGroupErrors(Context c) { + return new NotificationChannelGroup(GROUP_ID_ERRORS, + c.getString(R.string.notification_group_errors)); + } + + @RequiresApi(api = Build.VERSION_CODES.O) + private static NotificationChannelGroup createGroupNews(Context c) { + return new NotificationChannelGroup(GROUP_ID_NEWS, + c.getString(R.string.notification_group_news)); } } |