Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.30] BugFix - Check Thumbnail Existence and Shimmering #13539

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,15 @@ public long getLastTimestamp() {
return lastTimestamp;
}

@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);
if (holder instanceof ListGridImageViewHolder listGridImageViewHolder) {
LoaderImageView thumbnailShimmer = listGridImageViewHolder.getShimmerThumbnail();
DisplayUtils.stopShimmer(thumbnailShimmer, listGridImageViewHolder.getThumbnail());
}
}

@Override
public void avatarGenerated(Drawable avatarDrawable, Object callContext) {
((ImageView) callContext).setImageDrawable(avatarDrawable);
Expand Down
52 changes: 31 additions & 21 deletions app/src/main/java/com/owncloud/android/utils/DisplayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -927,12 +927,20 @@ private static void generateNewThumbnail(OCFile file,
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId());

if (thumbnail != null) {
// If thumbnail is already in cache, display it immediately
thumbnailView.setImageBitmap(thumbnail);
stopShimmer(shimmerThumbnail, thumbnailView);
return;
}

for (ThumbnailsCacheManager.ThumbnailGenerationTask task : asyncTasks) {
if (file.getRemoteId() != null && task.getImageKey() != null &&
file.getRemoteId().equals(task.getImageKey())) {
return;
}
}

try {
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
Expand All @@ -941,32 +949,34 @@ private static void generateNewThumbnail(OCFile file,
asyncTasks,
gridView,
file.getRemoteId());
if (thumbnail == null) {
Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
file.getFileName(),
context,
viewThemeUtils);
if (drawable == null) {
drawable = ResourcesCompat.getDrawable(context.getResources(),
R.drawable.file_image,
null);
}
if (drawable == null) {
drawable = new ColorDrawable(Color.GRAY);
}

int px = ThumbnailsCacheManager.getThumbnailDimension();
thumbnail = BitmapUtils.drawableToBitmap(drawable, px, px);
Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
file.getFileName(),
context,
viewThemeUtils);
if (drawable == null) {
drawable = ResourcesCompat.getDrawable(context.getResources(),
R.drawable.file_image,
null);
}
if (drawable == null) {
drawable = new ColorDrawable(Color.GRAY);
}

int px = ThumbnailsCacheManager.getThumbnailDimension();
thumbnail = BitmapUtils.drawableToBitmap(drawable, px, px);
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncThumbnailDrawable(context.getResources(),
thumbnail, task);

if (shimmerThumbnail != null && shimmerThumbnail.getVisibility() == View.GONE) {
if (gridView) {
configShimmerGridImageSize(shimmerThumbnail, preferences.getGridColumns());
}
startShimmer(shimmerThumbnail, thumbnailView);
if (shimmerThumbnail != null) {
shimmerThumbnail.postDelayed(() -> {
if (thumbnailView.getDrawable() == null) {
if (gridView) {
configShimmerGridImageSize(shimmerThumbnail, preferences.getGridColumns());
}
startShimmer(shimmerThumbnail, thumbnailView);
}
}, 100);
}

task.setListener(new ThumbnailsCacheManager.ThumbnailGenerationTask.Listener() {
Expand Down
Loading