From 243820bf4f160733a924a63292d5aeef4b4e0934 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Mon, 22 Jul 2024 16:05:36 +0530 Subject: [PATCH] Remove unnecessary Optional use --- .../external_communication/ShareUtils.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java b/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java index f48e99d94cc..9008a213deb 100644 --- a/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java @@ -30,7 +30,6 @@ import java.nio.file.Files; import java.util.Collections; import java.util.List; -import java.util.Optional; import coil.Coil; import coil.disk.DiskCache; @@ -381,17 +380,19 @@ private static ClipData generateClipDataForImagePreview( final var loader = Coil.imageLoader(context); final var value = loader.getMemoryCache() .get(new MemoryCache.Key(thumbnailUrl, Collections.emptyMap())); - final var cachedBitmap = Optional.ofNullable(value) - .map(MemoryCache.Value::getBitmap) - .orElseGet(() -> { - try (var snapshot = loader.getDiskCache().openSnapshot(thumbnailUrl)) { - if (snapshot != null) { - return BitmapFactory.decodeFile(snapshot.getData().toString()); - } else { - return null; - } - } - }); + + final Bitmap cachedBitmap; + if (value != null) { + cachedBitmap = value.getBitmap(); + } else { + try (var snapshot = loader.getDiskCache().openSnapshot(thumbnailUrl)) { + if (snapshot != null) { + cachedBitmap = BitmapFactory.decodeFile(snapshot.getData().toString()); + } else { + cachedBitmap = null; + } + } + } if (cachedBitmap == null) { return null;