Skip to content

Commit

Permalink
Upgrade thumbnails quality even further, allow shows without posters …
Browse files Browse the repository at this point in the history
…to display only covers
  • Loading branch information
astarivi committed Aug 6, 2023
1 parent 669d412 commit 609cec4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,60 +128,55 @@ public void fetchImages() {
String coverUrl = anime.getThumbnailUrl(true);
String posterUrl = anime.getThumbnailUrl(false);

if (posterUrl == null) {
// Nothing to display
if (posterUrl != null) {
Glide.with(binding.getRoot().getContext())
.load(posterUrl)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
if (coverUrl != null || !(resource instanceof BitmapDrawable)) return false;

Palette.from(
// Welcome to casting hell, again
((BitmapDrawable) resource).getBitmap()
).generate(palette -> {
if (palette == null) return;

binding.getRoot().post(() -> {
try {
binding.imageCover.setImageDrawable(null);
binding.imageCover.setBackgroundColor(palette.getMutedColor(
Color.parseColor("#9240aa")
));
} catch(Exception ignored) {
}
});
});
return false;
}
})
.placeholder(R.drawable.ic_general_placeholder)
.into(binding.imagePoster);
} else {
binding.imagePoster.setImageResource(R.drawable.ic_general_placeholder);
binding.imageCover.setImageResource(R.drawable.ic_general_placeholder);
return;
}

if (coverUrl == null) {
if (coverUrl != null) {
Glide.with(binding.getRoot().getContext())
.load(coverUrl)
// Fixes pixel level imperfections. This could be profiled to see if it's worth it.
// Profiled 2023-8-6, it's absolutely worth it.
.centerCrop()
.placeholder(R.drawable.ic_general_placeholder)
.into(binding.imageCover);
} else {
binding.imageCover.setImageResource(R.drawable.ic_general_placeholder);
}

Glide.with(binding.getRoot().getContext())
.load(posterUrl)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
if (coverUrl != null || !(resource instanceof BitmapDrawable)) return false;

Palette.from(
// Welcome to casting hell, again
((BitmapDrawable) resource).getBitmap()
).generate(palette -> {
if (palette == null) return;

binding.getRoot().post(() -> {
try {
binding.imageCover.setImageDrawable(null);
binding.imageCover.setBackgroundColor(palette.getMutedColor(
Color.parseColor("#9240aa")
));
} catch(Exception ignored) {
}
});
});
return false;
}
})
.placeholder(R.drawable.ic_general_placeholder)
.into(binding.imagePoster);

if (coverUrl == null) return;

// Handle cover image
Glide.with(binding.getRoot().getContext())
.load(coverUrl)
// Fixes pixel level imperfections. This could be profiled to see if it's worth it.
.centerCrop()
.placeholder(R.drawable.ic_general_placeholder)
.into(binding.imageCover);
}

public void unloadImages() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private void continueInitialization() {
posterUrl = anime.getImageUrlFromSize(ImageSize.TINY, false);
} else {
coverUrl = anime.getImageUrlFromSizeWithFallback(ImageSize.ORIGINAL, true);
posterUrl = anime.getImageUrlFromSizeWithFallback(ImageSize.MEDIUM, false);
posterUrl = anime.getImageUrlFromSizeWithFallback(ImageSize.ORIGINAL, false);
}

if (coverUrl != null)
Expand Down

0 comments on commit 609cec4

Please sign in to comment.