diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 655049b2c..e05538b63 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -91,7 +91,7 @@ public class MainActivity extends CastEnabledActivity { super.onCreate(savedInstanceState); StorageUtils.checkStorageAvailability(this); setContentView(R.layout.main); - recycledViewPool.setMaxRecycledViews(R.id.episode_item_view_holder, 25); + recycledViewPool.setMaxRecycledViews(R.id.view_type_episode_item, 25); drawerLayout = findViewById(R.id.drawer_layout); navDrawer = findViewById(R.id.navDrawerFragment); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java index d391f1c54..7099d6f3a 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java @@ -44,7 +44,7 @@ public class EpisodeItemListAdapter extends RecyclerView.Adapter onDownloadQueued(intent)); } else if (numberOfDownloads.get() == 0) { stopSelf(); @@ -191,7 +190,7 @@ public class DownloadService extends Service { Notification notification = notificationManager.updateNotifications( requester.getNumberOfDownloads(), downloads); - startForeground(NOTIFICATION_ID, notification); + startForeground(R.id.notification_downloading, notification); } @Override @@ -229,7 +228,7 @@ public class DownloadService extends Service { stopForeground(true); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - nm.cancel(NOTIFICATION_ID); + nm.cancel(R.id.notification_downloading); // if this was the initial gpodder sync, i.e. we just synced the feeds successfully, // it is now time to sync the episode actions @@ -566,7 +565,7 @@ public class DownloadService extends Service { setupNotificationUpdater(); Notification notification = notificationManager.updateNotifications( requester.getNumberOfDownloads(), downloads); - startForeground(NOTIFICATION_ID, notification); + startForeground(R.id.notification_downloading, notification); } } @@ -642,7 +641,7 @@ public class DownloadService extends Service { Notification n = notificationManager.updateNotifications(requester.getNumberOfDownloads(), downloads); if (n != null) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - nm.notify(NOTIFICATION_ID, n); + nm.notify(R.id.notification_downloading, n); } } } 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 f487193f3..64666d25d 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 @@ -17,8 +17,6 @@ import java.util.List; public class DownloadServiceNotification { private static final String TAG = "DownloadSvcNotification"; - private static final int REPORT_ID = 3; - private static final int AUTO_REPORT_ID = 4; private final Context context; private NotificationCompat.Builder notificationCompatBuilder; @@ -147,14 +145,14 @@ public class DownloadServiceNotification { titleId = R.string.auto_download_report_title; iconId = R.drawable.ic_notification_auto_download_complete; intent = ClientConfig.downloadServiceCallbacks.getAutoDownloadReportNotificationContentIntent(context); - id = AUTO_REPORT_ID; + id = R.id.notification_auto_download_report; content = createAutoDownloadNotificationContent(reportQueue); } else { channelId = NotificationUtils.CHANNEL_ID_ERROR; titleId = R.string.download_report_title; iconId = R.drawable.ic_notification_sync_error; intent = ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context); - id = REPORT_ID; + id = R.id.notification_download_report; content = String.format(context.getString(R.string.download_report_content), successfulDownloads, failedDownloads); } 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 33a2a72ff..bd17ff383 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 @@ -204,9 +204,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { */ private static volatile boolean isCasting = false; - private static final int NOTIFICATION_ID = 1; - private static final int NOTIFICATION_ID_STREAMING = 2; - private PlaybackServiceMediaPlayer mediaPlayer; private PlaybackServiceTaskManager taskManager; private PlaybackServiceFlavorHelper flavorHelper; @@ -271,7 +268,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { stateManager = new PlaybackServiceStateManager(this); notificationBuilder = new PlaybackServiceNotificationBuilder(this); - stateManager.startForeground(NOTIFICATION_ID, notificationBuilder.build()); + stateManager.startForeground(R.id.notification_playing, notificationBuilder.build()); registerReceiver(autoStateUpdated, new IntentFilter("com.google.android.gms.car.media.STATUS")); registerReceiver(headsetDisconnected, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); @@ -334,7 +331,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { if (notificationBuilder.getPlayerStatus() == PlayerStatus.PLAYING) { notificationBuilder.setPlayerStatus(PlayerStatus.STOPPED); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); - notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + notificationManager.notify(R.id.notification_playing, notificationBuilder.build()); } stateManager.stopForeground(!UserPreferences.isPersistNotify()); isRunning = false; @@ -450,9 +447,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { super.onStartCommand(intent, flags, startId); Log.d(TAG, "OnStartCommand called"); - stateManager.startForeground(NOTIFICATION_ID, notificationBuilder.build()); + stateManager.startForeground(R.id.notification_playing, notificationBuilder.build()); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); - notificationManager.cancel(NOTIFICATION_ID_STREAMING); + notificationManager.cancel(R.id.notification_streaming_confirmation); final int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1); final boolean castDisconnect = intent.getBooleanExtra(EXTRA_CAST_DISCONNECT, false); @@ -542,9 +539,11 @@ public class PlaybackService extends MediaBrowserServiceCompat { intentAllowThisTime.putExtra(EXTRA_ALLOW_STREAM_THIS_TIME, true); PendingIntent pendingIntentAllowThisTime; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - pendingIntentAllowThisTime = PendingIntent.getForegroundService(this, 0, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT); + pendingIntentAllowThisTime = PendingIntent.getForegroundService(this, + R.id.pending_intent_allow_stream_this_time, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT); } else { - pendingIntentAllowThisTime = PendingIntent.getService(this, 0, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT); + pendingIntentAllowThisTime = PendingIntent.getService(this, + R.id.pending_intent_allow_stream_this_time, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT); } Intent intentAlwaysAllow = new Intent(intentAllowThisTime); @@ -552,12 +551,15 @@ public class PlaybackService extends MediaBrowserServiceCompat { intentAlwaysAllow.putExtra(EXTRA_ALLOW_STREAM_ALWAYS, true); PendingIntent pendingIntentAlwaysAllow; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this, 0, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT); + pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this, + R.id.pending_intent_allow_stream_always, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT); } else { - pendingIntentAlwaysAllow = PendingIntent.getService(this, 0, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT); + pendingIntentAlwaysAllow = PendingIntent.getService(this, + R.id.pending_intent_allow_stream_always, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT); } - NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_USER_ACTION) + NotificationCompat.Builder builder = new NotificationCompat.Builder(this, + NotificationUtils.CHANNEL_ID_USER_ACTION) .setSmallIcon(R.drawable.ic_stream_white) .setContentTitle(getString(R.string.confirm_mobile_streaming_notification_title)) .setContentText(getString(R.string.confirm_mobile_streaming_notification_message)) @@ -573,7 +575,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { pendingIntentAlwaysAllow) .setAutoCancel(true); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); - notificationManager.notify(NOTIFICATION_ID_STREAMING, builder.build()); + notificationManager.notify(R.id.notification_streaming_confirmation, builder.build()); } /** @@ -1238,9 +1240,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { } } if (!Thread.currentThread().isInterrupted() && stateManager.hasReceivedValidStartCommand()) { - mediaSession.setSessionActivity(PendingIntent.getActivity(this, 0, - PlaybackService.getPlayerActivityIntent(this), - PendingIntent.FLAG_UPDATE_CURRENT)); + mediaSession.setSessionActivity(PendingIntent.getActivity(this, R.id.pending_intent_player_activity, + PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT)); try { mediaSession.setMetadata(builder.build()); } catch (OutOfMemoryError e) { @@ -1289,7 +1290,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { notificationBuilder.updatePosition(getCurrentPosition(), getCurrentPlaybackSpeed()); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); - notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + notificationManager.notify(R.id.notification_playing, notificationBuilder.build()); startForegroundIfPlaying(playerStatus); if (!notificationBuilder.isIconCached()) { @@ -1297,7 +1298,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { Log.d(TAG, "Loading notification icon"); notificationBuilder.loadIcon(); if (!Thread.currentThread().isInterrupted()) { - notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + notificationManager.notify(R.id.notification_playing, notificationBuilder.build()); } }); notificationSetupThread.start(); @@ -1309,12 +1310,12 @@ public class PlaybackService extends MediaBrowserServiceCompat { if (stateManager.hasReceivedValidStartCommand()) { if (isCasting || status == PlayerStatus.PLAYING || status == PlayerStatus.PREPARING || status == PlayerStatus.SEEKING) { - stateManager.startForeground(NOTIFICATION_ID, notificationBuilder.build()); + stateManager.startForeground(R.id.notification_playing, notificationBuilder.build()); Log.d(TAG, "foreground"); } else { stateManager.stopForeground(false); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); - notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + notificationManager.notify(R.id.notification_playing, notificationBuilder.build()); } } } @@ -1717,7 +1718,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { notificationBuilder.updatePosition(getCurrentPosition(), getCurrentPlaybackSpeed()); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + notificationManager.notify(R.id.notification_playing, notificationBuilder.build()); } skipEndingIfNecessary(); }); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java index 174b43846..915e77f6c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceNotificationBuilder.java @@ -146,8 +146,8 @@ public class PlaybackServiceNotificationBuilder { } private PendingIntent getPlayerActivityPendingIntent() { - return PendingIntent.getActivity(context, 0, PlaybackService.getPlayerActivityIntent(context), - PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getActivity(context, R.id.pending_intent_player_activity, + PlaybackService.getPlayerActivityIntent(context), PendingIntent.FLAG_UPDATE_CURRENT); } private void addActions(NotificationCompat.Builder notification, MediaSessionCompat.Token mediaSessionToken, 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 6985e4421..4c89ebc19 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 @@ -488,8 +488,8 @@ public class SyncService extends Worker { Intent intent = getApplicationContext().getPackageManager().getLaunchIntentForPackage( getApplicationContext().getPackageName()); - PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), + R.id.pending_intent_sync_error, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(getApplicationContext(), NotificationUtils.CHANNEL_ID_ERROR) .setContentTitle(getApplicationContext().getString(R.string.gpodnetsync_error_title)) diff --git a/core/src/main/res/values/ids.xml b/core/src/main/res/values/ids.xml index 1d1777ef1..3c173b72d 100644 --- a/core/src/main/res/values/ids.xml +++ b/core/src/main/res/values/ids.xml @@ -1,28 +1,36 @@ - - - - + - - - - - - + + + + + - - - + + + + + + + + + + + + + + + \ No newline at end of file