diff options
author | Koen <koen@koenvh.nl> | 2018-12-07 16:17:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-07 16:17:32 +0100 |
commit | 968b1d6972b137b4c1f1bdaf028db4bf54509579 (patch) | |
tree | ddae83de1ad54ac2d6650d399c01ebec7fb71258 /app/src/main/java/github/daneren2005/dsub/util/Notifications.java | |
parent | f104d619d6164d308f3195bd7f8dd0b01c832ef9 (diff) | |
parent | 898b2a955dfbad411187c7311cc09286cf53b554 (diff) | |
download | dsub-968b1d6972b137b4c1f1bdaf028db4bf54509579.tar.gz dsub-968b1d6972b137b4c1f1bdaf028db4bf54509579.tar.bz2 dsub-968b1d6972b137b4c1f1bdaf028db4bf54509579.zip |
Merge pull request #4 from daneren2005/edge
5.4.4
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/util/Notifications.java')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/util/Notifications.java | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java index 59341ebf..a8f7add0 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java @@ -114,11 +114,11 @@ public final class Notifications { handler.post(new Runnable() { @Override public void run() { - downloadService.stopForeground(true); + stopForeground(downloadService, true); showDownloadingNotification(context, downloadService, handler, downloadService.getCurrentDownloading(), downloadService.getBackgroundDownloads().size()); try { - downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); + startForeground(downloadService, NOTIFICATION_ID_PLAYING, notification); } catch(Exception e) { Log.e(TAG, "Failed to start notifications after stopping foreground download"); } @@ -130,7 +130,7 @@ public final class Notifications { public void run() { if (playing) { try { - downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); + startForeground(downloadService, NOTIFICATION_ID_PLAYING, notification); } catch(Exception e) { Log.e(TAG, "Failed to start notifications while playing"); } @@ -138,7 +138,7 @@ public final class Notifications { playShowing = false; persistentPlayingShowing = true; NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - downloadService.stopForeground(false); + stopForeground(downloadService, false); try { notificationManager.notify(NOTIFICATION_ID_PLAYING, notification); @@ -334,7 +334,7 @@ public final class Notifications { handler.post(new Runnable() { @Override public void run() { - downloadService.stopForeground(true); + stopForeground(downloadService, true); if(persistentPlayingShowing) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); @@ -413,7 +413,7 @@ public final class Notifications { handler.post(new Runnable() { @Override public void run() { - downloadService.startForeground(NOTIFICATION_ID_DOWNLOADING, notification); + startForeground(downloadService, NOTIFICATION_ID_DOWNLOADING, notification); } }); } @@ -429,7 +429,7 @@ public final class Notifications { handler.post(new Runnable() { @Override public void run() { - downloadService.stopForeground(true); + stopForeground(downloadService, true); } }); } @@ -461,8 +461,8 @@ public final class Notifications { .setChannelId("downloading-channel"); final Notification notification = builder.build(); - downloadService.startForeground(NOTIFICATION_ID_SHUT_GOOGLE_UP, notification); - downloadService.stopForeground(true); + startForeground(downloadService, NOTIFICATION_ID_SHUT_GOOGLE_UP, notification); + stopForeground(downloadService, true); } public static void showSyncNotification(final Context context, int stringId, String extra) { @@ -537,4 +537,14 @@ public final class Notifications { return syncChannel; } + + private static void startForeground(DownloadService downloadService, int notificationId, Notification notification) { + downloadService.startForeground(notificationId, notification); + downloadService.setIsForeground(true); + } + + private static void stopForeground(DownloadService downloadService, boolean removeNotification) { + downloadService.stopForeground(removeNotification); + downloadService.setIsForeground(false); + } } |