+ /**
+ * Calculate and save the folderSize on DB
+ * @param id
+ */
+ @Override
+ public void calculateFolderSize(long id) {
+ long folderSize = 0;
+
+ Vector<OCFile> files = getDirectoryContent(id);
+
+ for (OCFile f: files)
+ {
+ folderSize = folderSize + f.getFileLength();
+ }
+
+ updateSize(id, folderSize);
+ }
+
+ /**
+ * Update the size value of an OCFile in DB
+ */
+ private int updateSize(long id, long size) {
+ ContentValues cv = new ContentValues();
+ cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, size);
+ int result = -1;
+ if (getContentResolver() != null) {
+ result = getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, ProviderTableMeta._ID + "=?",
+ new String[] { String.valueOf(id) });
+ } else {
+ try {
+ result = getContentProvider().update(ProviderTableMeta.CONTENT_URI, cv, ProviderTableMeta._ID + "=?",
+ new String[] { String.valueOf(id) });
+ } catch (RemoteException e) {
+ Log_OC.e(TAG,"Fail to update size column into database " + e.getMessage());
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Update the size of a subtree of folder from a file to the root
+ * @param parentId: parent of the file
+ */
+ private void updateSizesToTheRoot(long parentId) {
+
+ OCFile file;
+
+ while (parentId != DataStorageManager.ROOT_PARENT_ID) {
+
+ Log_OC.d(TAG, "parent = " + parentId);
+ // Update the size of the parent
+ calculateFolderSize(parentId);
+
+ // search the next parent
+ file = getFileById(parentId);
+ parentId = file.getParentId();
+
+ }
+
+ }
+