Skip to content

Commit

Permalink
Only update notification large icon when it changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Aug 28, 2022
1 parent f9109eb commit 2572a8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void destroy() {
@Override
public void onThumbnailLoaded(@Nullable final Bitmap bitmap) {
super.onThumbnailLoaded(bitmap);
notificationUtil.createNotificationIfNeededAndUpdate(false);
notificationUtil.updateThumbnail();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.schabi.newpipe.util.NavigationHelper;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
import static androidx.media.app.NotificationCompat.MediaStyle;
Expand Down Expand Up @@ -79,6 +81,17 @@ public synchronized void createNotificationIfNeededAndUpdate(final boolean force
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}

public synchronized void updateThumbnail() {
Log.e(TAG, "updateThumbnail " + Integer.toHexString(notificationBuilder.hashCode())
+ " - " + Integer.toHexString(Optional.ofNullable(player.getThumbnail()).map(
Objects::hashCode).orElse(0))
+ " - " + player.getVideoTitle());
if (notificationBuilder != null) {
setLargeIcon(notificationBuilder);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}
}

private synchronized NotificationCompat.Builder createNotification() {
if (DEBUG) {
Log.d(TAG, "createNotification()");
Expand Down Expand Up @@ -123,6 +136,9 @@ private synchronized NotificationCompat.Builder createNotification() {
.setDeleteIntent(PendingIntent.getBroadcast(player.getContext(), NOTIFICATION_ID,
new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT));

// set the initial value for the video thumbnail, updatable with updateNotificationThumbnail
setLargeIcon(builder);

return builder;
}

Expand All @@ -142,7 +158,6 @@ private synchronized void updateNotification() {
notificationBuilder.setTicker(player.getVideoTitle());

updateActions(notificationBuilder);
setLargeIcon(notificationBuilder);
}


Expand Down

0 comments on commit 2572a8c

Please sign in to comment.