@@ -6,7 +6,6 @@ import android.app.PendingIntent
66import android.content.Context
77import android.content.Intent
88import android.graphics.Bitmap
9- import android.graphics.drawable.Drawable
109import android.net.Uri
1110import android.os.Build
1211import android.provider.Settings
@@ -15,21 +14,22 @@ import androidx.core.app.NotificationManagerCompat
1514import androidx.core.app.PendingIntentCompat
1615import androidx.core.content.ContextCompat
1716import androidx.core.content.getSystemService
17+ import androidx.core.graphics.drawable.toBitmapOrNull
1818import androidx.preference.PreferenceManager
19- import com.squareup.picasso.Picasso
20- import com.squareup.picasso.Target
19+ import coil.executeBlocking
20+ import coil.imageLoader
21+ import coil.request.ImageRequest
2122import org.schabi.newpipe.R
2223import org.schabi.newpipe.extractor.stream.StreamInfoItem
2324import org.schabi.newpipe.local.feed.service.FeedUpdateInfo
2425import org.schabi.newpipe.util.NavigationHelper
25- import org.schabi.newpipe.util.image.PicassoHelper
26+ import org.schabi.newpipe.util.image.ImageStrategy
2627
2728/* *
2829 * Helper for everything related to show notifications about new streams to the user.
2930 */
3031class NotificationHelper (val context : Context ) {
3132 private val manager = NotificationManagerCompat .from(context)
32- private val iconLoadingTargets = ArrayList <Target >()
3333
3434 /* *
3535 * Show notifications for new streams from a single channel. The individual notifications are
@@ -80,39 +80,20 @@ class NotificationHelper(val context: Context) {
8080 )
8181 )
8282
83- // a Target is like a listener for image loading events
84- val target = object : Target {
85- override fun onBitmapLoaded (bitmap : Bitmap , from : Picasso .LoadedFrom ) {
86- // set channel icon only if there is actually one (for Android versions < 7.0)
87- summaryBuilder.setLargeIcon(bitmap)
88-
89- // Show individual stream notifications, set channel icon only if there is actually
90- // one
91- showStreamNotifications(newStreams, data.serviceId, bitmap)
92- // Show summary notification
93- manager.notify(data.pseudoId, summaryBuilder.build())
94-
95- iconLoadingTargets.remove(this ) // allow it to be garbage-collected
96- }
97-
98- override fun onBitmapFailed (e : Exception , errorDrawable : Drawable ) {
99- // Show individual stream notifications
100- showStreamNotifications(newStreams, data.serviceId, null )
101- // Show summary notification
102- manager.notify(data.pseudoId, summaryBuilder.build())
103- iconLoadingTargets.remove(this ) // allow it to be garbage-collected
104- }
105-
106- override fun onPrepareLoad (placeHolderDrawable : Drawable ) {
107- // Nothing to do
108- }
109- }
83+ val request = ImageRequest .Builder (context)
84+ .data(data.avatarUrl?.takeIf { ImageStrategy .shouldLoadImages() })
85+ .placeholder(R .drawable.ic_newpipe_triangle_white)
86+ .error(R .drawable.ic_newpipe_triangle_white)
87+ .build()
88+ val avatarIcon = context.imageLoader.executeBlocking(request).drawable?.toBitmapOrNull()
11089
111- // add the target to the list to hold a strong reference and prevent it from being garbage
112- // collected, since Picasso only holds weak references to targets
113- iconLoadingTargets.add(target)
90+ summaryBuilder.setLargeIcon(avatarIcon)
11491
115- PicassoHelper .loadNotificationIcon(data.avatarUrl).into(target)
92+ // Show individual stream notifications, set channel icon only if there is actually
93+ // one
94+ showStreamNotifications(newStreams, data.serviceId, avatarIcon)
95+ // Show summary notification
96+ manager.notify(data.pseudoId, summaryBuilder.build())
11697 }
11798
11899 private fun showStreamNotifications (
0 commit comments