[Notification] Set default notification icon for failed Image loads or for Songs with no Cover

This commit is contained in:
Prathamesh More 2021-12-28 14:14:07 +05:30
parent 22451b3cf1
commit 158865a500
3 changed files with 19 additions and 10 deletions

View file

@ -99,8 +99,8 @@ import code.name.monkey.retromusic.providers.HistoryStore;
import code.name.monkey.retromusic.providers.MusicPlaybackQueueStore; import code.name.monkey.retromusic.providers.MusicPlaybackQueueStore;
import code.name.monkey.retromusic.providers.SongPlayCountStore; import code.name.monkey.retromusic.providers.SongPlayCountStore;
import code.name.monkey.retromusic.service.notification.PlayingNotification; import code.name.monkey.retromusic.service.notification.PlayingNotification;
import code.name.monkey.retromusic.service.notification.PlayingNotificationImpl; import code.name.monkey.retromusic.service.notification.PlayingNotificationClassic;
import code.name.monkey.retromusic.service.notification.PlayingNotificationOreo; import code.name.monkey.retromusic.service.notification.PlayingNotificationImpl24;
import code.name.monkey.retromusic.service.playback.Playback; import code.name.monkey.retromusic.service.playback.Playback;
import code.name.monkey.retromusic.util.MusicUtil; import code.name.monkey.retromusic.util.MusicUtil;
import code.name.monkey.retromusic.util.PackageValidator; import code.name.monkey.retromusic.util.PackageValidator;
@ -781,9 +781,9 @@ public class MusicService extends MediaBrowserServiceCompat
public void initNotification() { public void initNotification() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& !PreferenceUtil.INSTANCE.isClassicNotification()) { && !PreferenceUtil.INSTANCE.isClassicNotification()) {
playingNotification = PlayingNotificationImpl.Companion.from(this, notificationManager, mediaSession); playingNotification = PlayingNotificationImpl24.Companion.from(this, notificationManager, mediaSession);
} else { } else {
playingNotification = PlayingNotificationOreo.Companion.from(this, notificationManager); playingNotification = PlayingNotificationClassic.Companion.from(this, notificationManager);
} }
} }

View file

@ -50,7 +50,7 @@ import com.bumptech.glide.request.transition.Transition
* @author Hemanth S (h4h13). * @author Hemanth S (h4h13).
*/ */
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
class PlayingNotificationOreo( class PlayingNotificationClassic(
val context: Context val context: Context
) : PlayingNotification(context) { ) : PlayingNotification(context) {
@ -313,7 +313,7 @@ class PlayingNotificationOreo(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(context, notificationManager) createNotificationChannel(context, notificationManager)
} }
return PlayingNotificationOreo(context) return PlayingNotificationClassic(context)
} }
} }
} }

View file

@ -20,6 +20,7 @@ import android.app.PendingIntent
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.BitmapFactory
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
@ -47,7 +48,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
class PlayingNotificationImpl( class PlayingNotificationImpl24(
val context: Context, val context: Context,
mediaSessionToken: MediaSessionCompat.Token mediaSessionToken: MediaSessionCompat.Token
) : PlayingNotification(context) { ) : PlayingNotification(context) {
@ -154,12 +155,20 @@ class PlayingNotificationImpl(
override fun onLoadFailed(errorDrawable: Drawable?) { override fun onLoadFailed(errorDrawable: Drawable?) {
super.onLoadFailed(errorDrawable) super.onLoadFailed(errorDrawable)
setLargeIcon(null) setLargeIcon(
BitmapFactory.decodeResource(
context.resources,
R.drawable.default_audio_art
)
)
onUpdate() onUpdate()
} }
override fun onLoadCleared(placeholder: Drawable?) { override fun onLoadCleared(placeholder: Drawable?) {
setLargeIcon(null) setLargeIcon(BitmapFactory.decodeResource(
context.resources,
R.drawable.default_audio_art
))
onUpdate() onUpdate()
} }
}) })
@ -221,7 +230,7 @@ class PlayingNotificationImpl(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(context, notificationManager) createNotificationChannel(context, notificationManager)
} }
return PlayingNotificationImpl(context, mediaSession.sessionToken) return PlayingNotificationImpl24(context, mediaSession.sessionToken)
} }
} }
} }