X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/eee74aa5f2f8533693c86d4aecf5b40f12a331bb..3863cf061bd5be90b22bcf937bd28ba714fce631:/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..a082cfc5 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.List; import java.util.Vector; +import com.owncloud.android.DisplayUtils; import com.owncloud.android.Log_OC; import com.owncloud.android.db.ProviderMeta; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; @@ -179,13 +180,16 @@ public class FileDataStorageManager implements DataStorageManager { long new_id = Long.parseLong(result_uri.getPathSegments() .get(1)); file.setFileId(new_id); - } + } } if (file.isDirectory() && file.needsUpdatingWhileSaving()) for (OCFile f : getDirectoryContent(file)) saveFile(f); - + + Log_OC.d(TAG, ".........file Time= " + DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp())); + updateSubtreeSize(file.getParentId()); + return overriden; } @@ -465,6 +469,8 @@ public class FileDataStorageManager implements DataStorageManager { f.delete(); } } + + updateSubtreeSize(file.getParentId()); } @Override @@ -492,6 +498,8 @@ public class FileDataStorageManager implements DataStorageManager { if (removeDBData) { removeFile(dir, true); } + + updateSubtreeSize(dir.getParentId()); } } @@ -621,13 +629,30 @@ 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); + + for (OCFile f: files) + { + folderSize = folderSize + f.getFileLength(); + } + + 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 +660,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(); + + } + + } }