Skip to content

Commit

Permalink
Remove unnecessary Optional use
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Jul 22, 2024
1 parent 7d92a1d commit 243820b
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 243820b

Please sign in to comment.