X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/5167e646ad8ee3ca074cdc58730aeeb942935089..a69c04d8e938b67f1a44a72b9148b907ebd7b256:/src/com/owncloud/android/datamodel/FileDataStorageManager.java diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 71bc3ee6..b73845af 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; @@ -45,6 +46,7 @@ import android.content.OperationApplicationException; import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; +import android.provider.MediaStore; public class FileDataStorageManager { @@ -260,8 +262,8 @@ public class FileDataStorageManager { * HERE ONLY DATA CONSISTENCY SHOULD BE GRANTED * * @param folder - * @param files - * @param removeNotUpdated + * @param updatedFiles + * @param filesToRemove */ public void saveFolder( OCFile folder, Collection updatedFiles, Collection filesToRemove @@ -490,7 +492,7 @@ public class FileDataStorageManager { if (removeLocalCopy && file.isDown() && localPath != null && success) { success = new File(localPath).delete(); if (success) { - triggerMediaScan(localPath); + deleteFileInMediaScan(file); } if (!removeDBData && success) { // maybe unnecessary, but should be checked TODO remove if unnecessary @@ -538,7 +540,8 @@ public class FileDataStorageManager { private boolean removeLocalFolder(OCFile folder) { boolean success = true; - File localFolder = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, folder)); + String localFolderPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, folder); + File localFolder = new File(localFolderPath); if (localFolder.exists()) { // stage 1: remove the local files already registered in the files database Vector files = getFolderContent(folder.getFileId()); @@ -548,13 +551,12 @@ public class FileDataStorageManager { success &= removeLocalFolder(file); } else { if (file.isDown()) { - String path = file.getStoragePath(); File localFile = new File(file.getStoragePath()); success &= localFile.delete(); if (success) { + deleteFileInMediaScan(file); // notify MediaScanner about removed file file.setStoragePath(null); saveFile(file); - triggerMediaScan(path); // notify MediaScanner about removed file } } } @@ -578,7 +580,6 @@ public class FileDataStorageManager { } else { String path = localFile.getAbsolutePath(); success &= localFile.delete(); - triggerMediaScan(path); // notify MediaScanner about removed file } } } @@ -586,11 +587,6 @@ public class FileDataStorageManager { return success; } - public void moveFolder(OCFile folder, String newPath) { - // TODO check newPath - - } - /** * Updates database and file system for a file or folder that was moved to a different location. @@ -644,6 +640,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 +655,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 +697,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 +711,19 @@ public class FileDataStorageManager { } if (renamed) { - if (file.isFolder()) { - - } else { + Iterator it = originalPathsToTriggerMediaScan.iterator(); + while (it.hasNext()) { // Notify MediaScanner about removed file - triggerMediaScan(file.getStoragePath()); - + deleteFileInMediaScan(file); + triggerMediaScan(it.next()); + } + it = newPathsToTriggerMediaScan.iterator(); + while (it.hasNext()) { // Notify MediaScanner about new file/folder - triggerMediaScan(defaultSavePath + targetPath); + deleteFileInMediaScan(file); + triggerMediaScan(it.next()); } } - - Log_OC.d(TAG, "uri old: " + file.getStoragePath()); - Log_OC.d(TAG, "uri new: " + defaultSavePath + targetPath); } } @@ -1490,4 +1492,22 @@ public class FileDataStorageManager { MainApp.getAppContext().sendBroadcast(intent); } + public void deleteFileInMediaScan(OCFile file) { + + String path = file.getStoragePath(); + if (file.isImage()) { + // Images + getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, + MediaStore.Images.Media.DATA + "=?", new String[]{path}); + } else if (file.isAudio()) { + // Audio + getContentResolver().delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, + MediaStore.Audio.Media.DATA + "=?", new String[]{path}); + } else if (file.isVideo()) { + // Video + getContentResolver().delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, + MediaStore.Video.Media.DATA + "=?", new String[]{path}); + } + } + }