From: David A. Velasco Date: Tue, 2 Dec 2014 13:23:49 +0000 (+0100) Subject: Trigger MediaScan for every downloaded file in a renamed or moved folder X-Git-Tag: oc-android-1.7.0_signed~90^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/1e9ff8c5fa83b68f9648e91265034c78d96685be?ds=inline Trigger MediaScan for every downloaded file in a renamed or moved folder --- diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 71bc3ee6..55707bb9 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import java.util.List; import java.util.Vector; import com.owncloud.android.MainApp; @@ -644,6 +645,8 @@ public class FileDataStorageManager { ArrayList operations = new ArrayList(c.getCount()); String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name); + List originalPathsToTriggerMediaScan = new ArrayList(); + List newPathsToTriggerMediaScan = new ArrayList(); if (c.moveToFirst()) { int lengthOfOldPath = file.getRemotePath().length(); int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath; @@ -657,11 +660,14 @@ public class FileDataStorageManager { if (child.getStoragePath() != null && child.getStoragePath().startsWith(defaultSavePath)) { // update link to downloaded content - but local move is not done here! - cv.put( - ProviderTableMeta.FILE_STORAGE_PATH, - defaultSavePath + targetPath + - child.getStoragePath().substring(lengthOfOldStoragePath) - ); + String targetLocalPath = defaultSavePath + targetPath + + child.getStoragePath().substring(lengthOfOldStoragePath); + + cv.put(ProviderTableMeta.FILE_STORAGE_PATH, targetLocalPath); + + originalPathsToTriggerMediaScan.add(child.getStoragePath()); + newPathsToTriggerMediaScan.add(targetLocalPath); + } if (child.getRemotePath().equals(file.getRemotePath())) { cv.put( @@ -696,11 +702,12 @@ public class FileDataStorageManager { } /// 4. move in local file system - String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file); - File localFile = new File(localPath); + String originalLocalPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file); + String targetLocalPath = defaultSavePath + targetPath; + File localFile = new File(originalLocalPath); boolean renamed = false; if (localFile.exists()) { - File targetFile = new File(defaultSavePath + targetPath); + File targetFile = new File(targetLocalPath); File targetFolder = targetFile.getParentFile(); if (!targetFolder.exists()) { targetFolder.mkdirs(); @@ -709,19 +716,17 @@ public class FileDataStorageManager { } if (renamed) { - if (file.isFolder()) { - - } else { + Iterator it = originalPathsToTriggerMediaScan.iterator(); + while (it.hasNext()) { // Notify MediaScanner about removed file - triggerMediaScan(file.getStoragePath()); - + triggerMediaScan(it.next()); + } + it = newPathsToTriggerMediaScan.iterator(); + while (it.hasNext()) { // Notify MediaScanner about new file/folder - triggerMediaScan(defaultSavePath + targetPath); + triggerMediaScan(it.next()); } } - - Log_OC.d(TAG, "uri old: " + file.getStoragePath()); - Log_OC.d(TAG, "uri new: " + defaultSavePath + targetPath); } } diff --git a/src/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java b/src/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java index c86c8b5e..5afc4210 100644 --- a/src/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java +++ b/src/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java @@ -36,7 +36,6 @@ import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import android.content.Context; import android.net.Uri; -import android.util.Log; /** * Operation to find out what authentication method requires diff --git a/src/com/owncloud/android/operations/RenameFileOperation.java b/src/com/owncloud/android/operations/RenameFileOperation.java index 9bbf78c4..bd60e1fb 100644 --- a/src/com/owncloud/android/operations/RenameFileOperation.java +++ b/src/com/owncloud/android/operations/RenameFileOperation.java @@ -29,8 +29,6 @@ import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation; import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.utils.FileStorageUtils; -import android.accounts.Account; - /** * Remote operation performing the rename of a remote file (or folder?) in the ownCloud server.