From 2c62bb7e6d2d19c6ca7cc9bbad1ba6e9de4b5af0 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 29 Aug 2024 12:29:19 +0200 Subject: [PATCH 1/2] Check thumbnail existence and shimmering Signed-off-by: alperozturk --- .../android/ui/adapter/OCFileListAdapter.java | 9 ++++ .../owncloud/android/utils/DisplayUtils.java | 52 +++++++++++-------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index 3490e87b3f43..9c5dc23e862d 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -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); diff --git a/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java b/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java index 6a8d207ae8a6..cc35cf6d76e9 100644 --- a/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java +++ b/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java @@ -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, @@ -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); // 100ms delay, adjust as needed } task.setListener(new ThumbnailsCacheManager.ThumbnailGenerationTask.Listener() { From ede6c9e03a96c3306758c5890b460901a9935fb1 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 29 Aug 2024 12:31:00 +0200 Subject: [PATCH 2/2] Delete comment Signed-off-by: alperozturk --- app/src/main/java/com/owncloud/android/utils/DisplayUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java b/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java index cc35cf6d76e9..106916fb6e93 100644 --- a/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java +++ b/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java @@ -976,7 +976,7 @@ private static void generateNewThumbnail(OCFile file, } startShimmer(shimmerThumbnail, thumbnailView); } - }, 100); // 100ms delay, adjust as needed + }, 100); } task.setListener(new ThumbnailsCacheManager.ThumbnailGenerationTask.Listener() {