24
24
import org .schabi .newpipe .util .NavigationHelper ;
25
25
26
26
import java .util .List ;
27
+ import java .util .Objects ;
28
+ import java .util .Optional ;
27
29
28
30
import static android .app .PendingIntent .FLAG_UPDATE_CURRENT ;
29
31
import static androidx .media .app .NotificationCompat .MediaStyle ;
40
42
41
43
/**
42
44
* This is a utility class for player notifications.
43
- *
44
- * @author cool-student
45
45
*/
46
46
public final class NotificationUtil {
47
47
private static final String TAG = NotificationUtil .class .getSimpleName ();
@@ -79,6 +79,19 @@ public synchronized void createNotificationIfNeededAndUpdate(final boolean force
79
79
notificationManager .notify (NOTIFICATION_ID , notificationBuilder .build ());
80
80
}
81
81
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
+
82
95
private synchronized NotificationCompat .Builder createNotification () {
83
96
if (DEBUG ) {
84
97
Log .d (TAG , "createNotification()" );
@@ -123,6 +136,9 @@ private synchronized NotificationCompat.Builder createNotification() {
123
136
.setDeleteIntent (PendingIntent .getBroadcast (player .getContext (), NOTIFICATION_ID ,
124
137
new Intent (ACTION_CLOSE ), FLAG_UPDATE_CURRENT ));
125
138
139
+ // set the initial value for the video thumbnail, updatable with updateNotificationThumbnail
140
+ setLargeIcon (builder );
141
+
126
142
return builder ;
127
143
}
128
144
@@ -142,7 +158,6 @@ private synchronized void updateNotification() {
142
158
notificationBuilder .setTicker (player .getVideoTitle ());
143
159
144
160
updateActions (notificationBuilder );
145
- setLargeIcon (notificationBuilder );
146
161
}
147
162
148
163
0 commit comments