Преглед на файлове

Merge pull request #1171 from owncloud/fix_lock_of_upload_til_generation_of_thumbnails_finishes

Grant that cancellations of tasks generating thumbnails really works …
masensio преди 9 години
родител
ревизия
a81934a6cc
променени са 2 файла, в които са добавени 15 реда и са изтрити 7 реда
  1. 1 4
      src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java
  2. 14 3
      src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java

+ 1 - 4
src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

@@ -195,10 +195,6 @@ public class ThumbnailsCacheManager {
         }
         }
 
 
         protected void onPostExecute(Bitmap bitmap){
         protected void onPostExecute(Bitmap bitmap){
-            if (isCancelled()) {
-                bitmap = null;
-            }
-
             if (bitmap != null) {
             if (bitmap != null) {
                 final ImageView imageView = mImageViewReference.get();
                 final ImageView imageView = mImageViewReference.get();
                 final ThumbnailGenerationTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
                 final ThumbnailGenerationTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
@@ -365,6 +361,7 @@ public class ThumbnailsCacheManager {
             if (bitmapData == null || bitmapData != file) {
             if (bitmapData == null || bitmapData != file) {
                 // Cancel previous task
                 // Cancel previous task
                 bitmapWorkerTask.cancel(true);
                 bitmapWorkerTask.cancel(true);
+                Log_OC.v(TAG, "Cancelled generation of thumbnail for a reused imageView");
             } else {
             } else {
                 // The same work is already in progress
                 // The same work is already in progress
                 return false;
                 return false;

+ 14 - 3
src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java

@@ -37,6 +37,7 @@ import android.widget.TextView;
 
 
 import com.owncloud.android.R;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
+import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.utils.BitmapUtils;
 import com.owncloud.android.utils.BitmapUtils;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimetypeIconUtil;
 import com.owncloud.android.utils.MimetypeIconUtil;
@@ -46,7 +47,9 @@ import com.owncloud.android.utils.MimetypeIconUtil;
  * in a local directory
  * in a local directory
  */
  */
 public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
 public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
-    
+
+    private static final String TAG = LocalFileListAdapter.class.getSimpleName();
+
     private Context mContext;
     private Context mContext;
     private File mDirectory;
     private File mDirectory;
     private File[] mFiles = null;
     private File[] mFiles = null;
@@ -104,6 +107,12 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
             fileName.setText(name);
             fileName.setText(name);
             
             
             ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
             ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
+
+            /** Cancellation needs do be checked and done before changing the drawable in fileIcon, or
+             * {@link ThumbnailsCacheManager#cancelPotentialWork} will NEVER cancel any task.
+             **/
+            boolean allowedToCreateNewThumbnail = (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon));
+
             if (!file.isDirectory()) {
             if (!file.isDirectory()) {
                 fileIcon.setImageResource(R.drawable.file);
                 fileIcon.setImageResource(R.drawable.file);
             } else {
             } else {
@@ -143,7 +152,7 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
                     } else {
                     } else {
 
 
                         // generate new Thumbnail
                         // generate new Thumbnail
-                        if (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon)) {
+                        if (allowedToCreateNewThumbnail) {
                             final ThumbnailsCacheManager.ThumbnailGenerationTask task =
                             final ThumbnailsCacheManager.ThumbnailGenerationTask task =
                                     new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon);
                                     new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon);
                             if (thumbnail == null) {
                             if (thumbnail == null) {
@@ -157,7 +166,9 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
                 		        );
                 		        );
                             fileIcon.setImageDrawable(asyncDrawable);
                             fileIcon.setImageDrawable(asyncDrawable);
                             task.execute(file);
                             task.execute(file);
-                        }
+                            Log_OC.v(TAG, "Executing task to generate a new thumbnail");
+
+                        } // else, already being generated, don't restart it
                     }
                     }
                 } else {
                 } else {
                     fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(null, file.getName()));
                     fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(null, file.getName()));