summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2020-05-27 11:11:31 +0200
committerByteHamster <info@bytehamster.com>2020-05-27 11:11:31 +0200
commit31404f72cf972c303c4ea7e0c8ca5aa58dc87d49 (patch)
tree3da4027b563ac3a8a98935f47d3b6ac6d37ae811
parent84b9cf9dbb050d078f836c357cf9cd79aa947065 (diff)
downloadAntennaPod-31404f72cf972c303c4ea7e0c8ca5aa58dc87d49.zip
Made notification IDs unique
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java13
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java6
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java23
-rw-r--r--core/src/main/res/values/ids.xml5
4 files changed, 23 insertions, 24 deletions
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 28523ef0a..ba7019fd9 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
@@ -17,6 +17,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
+import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.sync.SyncService;
import org.apache.commons.io.FileUtils;
import org.greenrobot.eventbus.EventBus;
@@ -87,8 +88,6 @@ public class DownloadService extends Service {
public static final String EXTRA_CLEANUP_MEDIA = "cleanupMedia";
- public static final int NOTIFICATION_ID = 2;
-
/**
* Contains all completed downloads that have not been included in the report yet.
*/
@@ -165,7 +164,7 @@ public class DownloadService extends Service {
if (intent != null && intent.getParcelableArrayListExtra(EXTRA_REQUESTS) != null) {
Notification notification = notificationManager.updateNotifications(
requester.getNumberOfDownloads(), downloads);
- startForeground(NOTIFICATION_ID, notification);
+ startForeground(R.id.notification_downloading, notification);
syncExecutor.execute(() -> 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 f25b0a5a8..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);
@@ -578,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());
}
/**
@@ -1293,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()) {
@@ -1301,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();
@@ -1313,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());
}
}
}
@@ -1721,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/res/values/ids.xml b/core/src/main/res/values/ids.xml
index bfb6fc9be..3c173b72d 100644
--- a/core/src/main/res/values/ids.xml
+++ b/core/src/main/res/values/ids.xml
@@ -18,6 +18,11 @@
<!-- Notifications need unique IDs to update/cancel them -->
<item name="notification_gpodnet_sync_error" type="id"/>
<item name="notification_gpodnet_sync_autherror" type="id"/>
+ <item name="notification_downloading" type="id"/>
+ <item name="notification_download_report" type="id"/>
+ <item name="notification_auto_download_report" type="id"/>
+ <item name="notification_playing" type="id"/>
+ <item name="notification_streaming_confirmation" type="id"/>
<!-- PendingIntent objects that use the same action but different extras need to use a unique request code -->
<item name="pending_intent_download_service_notification" type="id"/>