X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/994e81d7ce72734e4ec55c3afd4789c2b3a807be..a7385a7a5afb65fe65676a4807dbd0d148bff52e:/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 595aa770..8b70d4a2 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -465,6 +465,8 @@ public class FileDataStorageManager implements DataStorageManager { f.delete(); } } + + updateSubtreeSize(file.getParentId()); } @Override @@ -621,13 +623,33 @@ public class FileDataStorageManager implements DataStorageManager { return ret; } + + /** + * Calculate and save the folderSize on DB + * @param id + */ + @Override + public void saveFolderSize(long id) { + long folderSize = 0; + + Vector files = getFilesbyParent(id); + + Log_OC.d(TAG, "Folder " + String.valueOf(id) + "--- Number of Files = " + String.valueOf(files.size())); + + for (OCFile f: files) + { + folderSize = folderSize + f.getFileLength(); + Log_OC.d(TAG, "Folder Size = " + String.valueOf(folderSize)); + } + + updatefolderSize(id, folderSize); + } /** - * Update the size value of a folder + * Update the size value of a folder on DB */ @Override - public int updatefolderSize(long id, long size) - { + public int updatefolderSize(long id, long size) { ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, size); int result = getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, ProviderTableMeta._ID + "=?", @@ -635,5 +657,26 @@ public class FileDataStorageManager implements DataStorageManager { return result; } + /** + * Update the size of a subtree of folder from a file to the root + * @param parentId: parent of the file + */ + private void updateSubtreeSize(long parentId) { + + OCFile file; + + while (parentId != 0) { + + Log_OC.d(TAG, "parent = " + parentId); + // Update the size of the parent + saveFolderSize(parentId); + + // search the next parent + file = getFileById(parentId); + parentId = file.getParentId(); + + } + + } }