From 3cdf44e0994b864c4f4f9b9c2b20c5beffbed4a2 Mon Sep 17 00:00:00 2001 From: Karim Abou Zeid Date: Mon, 22 Jun 2015 17:13:50 +0200 Subject: [PATCH] Fixed the notification not showing up when starting playback from the fab --- app/build.gradle | 4 ++-- .../helper/PlayingNotificationHelper.java | 20 +++++++++++-------- .../gramophone/service/MusicService.java | 12 +++++------ 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 59cf189b..157c7801 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,8 +26,8 @@ android { applicationId "com.kabouzeid.gramophone" minSdkVersion 16 targetSdkVersion 22 - versionCode 43 - versionName "0.9.27b dev-1" + versionCode 45 + versionName "0.9.29b dev-1" } buildTypes { diff --git a/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java b/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java index 3918b13a..2d473fbb 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java +++ b/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java @@ -72,21 +72,25 @@ public class PlayingNotificationHelper { if (intent.getAction().equals(ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED)) { boolean isColored = intent.getBooleanExtra(EXTRA_NOTIFICATION_COLORED, false); if (isNotificationShown && PlayingNotificationHelper.this.isColored != isColored) { - buildNotification(currentSong, isPlaying, isColored); + updateNotification(isColored); } } } }; - public void buildNotification(final Song song, final boolean isPlaying) { - buildNotification(song, isPlaying, PreferenceUtils.getInstance(service).coloredNotification()); + public void updateNotification() { + updateNotification(PreferenceUtils.getInstance(service).coloredNotification()); } - private void buildNotification(final Song song, final boolean isPlaying, final boolean isColored) { - if (song.id == -1) return; + private void updateNotification(final boolean isColored) { + Song song = service.getCurrentSong(); + if (song.id == -1) { + service.stopForeground(true); + return; + } this.isColored = isColored; currentSong = song; - this.isPlaying = isPlaying; + this.isPlaying = service.isPlayingAndNotFadingDown(); if (!isReceiverRegistered) service.registerReceiver(notificationColorPreferenceChangedReceiver, intentFilter); isReceiverRegistered = true; @@ -258,8 +262,8 @@ public class PlayingNotificationHelper { public void updatePlayState(final boolean isPlaying) { this.isPlaying = isPlaying; - if (notification == null || notificationManager == null) { - return; + if (notification == null) { + updateNotification(); } if (notificationLayout != null) { notificationLayout.setImageViewResource(R.id.action_play_pause, diff --git a/app/src/main/java/com/kabouzeid/gramophone/service/MusicService.java b/app/src/main/java/com/kabouzeid/gramophone/service/MusicService.java index b0d0675e..9115db9b 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/service/MusicService.java +++ b/app/src/main/java/com/kabouzeid/gramophone/service/MusicService.java @@ -434,7 +434,7 @@ public class MusicService extends Service { } private void updateNotification() { - playingNotificationHelper.buildNotification(getCurrentSong(), isPlayingAndNotFadingDown()); + playingNotificationHelper.updateNotification(); } private void updateWidgets() { @@ -570,11 +570,11 @@ public class MusicService extends Service { saveState(); } - public void addSongs(int position, List songs) { - playingQueue.addAll(position, songs); - originalPlayingQueue.addAll(position, songs); - saveState(); - } +// public void addSongs(int position, List songs) { +// playingQueue.addAll(position, songs); +// originalPlayingQueue.addAll(position, songs); +// saveState(); +// } public void addSongs(List songs) { playingQueue.addAll(songs);