mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
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
This commit is contained in:
parent
f3a9b81b67
commit
d73ca41cfe
@ -9,6 +9,7 @@ import android.os.Build;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes;
|
import androidx.annotation.DrawableRes;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
@ -137,12 +138,9 @@ public final class NotificationUtil {
|
|||||||
notificationBuilder.setContentTitle(player.getVideoTitle());
|
notificationBuilder.setContentTitle(player.getVideoTitle());
|
||||||
notificationBuilder.setContentText(player.getUploaderName());
|
notificationBuilder.setContentText(player.getUploaderName());
|
||||||
notificationBuilder.setTicker(player.getVideoTitle());
|
notificationBuilder.setTicker(player.getVideoTitle());
|
||||||
|
|
||||||
updateActions(notificationBuilder);
|
updateActions(notificationBuilder);
|
||||||
final boolean showThumbnail = player.getPrefs().getBoolean(
|
setLargeIcon(notificationBuilder);
|
||||||
player.getContext().getString(R.string.show_thumbnail_key), true);
|
|
||||||
if (showThumbnail) {
|
|
||||||
setLargeIcon(notificationBuilder);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -344,17 +342,26 @@ public final class NotificationUtil {
|
|||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
private void setLargeIcon(final NotificationCompat.Builder builder) {
|
private void setLargeIcon(final NotificationCompat.Builder builder) {
|
||||||
|
final boolean showThumbnail = player.getPrefs().getBoolean(
|
||||||
|
player.getContext().getString(R.string.show_thumbnail_key), true);
|
||||||
|
final Bitmap thumbnail = player.getThumbnail();
|
||||||
|
if (thumbnail == null || !showThumbnail) {
|
||||||
|
// since the builder is reused, make sure the thumbnail is unset if there is not one
|
||||||
|
builder.setLargeIcon(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final boolean scaleImageToSquareAspectRatio = player.getPrefs().getBoolean(
|
final boolean scaleImageToSquareAspectRatio = player.getPrefs().getBoolean(
|
||||||
player.getContext().getString(R.string.scale_to_square_image_in_notifications_key),
|
player.getContext().getString(R.string.scale_to_square_image_in_notifications_key),
|
||||||
false);
|
false);
|
||||||
if (scaleImageToSquareAspectRatio) {
|
if (scaleImageToSquareAspectRatio) {
|
||||||
builder.setLargeIcon(getBitmapWithSquareAspectRatio(player.getThumbnail()));
|
builder.setLargeIcon(getBitmapWithSquareAspectRatio(thumbnail));
|
||||||
} else {
|
} else {
|
||||||
builder.setLargeIcon(player.getThumbnail());
|
builder.setLargeIcon(thumbnail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bitmap getBitmapWithSquareAspectRatio(final Bitmap bitmap) {
|
private Bitmap getBitmapWithSquareAspectRatio(@NonNull final Bitmap bitmap) {
|
||||||
// Find the smaller dimension and then take a center portion of the image that
|
// Find the smaller dimension and then take a center portion of the image that
|
||||||
// has that size.
|
// has that size.
|
||||||
final int w = bitmap.getWidth();
|
final int w = bitmap.getWidth();
|
||||||
|
Loading…
Reference in New Issue
Block a user