aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-03-28 11:34:35 -0700
committerScott Jackson <daneren2005@gmail.com>2015-03-28 11:34:35 -0700
commit7811c911575c03dbdf7d6a1a334228210ada66f3 (patch)
tree29526b80025518ced9f68498b58768826073ebe8 /src
parent60ffea0878eabad526ec844c908a57c7d6e44558 (diff)
downloaddsub-7811c911575c03dbdf7d6a1a334228210ada66f3.tar.gz
dsub-7811c911575c03dbdf7d6a1a334228210ada66f3.tar.bz2
dsub-7811c911575c03dbdf7d6a1a334228210ada66f3.zip
Make ongoing notification dismissable
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/util/Notifications.java15
1 files changed, 12 insertions, 3 deletions
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);
+ }
}
});
}