|
9 | 9 | import android.util.Log; |
10 | 10 |
|
11 | 11 | import androidx.annotation.DrawableRes; |
| 12 | +import androidx.annotation.NonNull; |
12 | 13 | import androidx.annotation.Nullable; |
13 | 14 | import androidx.annotation.StringRes; |
14 | 15 | import androidx.core.app.NotificationCompat; |
@@ -137,12 +138,9 @@ private synchronized void updateNotification() { |
137 | 138 | notificationBuilder.setContentTitle(player.getVideoTitle()); |
138 | 139 | notificationBuilder.setContentText(player.getUploaderName()); |
139 | 140 | notificationBuilder.setTicker(player.getVideoTitle()); |
| 141 | + |
140 | 142 | 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); |
146 | 144 | } |
147 | 145 |
|
148 | 146 |
|
@@ -344,17 +342,26 @@ private Intent getIntentForNotification() { |
344 | 342 | ///////////////////////////////////////////////////// |
345 | 343 |
|
346 | 344 | 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 | + |
347 | 354 | final boolean scaleImageToSquareAspectRatio = player.getPrefs().getBoolean( |
348 | 355 | player.getContext().getString(R.string.scale_to_square_image_in_notifications_key), |
349 | 356 | false); |
350 | 357 | if (scaleImageToSquareAspectRatio) { |
351 | | - builder.setLargeIcon(getBitmapWithSquareAspectRatio(player.getThumbnail())); |
| 358 | + builder.setLargeIcon(getBitmapWithSquareAspectRatio(thumbnail)); |
352 | 359 | } else { |
353 | | - builder.setLargeIcon(player.getThumbnail()); |
| 360 | + builder.setLargeIcon(thumbnail); |
354 | 361 | } |
355 | 362 | } |
356 | 363 |
|
357 | | - private Bitmap getBitmapWithSquareAspectRatio(final Bitmap bitmap) { |
| 364 | + private Bitmap getBitmapWithSquareAspectRatio(@NonNull final Bitmap bitmap) { |
358 | 365 | // Find the smaller dimension and then take a center portion of the image that |
359 | 366 | // has that size. |
360 | 367 | final int w = bitmap.getWidth(); |
|
0 commit comments