Skip to content

Commit 7fbef35

Browse files
committed
Unify onThumbnailLoaded calls to ensure UIs always updated
1 parent e6391a8 commit 7fbef35

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -765,17 +765,15 @@ public void onBitmapLoaded(final Bitmap bitmap, final Picasso.LoadedFrom from) {
765765
+ " -> " + bitmap.getWidth() + "x" + bitmap.getHeight() + "], from = ["
766766
+ from + "]");
767767
}
768-
currentThumbnail = bitmap;
769768
// there is a new thumbnail, so e.g. the end screen thumbnail needs to change, too.
770-
UIs.call(playerUi -> playerUi.onThumbnailLoaded(bitmap));
769+
onThumbnailLoaded(bitmap);
771770
}
772771

773772
@Override
774773
public void onBitmapFailed(final Exception e, final Drawable errorDrawable) {
775774
Log.e(TAG, "Thumbnail - onBitmapFailed() called", e);
776-
currentThumbnail = null;
777775
// there is a new thumbnail, so e.g. the end screen thumbnail needs to change, too.
778-
UIs.call(playerUi -> playerUi.onThumbnailLoaded(null));
776+
onThumbnailLoaded(null);
779777
}
780778

781779
@Override
@@ -798,7 +796,7 @@ private void loadCurrentThumbnail(final String url) {
798796

799797
// Unset currentThumbnail, since it is now outdated. This ensures it is not used in media
800798
// session metadata while the new thumbnail is being loaded by Picasso.
801-
currentThumbnail = null;
799+
onThumbnailLoaded(null);
802800
if (isNullOrEmpty(url)) {
803801
return;
804802
}
@@ -813,6 +811,16 @@ private void cancelLoadingCurrentThumbnail() {
813811
// cancel the Picasso job associated with the player thumbnail, if any
814812
PicassoHelper.cancelTag(PICASSO_PLAYER_THUMBNAIL_TAG);
815813
}
814+
815+
private void onThumbnailLoaded(@Nullable final Bitmap bitmap) {
816+
// Avoid useless thumbnail updates, if the thumbnail has not actually changed. Based on the
817+
// thumbnail loading code, this if would be skipped only when both bitmaps are `null`, since
818+
// onThumbnailLoaded won't be called twice with the same nonnull bitmap by Picasso's target.
819+
if (currentThumbnail != bitmap) {
820+
currentThumbnail = bitmap;
821+
UIs.call(playerUi -> playerUi.onThumbnailLoaded(bitmap));
822+
}
823+
}
816824
//endregion
817825

818826

0 commit comments

Comments
 (0)