aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-04-04 19:52:35 -0700
committerScott Jackson <daneren2005@gmail.com>2013-04-04 19:52:35 -0700
commita0617207ded5c85ee3248d58c33c9f60a8c9b7d4 (patch)
tree87342597f6f96ef0f3394419f179d5e7aa9d6782
parent35ca854394f07851dc90c449ff5fac9941fa2783 (diff)
parent9f0e3c7aa53efeca8ac30a9e8b7725bbadb98b3f (diff)
downloaddsub-a0617207ded5c85ee3248d58c33c9f60a8c9b7d4.tar.gz
dsub-a0617207ded5c85ee3248d58c33c9f60a8c9b7d4.tar.bz2
dsub-a0617207ded5c85ee3248d58c33c9f60a8c9b7d4.zip
Merge branch 'master' of https://github.com/daneren2005/Subsonic.git
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java13
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java23
2 files changed, 23 insertions, 13 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index da34ddaf..e99ce3af 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -93,6 +93,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private boolean isPartial = true;
private final List<DownloadFile> downloadList = new ArrayList<DownloadFile>();
private final List<DownloadFile> backgroundDownloadList = new ArrayList<DownloadFile>();
+ private final Handler handler = new Handler();
private final DownloadServiceLifecycleSupport lifecycleSupport = new DownloadServiceLifecycleSupport(this);
private final ShufflePlayBuffer shufflePlayBuffer = new ShufflePlayBuffer(this);
@@ -239,7 +240,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
if(nextPlayingTask != null) {
nextPlayingTask.cancel();
}
- Util.hidePlayingNotification(this, this);
+ Util.hidePlayingNotification(this, this, handler);
instance = null;
}
@@ -514,7 +515,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
mRemoteControl.updateMetadata(this, currentPlaying.getSong());
} else {
Util.broadcastNewTrackInfo(this, null);
- Util.hidePlayingNotification(this, this);
+ Util.hidePlayingNotification(this, this, handler);
}
}
@@ -833,16 +834,16 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
if (show) {
- Util.showPlayingNotification(this, this, currentPlaying.getSong());
+ Util.showPlayingNotification(this, this, handler, currentPlaying.getSong());
} else if (pause) {
SharedPreferences prefs = Util.getPreferences(this);
if(prefs.getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false)) {
- Util.showPlayingNotification(this, this, currentPlaying.getSong());
+ Util.showPlayingNotification(this, this, handler, currentPlaying.getSong());
} else {
- Util.hidePlayingNotification(this, this);
+ Util.hidePlayingNotification(this, this, handler);
}
} else if(hide) {
- Util.hidePlayingNotification(this, this);
+ Util.hidePlayingNotification(this, this, handler);
}
mRemoteControl.setPlaybackState(playerState.getRemoteControlClientPlayState());
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index 6e5d31a9..0a86baf8 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -113,7 +113,6 @@ public final class Util {
private final static Pair<Integer, Integer> NOTIFICATION_TEXT_COLORS = new Pair<Integer, Integer>();
private static Toast toast;
- private static int notificationID = 123512383;
private Util() {
}
@@ -644,7 +643,7 @@ public final class Util {
.show();
}
- public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, MusicDirectory.Entry song) {
+ public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, 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;
@@ -662,8 +661,13 @@ public final class Util {
Intent notificationIntent = new Intent(context, DownloadActivity.class);
notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
- NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- manager.notify(notificationID, notification);
+
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification);
+ }
+ });
// Update widget
DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true);
@@ -738,9 +742,14 @@ public final class Util {
rv.setOnClickPendingIntent(R.id.control_next, pendingIntent);
}
- public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService) {
- NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- manager.cancelAll();
+ public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler) {
+ // Remove notification and remove the service from the foreground
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ downloadService.stopForeground(true);
+ }
+ });
// Update widget
DSubWidgetProvider.getInstance().notifyChange(context, downloadService, false);