1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Only update notification large icon when it changes

This commit is contained in:
Stypox 2022-08-28 18:35:58 +02:00
parent f9109ebc81
commit ed87465565
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
2 changed files with 19 additions and 4 deletions

View File

@ -43,7 +43,7 @@ public final class NotificationPlayerUi extends PlayerUi {
@Override @Override
public void onThumbnailLoaded(@Nullable final Bitmap bitmap) { public void onThumbnailLoaded(@Nullable final Bitmap bitmap) {
super.onThumbnailLoaded(bitmap); super.onThumbnailLoaded(bitmap);
notificationUtil.createNotificationIfNeededAndUpdate(false); notificationUtil.updateThumbnail();
} }
@Override @Override

View File

@ -24,6 +24,8 @@ import org.schabi.newpipe.player.mediasession.MediaSessionPlayerUi;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
import static androidx.media.app.NotificationCompat.MediaStyle; import static androidx.media.app.NotificationCompat.MediaStyle;
@ -40,8 +42,6 @@ import static org.schabi.newpipe.player.notification.NotificationConstants.ACTIO
/** /**
* This is a utility class for player notifications. * This is a utility class for player notifications.
*
* @author cool-student
*/ */
public final class NotificationUtil { public final class NotificationUtil {
private static final String TAG = NotificationUtil.class.getSimpleName(); private static final String TAG = NotificationUtil.class.getSimpleName();
@ -79,6 +79,19 @@ public final class NotificationUtil {
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
} }
public synchronized void updateThumbnail() {
if (notificationBuilder != null) {
if (DEBUG) {
Log.d(TAG, "updateThumbnail() called with thumbnail = [" + Integer.toHexString(
Optional.ofNullable(player.getThumbnail()).map(Objects::hashCode).orElse(0))
+ "], title = [" + player.getVideoTitle() + "]");
}
setLargeIcon(notificationBuilder);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}
}
private synchronized NotificationCompat.Builder createNotification() { private synchronized NotificationCompat.Builder createNotification() {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "createNotification()"); Log.d(TAG, "createNotification()");
@ -123,6 +136,9 @@ public final class NotificationUtil {
.setDeleteIntent(PendingIntent.getBroadcast(player.getContext(), NOTIFICATION_ID, .setDeleteIntent(PendingIntent.getBroadcast(player.getContext(), NOTIFICATION_ID,
new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT)); new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT));
// set the initial value for the video thumbnail, updatable with updateNotificationThumbnail
setLargeIcon(builder);
return builder; return builder;
} }
@ -142,7 +158,6 @@ public final class NotificationUtil {
notificationBuilder.setTicker(player.getVideoTitle()); notificationBuilder.setTicker(player.getVideoTitle());
updateActions(notificationBuilder); updateActions(notificationBuilder);
setLargeIcon(notificationBuilder);
} }