OC-576: method updateSubtreeSize in FileDataStorageManager. OC-523

This commit is contained in:
masensio 2013-07-05 13:00:57 +02:00 committed by David A. Velasco
parent eee74aa5f2
commit 7ec25767ef
4 changed files with 51 additions and 25 deletions

View file

@ -49,6 +49,8 @@ public interface DataStorageManager {
public Vector<OCFile> getFilesbyParent(long id);
public void saveFolderSize(long id);
public int updatefolderSize(long id, long size);
}

View file

@ -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;
}
/**
* Update the size value of a folder
* Calculate and save the folderSize on DB
* @param id
*/
@Override
public int updatefolderSize(long id, long size)
{
public void saveFolderSize(long id) {
long folderSize = 0;
Vector<OCFile> 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 on DB
*/
@Override
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();
}
}
}

View file

@ -268,7 +268,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
// Update folder size on DB
FileDataStorageManager storageManager = new FileDataStorageManager(getAccount(), getContext().getContentResolver());
FileStorageUtils.saveFolderSize(newFile.getFileId(), storageManager);
storageManager.saveFolderSize(newFile.getFileId());
}
}

View file

@ -18,7 +18,6 @@
package com.owncloud.android.utils;
import java.io.File;
import java.util.Vector;
import android.annotation.SuppressLint;
import android.content.Context;
@ -26,9 +25,7 @@ import android.net.Uri;
import android.os.Environment;
import android.os.StatFs;
import com.owncloud.android.Log_OC;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.DataStorageManager;
import com.owncloud.android.datamodel.OCFile;
/**
@ -77,21 +74,5 @@ public class FileStorageUtils {
String value = uploadPath + OCFile.PATH_SEPARATOR + (fileName == null ? "" : fileName);
return value;
}
public static void saveFolderSize(long id, DataStorageManager storageManager)
{
long folderSize = 0;
Vector<OCFile> files = storageManager.getFilesbyParent(id);
Log_OC.d(LOG_TAG, "Folder " + String.valueOf(id) + "--- Number of Files = " + String.valueOf(files.size()));
for (OCFile f: files)
{
folderSize = folderSize + f.getFileLength();
Log_OC.d(LOG_TAG, "Folder Size = " + String.valueOf(folderSize));
}
storageManager.updatefolderSize(id, folderSize);
}
}