fix file thumbnails

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-11-15 16:58:38 +01:00 committed by Alper Öztürk
parent 866531259e
commit d137b71024

View file

@ -11,6 +11,8 @@
package com.owncloud.android.utils; package com.owncloud.android.utils;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.LayerDrawable;
import android.net.Uri; import android.net.Uri;
@ -19,6 +21,7 @@ import android.webkit.MimeTypeMap;
import com.nextcloud.android.common.ui.theme.utils.ColorRole; import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.lib.resources.files.model.ServerFileInterface; import com.owncloud.android.lib.resources.files.model.ServerFileInterface;
import com.owncloud.android.utils.theme.ViewThemeUtils; import com.owncloud.android.utils.theme.ViewThemeUtils;
@ -144,15 +147,41 @@ public final class MimeTypeUtil {
return determineIconIdByMimeTypeList(possibleMimeTypes); return determineIconIdByMimeTypeList(possibleMimeTypes);
} }
/**
* Returns a drawable representing a file or folder.
* <p>
*
* - For folders: Returns a folder icon. If an overlay is needed, it includes an overlay icon on the folder.
*
* <p>
* - For files: Returns the file's thumbnail if it exists. Otherwise, it provides a thumbnail based on the file's MIME type.
*
* @return A drawable for the file or folder.
*/
public static Drawable getOCFileIcon(OCFile file, Context context, ViewThemeUtils viewThemeUtils, boolean isAutoUpload, boolean isDarkModeActive) { public static Drawable getOCFileIcon(OCFile file, Context context, ViewThemeUtils viewThemeUtils, boolean isAutoUpload, boolean isDarkModeActive) {
Drawable result; Drawable result;
if (file.isFolder()) { if (file.isFolder()) {
Integer overlayIconId = file.getFileOverlayIconId(isAutoUpload); Integer overlayIconId = file.getFileOverlayIconId(isAutoUpload);
result = MimeTypeUtil.getFolderIcon(isDarkModeActive, overlayIconId, context, viewThemeUtils); result = MimeTypeUtil.getFolderIcon(isDarkModeActive, overlayIconId, context, viewThemeUtils);
} else {
if ((MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file)) && file.getRemoteId() != null) {
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId());
if (thumbnail != null && !file.isUpdateThumbnailNeeded()) {
if (MimeTypeUtil.isVideo(file)) {
Bitmap withOverlay = ThumbnailsCacheManager.addVideoOverlay(thumbnail, context);
result = new BitmapDrawable(context.getResources(), withOverlay);
} else {
result = new BitmapDrawable(context.getResources(), thumbnail);
}
} else { } else {
result = MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(), context, viewThemeUtils); result = MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(), context, viewThemeUtils);
} }
} else {
result = MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(), context, viewThemeUtils);
}
}
return result; return result;
} }