Skip to content
This repository has been archived by the owner on Jun 4, 2018. It is now read-only.

Commit

Permalink
Fix notification sometimes not showing image by completely rebuilding
Browse files Browse the repository at this point in the history
the notification and not just updating it. Fix thread synchronization.
  • Loading branch information
djselbeck committed Oct 17, 2017
1 parent 9cdc37d commit c7768da
Showing 1 changed file with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ public class NotificationManager implements CoverBitmapLoader.CoverBitmapListene
*/
private MALPVolumeControlProvider mVolumeControlProvider;

private ReentrantLock mArtworkLock;


public NotificationManager(BackgroundService service) {
mService = service;
mNotificationManager = (android.app.NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE);
Expand All @@ -136,7 +133,6 @@ public NotificationManager(BackgroundService service) {

ArtworkManager.getInstance(service).registerOnNewAlbumImageListener(this);

mArtworkLock = new ReentrantLock();
}

/**
Expand Down Expand Up @@ -217,7 +213,6 @@ public synchronized void hideNotification() {
*/
public synchronized void updateNotification(MPDTrack track, MPDCurrentStatus.MPD_PLAYBACK_STATE state) {
if (track != null) {
mArtworkLock.lock();
openChannel();
mNotificationBuilder = new NotificationCompat.Builder(mService, NOTIFICATION_CHANNEL_ID);

Expand Down Expand Up @@ -352,7 +347,6 @@ public synchronized void updateNotification(MPDTrack track, MPDCurrentStatus.MPD

// Send the notification away
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
mArtworkLock.unlock();
}
}

Expand Down Expand Up @@ -404,7 +398,7 @@ private synchronized void updateMetadata(MPDTrack track, MPDCurrentStatus.MPD_PL
*
* @param status New MPD status
*/
public void setMPDStatus(MPDCurrentStatus status) {
public synchronized void setMPDStatus(MPDCurrentStatus status) {
if (mSessionActive) {
// Only update the notification if playback state really changed
if ( mLastStatus.getPlaybackState() != status.getPlaybackState()) {
Expand Down Expand Up @@ -468,11 +462,8 @@ public boolean notificationNeedsUpdate(MPDTrack track) {
public synchronized void receiveBitmap(Bitmap bm, final CoverBitmapLoader.IMAGE_TYPE type) {
// Check if notification exists and set picture
mLastBitmap = bm;
mArtworkLock.lock();
if (type == CoverBitmapLoader.IMAGE_TYPE.ALBUM_IMAGE && mNotification != null && bm != null) {
mNotificationBuilder.setLargeIcon(bm);
mNotification = mNotificationBuilder.build();
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
updateNotification(mLastTrack,mLastStatus.getPlaybackState());

/* Set lockscreen picture and stuff */
if (mMediaSession != null) {
Expand All @@ -485,7 +476,6 @@ public synchronized void receiveBitmap(Bitmap bm, final CoverBitmapLoader.IMAGE_
}
}
}
mArtworkLock.unlock();
}

@Override
Expand Down

0 comments on commit c7768da

Please sign in to comment.