Merge pull request #13158 from camillo-positano/master

fix for media tab not showing thumbnails when image not in cache manager
This commit is contained in:
Andy Scherzinger 2024-06-27 10:34:25 +02:00 коммит произвёл GitHub
Родитель 38addfcdcc 92d641eabc
Коммит a37e6d228f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 61 добавлений и 48 удалений

Просмотреть файл

@ -286,58 +286,70 @@ public final class ThumbnailsCacheManager {
protected Bitmap doInBackground(Object... params) {
Bitmap thumbnail;
file = (OCFile) params[0];
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);
}
if (MimeTypeUtil.isVideo(file)) {
return ThumbnailsCacheManager.addVideoOverlay(thumbnail, MainApp.getAppContext());
} else {
return thumbnail;
}
} else {
try {
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(user.toOwnCloudAccount(),
MainApp.getAppContext());
thumbnail = doResizedImageInBackground(file, storageManager);
newImage = true;
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 thumbnail;
}
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()) {
// Thumbnail in cache?
thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
ThumbnailsCacheManager.PREFIX_RESIZED_IMAGE + file.getRemoteId());
if (thumbnail != null && !file.isUpdateThumbnailNeeded())
return getThumbnailFromCache(thumbnail);
return getThumbnailFromServerAndAddToCache(thumbnail);
}
Log_OC.d(TAG, "File cannot be previewed");
return null;
}
@Nullable
private Bitmap getThumbnailFromServerAndAddToCache(Bitmap thumbnail) {
try {
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(user.toOwnCloudAccount(),
MainApp.getAppContext());
thumbnail = doResizedImageInBackground(file, storageManager);
newImage = true;
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 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) {
if (bitmap != null && imageViewReference != null) {
final ImageView imageView = imageViewReference.get();
@ -1423,9 +1435,10 @@ public final class ThumbnailsCacheManager {
}
}
// 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);
}
}