mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 13:15:35 +03:00
Handle thumbnail generation for invalid local path
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
7e0e59fadb
commit
ce41617086
2 changed files with 57 additions and 29 deletions
|
@ -485,9 +485,8 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|||
&& fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId() != null &&
|
||||
item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED) {
|
||||
// Thumbnail in Cache?
|
||||
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
||||
String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId())
|
||||
);
|
||||
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId()));
|
||||
|
||||
if (thumbnail != null && !fakeFileToCheatThumbnailsCacheManagerInterface.isUpdateThumbnailNeeded()) {
|
||||
itemViewHolder.binding.thumbnail.setImageBitmap(thumbnail);
|
||||
} else {
|
||||
|
@ -520,21 +519,17 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|||
}
|
||||
|
||||
if ("image/png".equals(item.getMimeType())) {
|
||||
itemViewHolder.binding.thumbnail.setBackgroundColor(parentActivity.getResources()
|
||||
.getColor(R.color.bg_default));
|
||||
itemViewHolder.binding.thumbnail.setBackgroundColor(parentActivity.getResources().getColor(R.color.bg_default));
|
||||
}
|
||||
|
||||
|
||||
} else if (MimeTypeUtil.isImage(fakeFileToCheatThumbnailsCacheManagerInterface)) {
|
||||
File file = new File(item.getLocalPath());
|
||||
// Thumbnail in Cache?
|
||||
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
||||
String.valueOf(file.hashCode()));
|
||||
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(String.valueOf(file.hashCode()));
|
||||
|
||||
if (thumbnail != null) {
|
||||
itemViewHolder.binding.thumbnail.setImageBitmap(thumbnail);
|
||||
} else {
|
||||
// generate new Thumbnail
|
||||
if (allowedToCreateNewThumbnail) {
|
||||
} else if (allowedToCreateNewThumbnail) {
|
||||
getThumbnailFromFileTypeAndSetIcon(item.getLocalPath(), itemViewHolder);
|
||||
|
||||
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
||||
new ThumbnailsCacheManager.ThumbnailGenerationTask(itemViewHolder.binding.thumbnail);
|
||||
|
||||
|
@ -548,19 +543,27 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|||
new ThumbnailsCacheManager.AsyncThumbnailDrawable(parentActivity.getResources(), thumbnail,
|
||||
task);
|
||||
|
||||
itemViewHolder.binding.thumbnail.setImageDrawable(asyncDrawable);
|
||||
task.execute(new ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file, null));
|
||||
Log_OC.v(TAG, "Executing task to generate a new thumbnail");
|
||||
task.setListener(new ThumbnailsCacheManager.ThumbnailGenerationTask.Listener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
itemViewHolder.binding.thumbnail.setImageDrawable(asyncDrawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
getThumbnailFromFileTypeAndSetIcon(item.getLocalPath(), itemViewHolder);
|
||||
}
|
||||
});
|
||||
|
||||
Log_OC.v(TAG, "Executing task to generate a new thumbnail");
|
||||
}
|
||||
|
||||
if ("image/png".equalsIgnoreCase(item.getMimeType())) {
|
||||
itemViewHolder.binding.thumbnail.setBackgroundColor(parentActivity.getResources()
|
||||
.getColor(R.color.bg_default));
|
||||
itemViewHolder.binding.thumbnail.setBackgroundColor(parentActivity.getResources().getColor(R.color.bg_default));
|
||||
}
|
||||
} else {
|
||||
if (optionalUser.isPresent()) {
|
||||
final User user = optionalUser.get();
|
||||
final Drawable icon = MimeTypeUtil.getFileTypeIcon(item.getMimeType(),
|
||||
fileName,
|
||||
parentActivity,
|
||||
|
@ -570,6 +573,12 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|||
}
|
||||
}
|
||||
|
||||
private void getThumbnailFromFileTypeAndSetIcon(String localPath, ItemViewHolder itemViewHolder) {
|
||||
Drawable drawable = MimeTypeUtil.getIcon(localPath, parentActivity, viewThemeUtils);
|
||||
if (drawable == null) return;
|
||||
itemViewHolder.binding.thumbnail.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
private boolean checkAndOpenConflictResolutionDialog(User user,
|
||||
ItemViewHolder itemViewHolder,
|
||||
OCUpload item,
|
||||
|
|
|
@ -17,6 +17,7 @@ import android.net.Uri;
|
|||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
|
||||
import com.nextcloud.utils.autoRename.AutoRename;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.resources.files.model.ServerFileInterface;
|
||||
|
@ -106,6 +107,23 @@ public final class MimeTypeUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static Drawable getIcon(String localPath, Context context, ViewThemeUtils viewThemeUtils) {
|
||||
if (context == null) return null;
|
||||
|
||||
String mimeType = getMimeTypeFromPath(localPath);
|
||||
List<String> possibleMimeTypes = Collections.singletonList(mimeType);
|
||||
int iconId = determineIconIdByMimeTypeList(possibleMimeTypes);
|
||||
|
||||
Drawable result = ContextCompat.getDrawable(context, iconId);
|
||||
if (result == null) return null;
|
||||
|
||||
if (R.drawable.file_zip == iconId) {
|
||||
viewThemeUtils.platform.tintDrawable(context, result, ColorRole.PRIMARY);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resource identifier of an image to use as icon associated to a known MIME type.
|
||||
*
|
||||
|
@ -317,6 +335,7 @@ public final class MimeTypeUtil {
|
|||
* @return the file's mime type
|
||||
*/
|
||||
private static String extractMimeType(File file) {
|
||||
file = new File(file.getName().trim());
|
||||
Uri selectedUri = Uri.fromFile(file);
|
||||
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString().toLowerCase(Locale.ROOT));
|
||||
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
|
||||
|
|
Loading…
Reference in a new issue