Parallel thumbnail fetching

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2022-04-14 10:07:36 +02:00 committed by Álvaro Brey (Rebase PR Action)
parent a2d2c1a3c7
commit 73bb12f78a
3 changed files with 24 additions and 8 deletions

View file

@ -462,19 +462,27 @@ public final class ThumbnailsCacheManager {
mAsyncTasks = asyncTasks; mAsyncTasks = asyncTasks;
} }
public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager, public ThumbnailGenerationTask(ImageView imageView,
User user, List<ThumbnailGenerationTask> asyncTasks, FileDataStorageManager storageManager,
boolean gridViewEnabled) User user,
List<ThumbnailGenerationTask> asyncTasks,
boolean gridViewEnabled,
String imageKey)
throws IllegalArgumentException { throws IllegalArgumentException {
this(imageView, storageManager, user, asyncTasks); this(imageView, storageManager, user, asyncTasks);
this.gridViewEnabled = gridViewEnabled; this.gridViewEnabled = gridViewEnabled;
mImageKey = imageKey;
} }
public GetMethod getGetMethod() { public GetMethod getGetMethod() {
return getMethod; return getMethod;
} }
public ThumbnailGenerationTask(FileDataStorageManager storageManager, User user){ public String getImageKey() {
return mImageKey;
}
public ThumbnailGenerationTask(FileDataStorageManager storageManager, User user) {
if (storageManager == null) { if (storageManager == null) {
throw new IllegalArgumentException("storageManager must not be NULL"); throw new IllegalArgumentException("storageManager must not be NULL");
} }

View file

@ -41,7 +41,6 @@ import android.view.MotionEvent;
import android.view.ScaleGestureDetector; import android.view.ScaleGestureDetector;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;

View file

@ -38,6 +38,7 @@ import android.graphics.Point;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.PictureDrawable; import android.graphics.drawable.PictureDrawable;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.TextUtils; import android.text.TextUtils;
@ -896,13 +897,20 @@ public final class DisplayUtils {
} else { } else {
// generate new thumbnail // generate new thumbnail
if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) { if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) {
for (ThumbnailsCacheManager.ThumbnailGenerationTask task : asyncTasks) {
if (file.getRemoteId() != null && task.getImageKey() != null &&
file.getRemoteId().equals(task.getImageKey())) {
return;
}
}
try { try {
final ThumbnailsCacheManager.ThumbnailGenerationTask task = final ThumbnailsCacheManager.ThumbnailGenerationTask task =
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView, new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
storageManager, storageManager,
user, user,
asyncTasks, asyncTasks,
gridView); gridView,
file.getRemoteId());
if (thumbnail == null) { if (thumbnail == null) {
Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(), Drawable drawable = MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
file.getFileName(), file.getFileName(),
@ -941,8 +949,9 @@ public final class DisplayUtils {
thumbnailView.setImageDrawable(asyncDrawable); thumbnailView.setImageDrawable(asyncDrawable);
asyncTasks.add(task); asyncTasks.add(task);
task.execute(new ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file, task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
file.getRemoteId())); new ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file,
file.getRemoteId()));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log_OC.d(TAG, "ThumbnailGenerationTask : " + e.getMessage()); Log_OC.d(TAG, "ThumbnailGenerationTask : " + e.getMessage());
} }