Skip to content

Commit ff35619

Browse files
Merge pull request nextcloud#13487 from nextcloud/bugfix/check-shimmering-effect
BugFix - Check Thumbnail Existence and Shimmering
2 parents 87b2e81 + 79481fc commit ff35619

2 files changed

Lines changed: 40 additions & 21 deletions

File tree

app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,15 @@ public long getLastTimestamp() {
10151015
return lastTimestamp;
10161016
}
10171017

1018+
@Override
1019+
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
1020+
super.onViewRecycled(holder);
1021+
if (holder instanceof ListGridImageViewHolder listGridImageViewHolder) {
1022+
LoaderImageView thumbnailShimmer = listGridImageViewHolder.getShimmerThumbnail();
1023+
DisplayUtils.stopShimmer(thumbnailShimmer, listGridImageViewHolder.getThumbnail());
1024+
}
1025+
}
1026+
10181027
@Override
10191028
public void avatarGenerated(Drawable avatarDrawable, Object callContext) {
10201029
((ImageView) callContext).setImageDrawable(avatarDrawable);

app/src/main/java/com/owncloud/android/utils/DisplayUtils.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -927,12 +927,20 @@ private static void generateNewThumbnail(OCFile file,
927927
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
928928
ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId());
929929

930+
if (thumbnail != null) {
931+
// If thumbnail is already in cache, display it immediately
932+
thumbnailView.setImageBitmap(thumbnail);
933+
stopShimmer(shimmerThumbnail, thumbnailView);
934+
return;
935+
}
936+
930937
for (ThumbnailsCacheManager.ThumbnailGenerationTask task : asyncTasks) {
931938
if (file.getRemoteId() != null && task.getImageKey() != null &&
932939
file.getRemoteId().equals(task.getImageKey())) {
933940
return;
934941
}
935942
}
943+
936944
try {
937945
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
938946
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
@@ -941,32 +949,34 @@ private static void generateNewThumbnail(OCFile file,
941949
asyncTasks,
942950
gridView,
943951
file.getRemoteId());
944-
if (thumbnail == null) {
945-
Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
946-
file.getFileName(),
947-
context,
948-
viewThemeUtils);
949-
if (drawable == null) {
950-
drawable = ResourcesCompat.getDrawable(context.getResources(),
951-
R.drawable.file_image,
952-
null);
953-
}
954-
if (drawable == null) {
955-
drawable = new ColorDrawable(Color.GRAY);
956-
}
957-
958-
int px = ThumbnailsCacheManager.getThumbnailDimension();
959-
thumbnail = BitmapUtils.drawableToBitmap(drawable, px, px);
952+
Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
953+
file.getFileName(),
954+
context,
955+
viewThemeUtils);
956+
if (drawable == null) {
957+
drawable = ResourcesCompat.getDrawable(context.getResources(),
958+
R.drawable.file_image,
959+
null);
960+
}
961+
if (drawable == null) {
962+
drawable = new ColorDrawable(Color.GRAY);
960963
}
964+
965+
int px = ThumbnailsCacheManager.getThumbnailDimension();
966+
thumbnail = BitmapUtils.drawableToBitmap(drawable, px, px);
961967
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
962968
new ThumbnailsCacheManager.AsyncThumbnailDrawable(context.getResources(),
963969
thumbnail, task);
964970

965-
if (shimmerThumbnail != null && shimmerThumbnail.getVisibility() == View.GONE) {
966-
if (gridView) {
967-
configShimmerGridImageSize(shimmerThumbnail, preferences.getGridColumns());
968-
}
969-
startShimmer(shimmerThumbnail, thumbnailView);
971+
if (shimmerThumbnail != null) {
972+
shimmerThumbnail.postDelayed(() -> {
973+
if (thumbnailView.getDrawable() == null) {
974+
if (gridView) {
975+
configShimmerGridImageSize(shimmerThumbnail, preferences.getGridColumns());
976+
}
977+
startShimmer(shimmerThumbnail, thumbnailView);
978+
}
979+
}, 100);
970980
}
971981

972982
task.setListener(new ThumbnailsCacheManager.ThumbnailGenerationTask.Listener() {

0 commit comments

Comments
 (0)