Skip to content

Commit d73ca41

Browse files
Stypoxlitetex
authored andcommitted
Even when thumbnails should not be shown, set it to null in notification
This makes sure the thumbnail is removed from the notification if the user disables thumbnails
1 parent f3a9b81 commit d73ca41

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.util.Log;
1010

1111
import androidx.annotation.DrawableRes;
12+
import androidx.annotation.NonNull;
1213
import androidx.annotation.Nullable;
1314
import androidx.annotation.StringRes;
1415
import androidx.core.app.NotificationCompat;
@@ -137,12 +138,9 @@ private synchronized void updateNotification() {
137138
notificationBuilder.setContentTitle(player.getVideoTitle());
138139
notificationBuilder.setContentText(player.getUploaderName());
139140
notificationBuilder.setTicker(player.getVideoTitle());
141+
140142
updateActions(notificationBuilder);
141-
final boolean showThumbnail = player.getPrefs().getBoolean(
142-
player.getContext().getString(R.string.show_thumbnail_key), true);
143-
if (showThumbnail) {
144-
setLargeIcon(notificationBuilder);
145-
}
143+
setLargeIcon(notificationBuilder);
146144
}
147145

148146

@@ -344,17 +342,26 @@ private Intent getIntentForNotification() {
344342
/////////////////////////////////////////////////////
345343

346344
private void setLargeIcon(final NotificationCompat.Builder builder) {
345+
final boolean showThumbnail = player.getPrefs().getBoolean(
346+
player.getContext().getString(R.string.show_thumbnail_key), true);
347+
final Bitmap thumbnail = player.getThumbnail();
348+
if (thumbnail == null || !showThumbnail) {
349+
// since the builder is reused, make sure the thumbnail is unset if there is not one
350+
builder.setLargeIcon(null);
351+
return;
352+
}
353+
347354
final boolean scaleImageToSquareAspectRatio = player.getPrefs().getBoolean(
348355
player.getContext().getString(R.string.scale_to_square_image_in_notifications_key),
349356
false);
350357
if (scaleImageToSquareAspectRatio) {
351-
builder.setLargeIcon(getBitmapWithSquareAspectRatio(player.getThumbnail()));
358+
builder.setLargeIcon(getBitmapWithSquareAspectRatio(thumbnail));
352359
} else {
353-
builder.setLargeIcon(player.getThumbnail());
360+
builder.setLargeIcon(thumbnail);
354361
}
355362
}
356363

357-
private Bitmap getBitmapWithSquareAspectRatio(final Bitmap bitmap) {
364+
private Bitmap getBitmapWithSquareAspectRatio(@NonNull final Bitmap bitmap) {
358365
// Find the smaller dimension and then take a center portion of the image that
359366
// has that size.
360367
final int w = bitmap.getWidth();

0 commit comments

Comments
 (0)