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

fix for media tab not showing thumbnails when image not in cache manager #13158

Merged
merged 4 commits into from
Jun 27, 2024
Merged
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 @@ -286,56 +286,68 @@ public String getImageKey() {
protected Bitmap doInBackground(Object... params) {
Bitmap thumbnail;

file = (OCFile) params[0];
if (params == null || params.length == 0 || !(params[0] instanceof OCFile)) {
Log_OC.d(TAG, "Downloaded file is null or is not an instance of OCFile");
return null;
}

file = (OCFile) params[0];

if (file.getRemoteId() != null && file.isPreviewAvailable()) {
if (file.getRemoteId() != null || file.isPreviewAvailable()) {
// Thumbnail in cache?
thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
ThumbnailsCacheManager.PREFIX_RESIZED_IMAGE + file.getRemoteId()
);

if (thumbnail != null && !file.isUpdateThumbnailNeeded()) {
Float size = (float) ThumbnailsCacheManager.getThumbnailDimension();

// resized dimensions
ImageDimension imageDimension = file.getImageDimension();
if (imageDimension == null ||
imageDimension.getWidth() != size ||
imageDimension.getHeight() != size) {
file.setImageDimension(new ImageDimension(thumbnail.getWidth(), thumbnail.getHeight()));
storageManager.saveFile(file);
}
ThumbnailsCacheManager.PREFIX_RESIZED_IMAGE + file.getRemoteId());

if (MimeTypeUtil.isVideo(file)) {
return ThumbnailsCacheManager.addVideoOverlay(thumbnail, MainApp.getAppContext());
} else {
return thumbnail;
}
} else {
try {
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(user.toOwnCloudAccount(),
MainApp.getAppContext());
if (thumbnail != null && !file.isUpdateThumbnailNeeded())
return getThumbnailFromCache(thumbnail);

thumbnail = doResizedImageInBackground(file, storageManager);
newImage = true;
return getThumbnailFromServerAndAddToCache(thumbnail);
}

if (MimeTypeUtil.isVideo(file) && thumbnail != null) {
thumbnail = addVideoOverlay(thumbnail, MainApp.getAppContext());
}
Log_OC.d(TAG, "File cannot be previewed");
return null;
}

} catch (OutOfMemoryError oome) {
Log_OC.e(TAG, "Out of memory");
} catch (Throwable t) {
// the app should never break due to a problem with thumbnails
Log_OC.e(TAG, "Generation of gallery image for " + file + " failed", t);
}
@Nullable
private Bitmap getThumbnailFromServerAndAddToCache(Bitmap thumbnail) {
try {
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(user.toOwnCloudAccount(),
MainApp.getAppContext());

thumbnail = doResizedImageInBackground(file, storageManager);
newImage = true;

return thumbnail;
if (MimeTypeUtil.isVideo(file) && thumbnail != null) {
thumbnail = addVideoOverlay(thumbnail, MainApp.getAppContext());
}

} catch (OutOfMemoryError oome) {
Log_OC.e(TAG, "Out of memory");
} catch (Throwable t) {
// the app should never break due to a problem with thumbnails
Log_OC.e(TAG, "Generation of gallery image for " + file + " failed", t);
}

return null;
return thumbnail;
}

private Bitmap getThumbnailFromCache(Bitmap thumbnail) {
float size = (float) ThumbnailsCacheManager.getThumbnailDimension();

// resized dimensions
ImageDimension imageDimension = file.getImageDimension();
if (imageDimension == null ||
imageDimension.getWidth() != size ||
imageDimension.getHeight() != size) {
file.setImageDimension(new ImageDimension(thumbnail.getWidth(), thumbnail.getHeight()));
storageManager.saveFile(file);
}

if (MimeTypeUtil.isVideo(file)) {
return ThumbnailsCacheManager.addVideoOverlay(thumbnail, MainApp.getAppContext());
} else {
return thumbnail;
}
}

protected void onPostExecute(Bitmap bitmap) {
Expand Down Expand Up @@ -1423,9 +1435,10 @@ private static Bitmap doResizedImageInBackground(OCFile file, FileDataStorageMan
}
}

// resized dimensions
// resized dimensions and set update thumbnail needed to false to prevent rendering loop
if (thumbnail != null) {
file.setImageDimension(new ImageDimension(thumbnail.getWidth(), thumbnail.getHeight()));
file.setUpdateThumbnailNeeded(false);
storageManager.saveFile(file);
}
}
Expand Down
Loading