2424import org .schabi .newpipe .util .NavigationHelper ;
2525
2626import java .util .List ;
27+ import java .util .Objects ;
28+ import java .util .Optional ;
2729
2830import static android .app .PendingIntent .FLAG_UPDATE_CURRENT ;
2931import static androidx .media .app .NotificationCompat .MediaStyle ;
4042
4143/**
4244 * This is a utility class for player notifications.
43- *
44- * @author cool-student
4545 */
4646public final class NotificationUtil {
4747 private static final String TAG = NotificationUtil .class .getSimpleName ();
@@ -79,6 +79,19 @@ public synchronized void createNotificationIfNeededAndUpdate(final boolean force
7979 notificationManager .notify (NOTIFICATION_ID , notificationBuilder .build ());
8080 }
8181
82+ public synchronized void updateThumbnail () {
83+ if (notificationBuilder != null ) {
84+ if (DEBUG ) {
85+ Log .d (TAG , "updateThumbnail() called with thumbnail = [" + Integer .toHexString (
86+ Optional .ofNullable (player .getThumbnail ()).map (Objects ::hashCode ).orElse (0 ))
87+ + "], title = [" + player .getVideoTitle () + "]" );
88+ }
89+
90+ setLargeIcon (notificationBuilder );
91+ notificationManager .notify (NOTIFICATION_ID , notificationBuilder .build ());
92+ }
93+ }
94+
8295 private synchronized NotificationCompat .Builder createNotification () {
8396 if (DEBUG ) {
8497 Log .d (TAG , "createNotification()" );
@@ -123,6 +136,9 @@ private synchronized NotificationCompat.Builder createNotification() {
123136 .setDeleteIntent (PendingIntent .getBroadcast (player .getContext (), NOTIFICATION_ID ,
124137 new Intent (ACTION_CLOSE ), FLAG_UPDATE_CURRENT ));
125138
139+ // set the initial value for the video thumbnail, updatable with updateNotificationThumbnail
140+ setLargeIcon (builder );
141+
126142 return builder ;
127143 }
128144
@@ -142,7 +158,6 @@ private synchronized void updateNotification() {
142158 notificationBuilder .setTicker (player .getVideoTitle ());
143159
144160 updateActions (notificationBuilder );
145- setLargeIcon (notificationBuilder );
146161 }
147162
148163
0 commit comments