mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 15:15:51 +03:00
Check thumbnail existence and shimmering
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
45e3febb96
commit
8d5fe93192
2 changed files with 40 additions and 21 deletions
|
@ -1015,6 +1015,15 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||||
return lastTimestamp;
|
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
|
@Override
|
||||||
public void avatarGenerated(Drawable avatarDrawable, Object callContext) {
|
public void avatarGenerated(Drawable avatarDrawable, Object callContext) {
|
||||||
((ImageView) callContext).setImageDrawable(avatarDrawable);
|
((ImageView) callContext).setImageDrawable(avatarDrawable);
|
||||||
|
|
|
@ -927,12 +927,20 @@ public final class DisplayUtils {
|
||||||
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
||||||
ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId());
|
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) {
|
for (ThumbnailsCacheManager.ThumbnailGenerationTask task : asyncTasks) {
|
||||||
if (file.getRemoteId() != null && task.getImageKey() != null &&
|
if (file.getRemoteId() != null && task.getImageKey() != null &&
|
||||||
file.getRemoteId().equals(task.getImageKey())) {
|
file.getRemoteId().equals(task.getImageKey())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
||||||
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
|
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
|
||||||
|
@ -941,32 +949,34 @@ public final class DisplayUtils {
|
||||||
asyncTasks,
|
asyncTasks,
|
||||||
gridView,
|
gridView,
|
||||||
file.getRemoteId());
|
file.getRemoteId());
|
||||||
if (thumbnail == null) {
|
Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
|
||||||
Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
|
file.getFileName(),
|
||||||
file.getFileName(),
|
context,
|
||||||
context,
|
viewThemeUtils);
|
||||||
viewThemeUtils);
|
if (drawable == null) {
|
||||||
if (drawable == null) {
|
drawable = ResourcesCompat.getDrawable(context.getResources(),
|
||||||
drawable = ResourcesCompat.getDrawable(context.getResources(),
|
R.drawable.file_image,
|
||||||
R.drawable.file_image,
|
null);
|
||||||
null);
|
|
||||||
}
|
|
||||||
if (drawable == null) {
|
|
||||||
drawable = new ColorDrawable(Color.GRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
int px = ThumbnailsCacheManager.getThumbnailDimension();
|
|
||||||
thumbnail = BitmapUtils.drawableToBitmap(drawable, px, px);
|
|
||||||
}
|
}
|
||||||
|
if (drawable == null) {
|
||||||
|
drawable = new ColorDrawable(Color.GRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
int px = ThumbnailsCacheManager.getThumbnailDimension();
|
||||||
|
thumbnail = BitmapUtils.drawableToBitmap(drawable, px, px);
|
||||||
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
||||||
new ThumbnailsCacheManager.AsyncThumbnailDrawable(context.getResources(),
|
new ThumbnailsCacheManager.AsyncThumbnailDrawable(context.getResources(),
|
||||||
thumbnail, task);
|
thumbnail, task);
|
||||||
|
|
||||||
if (shimmerThumbnail != null && shimmerThumbnail.getVisibility() == View.GONE) {
|
if (shimmerThumbnail != null) {
|
||||||
if (gridView) {
|
shimmerThumbnail.postDelayed(() -> {
|
||||||
configShimmerGridImageSize(shimmerThumbnail, preferences.getGridColumns());
|
if (thumbnailView.getDrawable() == null) {
|
||||||
}
|
if (gridView) {
|
||||||
startShimmer(shimmerThumbnail, thumbnailView);
|
configShimmerGridImageSize(shimmerThumbnail, preferences.getGridColumns());
|
||||||
|
}
|
||||||
|
startShimmer(shimmerThumbnail, thumbnailView);
|
||||||
|
}
|
||||||
|
}, 100); // 100ms delay, adjust as needed
|
||||||
}
|
}
|
||||||
|
|
||||||
task.setListener(new ThumbnailsCacheManager.ThumbnailGenerationTask.Listener() {
|
task.setListener(new ThumbnailsCacheManager.ThumbnailGenerationTask.Listener() {
|
||||||
|
|
Loading…
Reference in a new issue