1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-06-18 06:24:14 +00:00

Added Coil helper method

This commit is contained in:
Isira Seneviratne 2024-06-22 18:32:03 +05:30
parent 4d3b4a7b20
commit f74402bc94
4 changed files with 17 additions and 27 deletions

View File

@ -14,16 +14,12 @@ import androidx.core.app.NotificationManagerCompat
import androidx.core.app.PendingIntentCompat import androidx.core.app.PendingIntentCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.core.graphics.drawable.toBitmapOrNull
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import coil.executeBlocking
import coil.imageLoader
import coil.request.ImageRequest
import org.schabi.newpipe.R import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.stream.StreamInfoItem import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.local.feed.service.FeedUpdateInfo import org.schabi.newpipe.local.feed.service.FeedUpdateInfo
import org.schabi.newpipe.util.NavigationHelper import org.schabi.newpipe.util.NavigationHelper
import org.schabi.newpipe.util.image.ImageStrategy import org.schabi.newpipe.util.image.CoilHelper
/** /**
* Helper for everything related to show notifications about new streams to the user. * Helper for everything related to show notifications about new streams to the user.
@ -68,24 +64,15 @@ class NotificationHelper(val context: Context) {
summaryBuilder.setStyle(style) summaryBuilder.setStyle(style)
// open the channel page when clicking on the summary notification // open the channel page when clicking on the summary notification
summaryBuilder.setContentIntent( val intent = NavigationHelper
PendingIntentCompat.getActivity(
context,
data.pseudoId,
NavigationHelper
.getChannelIntent(context, data.serviceId, data.url) .getChannelIntent(context, data.serviceId, data.url)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
0, summaryBuilder.setContentIntent(
false PendingIntentCompat.getActivity(context, data.pseudoId, intent, 0, false)
)
) )
val request = ImageRequest.Builder(context) val avatarIcon =
.data(data.avatarUrl?.takeIf { ImageStrategy.shouldLoadImages() }) CoilHelper.loadBitmapBlocking(context, data.avatarUrl, R.drawable.ic_newpipe_triangle_white)
.placeholder(R.drawable.ic_newpipe_triangle_white)
.error(R.drawable.ic_newpipe_triangle_white)
.build()
val avatarIcon = context.imageLoader.executeBlocking(request).drawable?.toBitmapOrNull()
summaryBuilder.setLargeIcon(avatarIcon) summaryBuilder.setLargeIcon(avatarIcon)

View File

@ -179,7 +179,7 @@ public class SeekbarPreviewThumbnailHolder {
// Gets the bitmap within the timeout of 15 seconds imposed by default by OkHttpClient // Gets the bitmap within the timeout of 15 seconds imposed by default by OkHttpClient
// Ensure that you are not running on the main thread, otherwise this will hang // Ensure that you are not running on the main thread, otherwise this will hang
final var bitmap = CoilHelper.INSTANCE.loadBitmap(App.getApp(), url); final var bitmap = CoilHelper.INSTANCE.loadBitmapBlocking(App.getApp(), url);
if (sw != null) { if (sw != null) {
Log.d(TAG, "Download of bitmap for seekbarPreview from '" + url + "' took " Log.d(TAG, "Download of bitmap for seekbarPreview from '" + url + "' took "

View File

@ -369,7 +369,7 @@ public final class ShareUtils {
@NonNull final Context context, @NonNull final Context context,
@NonNull final String thumbnailUrl) { @NonNull final String thumbnailUrl) {
try { try {
final var bitmap = CoilHelper.INSTANCE.loadBitmap(context, thumbnailUrl); final var bitmap = CoilHelper.INSTANCE.loadBitmapBlocking(context, thumbnailUrl);
if (bitmap == null) { if (bitmap == null) {
return null; return null;
} }

View File

@ -19,12 +19,15 @@ import org.schabi.newpipe.ktx.scale
import kotlin.math.min import kotlin.math.min
object CoilHelper { object CoilHelper {
private const val TAG = "CoilHelper" private val TAG = CoilHelper::class.java.simpleName
fun loadBitmap(context: Context, url: String): Bitmap? { @JvmOverloads
val request = ImageRequest.Builder(context) fun loadBitmapBlocking(
.data(url) context: Context,
.build() url: String?,
placeholderResId: Int = 0
): Bitmap? {
val request = getImageRequest(context, url, placeholderResId).build()
return context.imageLoader.executeBlocking(request).drawable?.toBitmapOrNull() return context.imageLoader.executeBlocking(request).drawable?.toBitmapOrNull()
} }