|
@@ -864,8 +864,7 @@ public final class DisplayUtils {
|
|
|
if (file.getRemoteId() != null && file.isPreviewAvailable()) {
|
|
|
// Thumbnail in cache?
|
|
|
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
|
|
- ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId()
|
|
|
- );
|
|
|
+ ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId());
|
|
|
|
|
|
if (thumbnail != null && !file.isUpdateThumbnailNeeded()) {
|
|
|
stopShimmer(shimmerThumbnail, thumbnailView);
|
|
@@ -881,83 +880,104 @@ public final class DisplayUtils {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- // generate new thumbnail
|
|
|
- if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) {
|
|
|
- for (ThumbnailsCacheManager.ThumbnailGenerationTask task : asyncTasks) {
|
|
|
- if (file.getRemoteId() != null && task.getImageKey() != null &&
|
|
|
- file.getRemoteId().equals(task.getImageKey())) {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- try {
|
|
|
- final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
|
|
- new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
|
|
|
- storageManager,
|
|
|
- user,
|
|
|
- asyncTasks,
|
|
|
- gridView,
|
|
|
- file.getRemoteId());
|
|
|
- if (thumbnail == null) {
|
|
|
- Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
|
|
|
- file.getFileName(),
|
|
|
- context,
|
|
|
- viewThemeUtils);
|
|
|
- if (drawable == null) {
|
|
|
- drawable = ResourcesCompat.getDrawable(context.getResources(),
|
|
|
- R.drawable.file_image,
|
|
|
- null);
|
|
|
- }
|
|
|
- if (drawable == null) {
|
|
|
- drawable = new ColorDrawable(Color.GRAY);
|
|
|
- }
|
|
|
-
|
|
|
- int px = ThumbnailsCacheManager.getThumbnailDimension();
|
|
|
- thumbnail = BitmapUtils.drawableToBitmap(drawable, px, px);
|
|
|
- }
|
|
|
- final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
|
|
- new ThumbnailsCacheManager.AsyncThumbnailDrawable(context.getResources(),
|
|
|
- thumbnail, task);
|
|
|
-
|
|
|
- if (shimmerThumbnail != null && shimmerThumbnail.getVisibility() == View.GONE) {
|
|
|
- if (gridView) {
|
|
|
- configShimmerGridImageSize(shimmerThumbnail, preferences.getGridColumns());
|
|
|
- }
|
|
|
- startShimmer(shimmerThumbnail, thumbnailView);
|
|
|
- }
|
|
|
-
|
|
|
- task.setListener(new ThumbnailsCacheManager.ThumbnailGenerationTask.Listener() {
|
|
|
- @Override
|
|
|
- public void onSuccess() {
|
|
|
- stopShimmer(shimmerThumbnail, thumbnailView);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError() {
|
|
|
- stopShimmer(shimmerThumbnail, thumbnailView);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- thumbnailView.setImageDrawable(asyncDrawable);
|
|
|
- asyncTasks.add(task);
|
|
|
- task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
|
|
- new ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file,
|
|
|
- file.getRemoteId()));
|
|
|
- } catch (IllegalArgumentException e) {
|
|
|
- Log_OC.d(TAG, "ThumbnailGenerationTask : " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
+ generateNewThumbnail(file, thumbnailView, user, storageManager, asyncTasks, gridView, context, shimmerThumbnail, preferences, viewThemeUtils);
|
|
|
}
|
|
|
|
|
|
if ("image/png".equalsIgnoreCase(file.getMimeType())) {
|
|
|
thumbnailView.setBackgroundColor(context.getResources().getColor(R.color.bg_default));
|
|
|
}
|
|
|
} else {
|
|
|
- stopShimmer(shimmerThumbnail, thumbnailView);
|
|
|
- thumbnailView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
|
|
|
- file.getFileName(),
|
|
|
- context,
|
|
|
- viewThemeUtils));
|
|
|
+ if (file.getRemoteId() != null) {
|
|
|
+ generateNewThumbnail(file, thumbnailView, user, storageManager, asyncTasks, gridView, context, shimmerThumbnail, preferences, viewThemeUtils);
|
|
|
+ } else {
|
|
|
+ stopShimmer(shimmerThumbnail, thumbnailView);
|
|
|
+ thumbnailView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
|
|
|
+ file.getFileName(),
|
|
|
+ context,
|
|
|
+ viewThemeUtils));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void generateNewThumbnail(OCFile file,
|
|
|
+ ImageView thumbnailView,
|
|
|
+ User user,
|
|
|
+ FileDataStorageManager storageManager,
|
|
|
+ List<ThumbnailsCacheManager.ThumbnailGenerationTask> asyncTasks,
|
|
|
+ boolean gridView,
|
|
|
+ Context context,
|
|
|
+ LoaderImageView shimmerThumbnail,
|
|
|
+ AppPreferences preferences,
|
|
|
+ ViewThemeUtils viewThemeUtils) {
|
|
|
+ if (!ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
|
|
+ ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId());
|
|
|
+
|
|
|
+ for (ThumbnailsCacheManager.ThumbnailGenerationTask task : asyncTasks) {
|
|
|
+ if (file.getRemoteId() != null && task.getImageKey() != null &&
|
|
|
+ file.getRemoteId().equals(task.getImageKey())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
|
|
+ new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
|
|
|
+ storageManager,
|
|
|
+ user,
|
|
|
+ asyncTasks,
|
|
|
+ gridView,
|
|
|
+ file.getRemoteId());
|
|
|
+ if (thumbnail == null) {
|
|
|
+ Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
|
|
|
+ file.getFileName(),
|
|
|
+ context,
|
|
|
+ viewThemeUtils);
|
|
|
+ if (drawable == null) {
|
|
|
+ drawable = ResourcesCompat.getDrawable(context.getResources(),
|
|
|
+ R.drawable.file_image,
|
|
|
+ null);
|
|
|
+ }
|
|
|
+ if (drawable == null) {
|
|
|
+ drawable = new ColorDrawable(Color.GRAY);
|
|
|
+ }
|
|
|
+
|
|
|
+ int px = ThumbnailsCacheManager.getThumbnailDimension();
|
|
|
+ thumbnail = BitmapUtils.drawableToBitmap(drawable, px, px);
|
|
|
+ }
|
|
|
+ final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
|
|
+ new ThumbnailsCacheManager.AsyncThumbnailDrawable(context.getResources(),
|
|
|
+ thumbnail, task);
|
|
|
+
|
|
|
+ if (shimmerThumbnail != null && shimmerThumbnail.getVisibility() == View.GONE) {
|
|
|
+ if (gridView) {
|
|
|
+ configShimmerGridImageSize(shimmerThumbnail, preferences.getGridColumns());
|
|
|
+ }
|
|
|
+ startShimmer(shimmerThumbnail, thumbnailView);
|
|
|
}
|
|
|
+
|
|
|
+ task.setListener(new ThumbnailsCacheManager.ThumbnailGenerationTask.Listener() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess() {
|
|
|
+ stopShimmer(shimmerThumbnail, thumbnailView);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError() {
|
|
|
+ stopShimmer(shimmerThumbnail, thumbnailView);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ thumbnailView.setImageDrawable(asyncDrawable);
|
|
|
+ asyncTasks.add(task);
|
|
|
+ task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
|
|
+ new ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file,
|
|
|
+ file.getRemoteId()));
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ Log_OC.d(TAG, "ThumbnailGenerationTask : " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|