Просмотр исходного кода

Only trigger media scans when the file is a media file

Fixes #4999

Signed-off-by: Torsten Grote <t@grobox.de>
Torsten Grote 5 лет назад
Родитель
Сommit
574f50e684

+ 5 - 3
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -381,7 +381,7 @@ public class FileDataStorageManager {
 
                     if (file.isDown()) {
                         String path = file.getStoragePath();
-                        if (new File(path).delete()) {
+                        if (new File(path).delete() && MimeTypeUtil.isMedia(file.getMimeType())) {
                             triggerMediaScan(path); // notify MediaScanner about removed file
                         }
                     }
@@ -702,8 +702,10 @@ public class FileDataStorageManager {
 
                         cv.put(ProviderTableMeta.FILE_STORAGE_PATH, targetLocalPath);
 
-                        originalPathsToTriggerMediaScan.add(child.getStoragePath());
-                        newPathsToTriggerMediaScan.add(targetLocalPath);
+                        if (MimeTypeUtil.isMedia(child.getMimeType())) {
+                            originalPathsToTriggerMediaScan.add(child.getStoragePath());
+                            newPathsToTriggerMediaScan.add(targetLocalPath);
+                        }
 
                     }
                     if (child.getRemotePath().equals(file.getRemotePath())) {

+ 4 - 1
src/main/java/com/owncloud/android/files/services/FileDownloader.java

@@ -60,6 +60,7 @@ import com.owncloud.android.ui.notifications.NotificationUtils;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
 import com.owncloud.android.utils.ErrorMessageAdapter;
+import com.owncloud.android.utils.MimeTypeUtil;
 import com.owncloud.android.utils.ThemeUtils;
 
 import java.io.File;
@@ -504,7 +505,9 @@ public class FileDownloader extends Service
         file.setFileLength(new File(mCurrentDownload.getSavePath()).length());
         file.setRemoteId(mCurrentDownload.getFile().getRemoteId());
         mStorageManager.saveFile(file);
-        FileDataStorageManager.triggerMediaScan(file.getStoragePath());
+        if (MimeTypeUtil.isMedia(mCurrentDownload.getMimeType())) {
+            FileDataStorageManager.triggerMediaScan(file.getStoragePath());
+        }
         mStorageManager.saveConflict(file, null);
     }
 

+ 5 - 2
src/main/java/com/owncloud/android/operations/RemoveFileOperation.java

@@ -33,6 +33,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
 import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
 import com.owncloud.android.operations.common.SyncOperation;
+import com.owncloud.android.utils.MimeTypeUtil;
 
 
 /**
@@ -91,8 +92,10 @@ public class RemoveFileOperation extends SyncOperation {
 
         fileToRemove = getStorageManager().getFileByPath(remotePath);
 
-        // store resized image
-        ThumbnailsCacheManager.generateResizedImage(fileToRemove);
+        if (MimeTypeUtil.isImage(fileToRemove.getMimeType())) {
+            // store resized image
+            ThumbnailsCacheManager.generateResizedImage(fileToRemove);
+        }
 
         boolean localRemovalFailed = false;
         if (!onlyLocalCopy) {

+ 5 - 2
src/main/java/com/owncloud/android/operations/RenameFileOperation.java

@@ -32,6 +32,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.files.RenameFileRemoteOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.utils.FileStorageUtils;
+import com.owncloud.android.utils.MimeTypeUtil;
 
 import java.io.File;
 import java.io.IOException;
@@ -130,8 +131,10 @@ public class RenameFileOperation extends SyncOperation {
 
                 // notify MediaScanner about removed file
                 getStorageManager().deleteFileInMediaScan(oldPath);
-                // notify to scan about new file
-                FileDataStorageManager.triggerMediaScan(newPath);
+                // notify to scan about new file, if it is a media file
+                if (MimeTypeUtil.isMedia(file.getMimeType())) {
+                    FileDataStorageManager.triggerMediaScan(newPath);
+                }
             }
             // else - NOTHING: the link to the local file is kept although the local name
             // can't be updated

+ 9 - 3
src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -967,7 +967,9 @@ public class UploadFileOperation extends SyncOperation {
                 }
                 mFile.setStoragePath(expectedFile.getAbsolutePath());
                 saveUploadedFile(client);
-                FileDataStorageManager.triggerMediaScan(expectedFile.getAbsolutePath());
+                if (MimeTypeUtil.isMedia(mFile.getMimeType())) {
+                    FileDataStorageManager.triggerMediaScan(expectedFile.getAbsolutePath());
+                }
                 break;
 
             case FileUploader.LOCAL_BEHAVIOUR_MOVE:
@@ -982,7 +984,9 @@ public class UploadFileOperation extends SyncOperation {
                 getStorageManager().deleteFileInMediaScan(originalFile.getAbsolutePath());
                 mFile.setStoragePath(newFile.getAbsolutePath());
                 saveUploadedFile(client);
-                FileDataStorageManager.triggerMediaScan(newFile.getAbsolutePath());
+                if (MimeTypeUtil.isMedia(mFile.getMimeType())) {
+                    FileDataStorageManager.triggerMediaScan(newFile.getAbsolutePath());
+                }
                 break;
         }
     }
@@ -1324,7 +1328,9 @@ public class UploadFileOperation extends SyncOperation {
         getStorageManager().saveFile(file);
         getStorageManager().saveConflict(file, null);
 
-        FileDataStorageManager.triggerMediaScan(file.getStoragePath());
+        if (MimeTypeUtil.isMedia(file.getMimeType())) {
+            FileDataStorageManager.triggerMediaScan(file.getStoragePath());
+        }
 
         // generate new Thumbnail
         final ThumbnailsCacheManager.ThumbnailGenerationTask task =

+ 4 - 0
src/main/java/com/owncloud/android/utils/MimeTypeUtil.java

@@ -203,6 +203,10 @@ public final class MimeTypeUtil {
         return candidates.get(0);
     }
 
+    public static boolean isMedia(String mimeType) {
+        return isImage(mimeType) || isVideo(mimeType) || isAudio(mimeType);
+    }
+
     public static boolean isImageOrVideo(String mimeType) {
         return isImage(mimeType) || isVideo(mimeType);
     }