From 7811c911575c03dbdf7d6a1a334228210ada66f3 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 28 Mar 2015 11:34:35 -0700 Subject: Make ongoing notification dismissable --- src/github/daneren2005/dsub/util/Notifications.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/util/Notifications.java b/src/github/daneren2005/dsub/util/Notifications.java index 330e14ec..f56d9065 100644 --- a/src/github/daneren2005/dsub/util/Notifications.java +++ b/src/github/daneren2005/dsub/util/Notifications.java @@ -59,9 +59,11 @@ public final class Notifications { public static void showPlayingNotification(final Context context, final DownloadService downloadService, final Handler handler, MusicDirectory.Entry song) { // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(), System.currentTimeMillis()); - notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; - boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; + final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; + if(playing) { + notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; + } boolean remote = downloadService.isRemoteEnabled(); if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.JELLY_BEAN){ RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); @@ -97,7 +99,14 @@ public final class Notifications { handler.post(new Runnable() { @Override public void run() { - downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); + if(playing) { + downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); + } else { + playShowing = false; + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + downloadService.stopForeground(true); + notificationManager.notify(NOTIFICATION_ID_PLAYING, notification); + } } }); } -- cgit v1.2.3