Skip to content

Commit ed87465

Browse files
committed
Only update notification large icon when it changes
1 parent f9109eb commit ed87465

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

app/src/main/java/org/schabi/newpipe/player/notification/NotificationPlayerUi.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void destroy() {
4343
@Override
4444
public void onThumbnailLoaded(@Nullable final Bitmap bitmap) {
4545
super.onThumbnailLoaded(bitmap);
46-
notificationUtil.createNotificationIfNeededAndUpdate(false);
46+
notificationUtil.updateThumbnail();
4747
}
4848

4949
@Override

app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.schabi.newpipe.util.NavigationHelper;
2525

2626
import java.util.List;
27+
import java.util.Objects;
28+
import java.util.Optional;
2729

2830
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
2931
import static androidx.media.app.NotificationCompat.MediaStyle;
@@ -40,8 +42,6 @@
4042

4143
/**
4244
* This is a utility class for player notifications.
43-
*
44-
* @author cool-student
4545
*/
4646
public 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

Comments
 (0)