From 158865a50053bbf8c9ca785ec8c423662832fa19 Mon Sep 17 00:00:00 2001 From: Prathamesh More Date: Tue, 28 Dec 2021 14:14:07 +0530 Subject: [PATCH] [Notification] Set default notification icon for failed Image loads or for Songs with no Cover --- .../monkey/retromusic/service/MusicService.java | 8 ++++---- ...ionOreo.kt => PlayingNotificationClassic.kt} | 4 ++-- ...tionImpl.kt => PlayingNotificationImpl24.kt} | 17 +++++++++++++---- 3 files changed, 19 insertions(+), 10 deletions(-) rename app/src/main/java/code/name/monkey/retromusic/service/notification/{PlayingNotificationOreo.kt => PlayingNotificationClassic.kt} (99%) rename app/src/main/java/code/name/monkey/retromusic/service/notification/{PlayingNotificationImpl.kt => PlayingNotificationImpl24.kt} (93%) diff --git a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java index 651bb605f..6399e8fdd 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java +++ b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java @@ -99,8 +99,8 @@ import code.name.monkey.retromusic.providers.HistoryStore; import code.name.monkey.retromusic.providers.MusicPlaybackQueueStore; import code.name.monkey.retromusic.providers.SongPlayCountStore; import code.name.monkey.retromusic.service.notification.PlayingNotification; -import code.name.monkey.retromusic.service.notification.PlayingNotificationImpl; -import code.name.monkey.retromusic.service.notification.PlayingNotificationOreo; +import code.name.monkey.retromusic.service.notification.PlayingNotificationClassic; +import code.name.monkey.retromusic.service.notification.PlayingNotificationImpl24; import code.name.monkey.retromusic.service.playback.Playback; import code.name.monkey.retromusic.util.MusicUtil; import code.name.monkey.retromusic.util.PackageValidator; @@ -781,9 +781,9 @@ public class MusicService extends MediaBrowserServiceCompat public void initNotification() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !PreferenceUtil.INSTANCE.isClassicNotification()) { - playingNotification = PlayingNotificationImpl.Companion.from(this, notificationManager, mediaSession); + playingNotification = PlayingNotificationImpl24.Companion.from(this, notificationManager, mediaSession); } else { - playingNotification = PlayingNotificationOreo.Companion.from(this, notificationManager); + playingNotification = PlayingNotificationClassic.Companion.from(this, notificationManager); } } diff --git a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.kt b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationClassic.kt similarity index 99% rename from app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.kt rename to app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationClassic.kt index a314ca2e5..aad278f36 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.kt +++ b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationClassic.kt @@ -50,7 +50,7 @@ import com.bumptech.glide.request.transition.Transition * @author Hemanth S (h4h13). */ @SuppressLint("RestrictedApi") -class PlayingNotificationOreo( +class PlayingNotificationClassic( val context: Context ) : PlayingNotification(context) { @@ -313,7 +313,7 @@ class PlayingNotificationOreo( if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { createNotificationChannel(context, notificationManager) } - return PlayingNotificationOreo(context) + return PlayingNotificationClassic(context) } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.kt similarity index 93% rename from app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt rename to app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.kt index 8f0156f8d..d9373757e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt +++ b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.kt @@ -20,6 +20,7 @@ import android.app.PendingIntent import android.content.ComponentName import android.content.Context import android.content.Intent +import android.graphics.BitmapFactory import android.graphics.Color import android.graphics.drawable.Drawable import android.os.Build @@ -47,7 +48,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @SuppressLint("RestrictedApi") -class PlayingNotificationImpl( +class PlayingNotificationImpl24( val context: Context, mediaSessionToken: MediaSessionCompat.Token ) : PlayingNotification(context) { @@ -154,12 +155,20 @@ class PlayingNotificationImpl( override fun onLoadFailed(errorDrawable: Drawable?) { super.onLoadFailed(errorDrawable) - setLargeIcon(null) + setLargeIcon( + BitmapFactory.decodeResource( + context.resources, + R.drawable.default_audio_art + ) + ) onUpdate() } override fun onLoadCleared(placeholder: Drawable?) { - setLargeIcon(null) + setLargeIcon(BitmapFactory.decodeResource( + context.resources, + R.drawable.default_audio_art + )) onUpdate() } }) @@ -221,7 +230,7 @@ class PlayingNotificationImpl( if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { createNotificationChannel(context, notificationManager) } - return PlayingNotificationImpl(context, mediaSession.sessionToken) + return PlayingNotificationImpl24(context, mediaSession.sessionToken) } } } \ No newline at end of file