Browse Source

Some cleanup and methods renamed in FileDataStorageManager

David A. Velasco 11 years ago
parent
commit
d8de614d78

+ 4 - 4
src/com/owncloud/android/Uploader.java

@@ -229,12 +229,12 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
         // click on folder in the list
         Log_OC.d(TAG, "on item click");
-        Vector<OCFile> tmpfiles = mStorageManager.getDirectoryContent(mFile);
+        Vector<OCFile> tmpfiles = mStorageManager.getFolderContent(mFile);
         if (tmpfiles.size() <= 0) return;
         // filter on dirtype
         Vector<OCFile> files = new Vector<OCFile>();
         for (OCFile f : tmpfiles)
-            if (f.isDirectory())
+            if (f.isFolder())
                 files.add(f);
         if (files.size() < position) {
             throw new IndexOutOfBoundsException("Incorrect item selected");
@@ -294,11 +294,11 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
         
         mFile = mStorageManager.getFileByPath(full_path);
         if (mFile != null) {
-            Vector<OCFile> files = mStorageManager.getDirectoryContent(mFile);
+            Vector<OCFile> files = mStorageManager.getFolderContent(mFile);
             List<HashMap<String, Object>> data = new LinkedList<HashMap<String,Object>>();
             for (OCFile f : files) {
                 HashMap<String, Object> h = new HashMap<String, Object>();
-                if (f.isDirectory()) {
+                if (f.isFolder()) {
                     h.put("dirname", f.getFileName());
                     data.add(h);
                 }

+ 225 - 219
src/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -25,7 +25,6 @@ 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;
@@ -47,23 +46,49 @@ public class FileDataStorageManager {
     public static final int ROOT_PARENT_ID = 0;
 
     private ContentResolver mContentResolver;
-    private ContentProviderClient mContentProvider;
+    private ContentProviderClient mContentProviderClient;
     private Account mAccount;
 
-    private static String TAG = "FileDataStorageManager";
+    private static String TAG = FileDataStorageManager.class.getSimpleName();
 
+    
     public FileDataStorageManager(Account account, ContentResolver cr) {
-        mContentProvider = null;
+        mContentProviderClient = null;
         mContentResolver = cr;
         mAccount = account;
     }
 
     public FileDataStorageManager(Account account, ContentProviderClient cp) {
-        mContentProvider = cp;
+        mContentProviderClient = cp;
         mContentResolver = null;
         mAccount = account;
     }
 
+    
+    public void setAccount(Account account) {
+        mAccount = account;
+    }
+
+    public Account getAccount() {
+        return mAccount;
+    }
+
+    public void setContentResolver(ContentResolver cr) {
+        mContentResolver = cr;
+    }
+
+    public ContentResolver getContentResolver() {
+        return mContentResolver;
+    }
+
+    public void setContentProviderClient(ContentProviderClient cp) {
+        mContentProviderClient = cp;
+    }
+
+    public ContentProviderClient getContentProviderClient() {
+        return mContentProviderClient;
+    }
+    
 
     public OCFile getFileByPath(String path) {
         Cursor c = getCursorForValue(ProviderTableMeta.FILE_PATH, path);
@@ -72,21 +97,13 @@ public class FileDataStorageManager {
             file = createFileInstance(c);
         }
         c.close();
-        if (file == null && OCFile.PATH_SEPARATOR.equals(path)) {
+        if (file == null && OCFile.ROOT_PATH.equals(path)) {
             return createRootDir(); // root should always exist
         }
         return file;
     }
 
 
-    private OCFile createRootDir() {
-        OCFile file = new OCFile(OCFile.PATH_SEPARATOR);
-        file.setMimetype("DIR");
-        file.setParentId(FileDataStorageManager.ROOT_PARENT_ID);
-        saveFile(file);
-        return file;
-    }
-
     public OCFile getFileById(long id) {
         Cursor c = getCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
         OCFile file = null;
@@ -115,6 +132,34 @@ public class FileDataStorageManager {
         return fileExists(ProviderTableMeta.FILE_PATH, path);
     }
 
+    
+    public Vector<OCFile> getFolderContent(OCFile f) {
+        if (f != null && f.isFolder() && f.getFileId() != -1) {
+            return getFolderContent(f.getFileId());
+
+        } else {
+            return new Vector<OCFile>();
+        }
+    }
+    
+    
+    public Vector<OCFile> getFolderImages(OCFile folder) {
+        Vector<OCFile> ret = new Vector<OCFile>(); 
+        if (folder != null) {
+            // TODO better implementation, filtering in the access to database (if possible) instead of here 
+            Vector<OCFile> tmp = getFolderContent(folder);
+            OCFile current = null; 
+            for (int i=0; i<tmp.size(); i++) {
+                current = tmp.get(i);
+                if (current.isImage()) {
+                    ret.add(current);
+                }
+            }
+        }
+        return ret;
+    }
+
+    
     public boolean saveFile(OCFile file) {
         boolean overriden = false;
         ContentValues cv = new ContentValues();
@@ -127,7 +172,7 @@ public class FileDataStorageManager {
         //if (file.getParentId() != DataStorageManager.ROOT_PARENT_ID)
             cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
         cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
-        if (!file.isDirectory())
+        if (!file.isFolder())
             cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
         cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
         cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
@@ -156,7 +201,7 @@ public class FileDataStorageManager {
                         new String[] { String.valueOf(file.getFileId()) });
             } else {
                 try {
-                    getContentProvider().update(ProviderTableMeta.CONTENT_URI,
+                    getContentProviderClient().update(ProviderTableMeta.CONTENT_URI,
                             cv, ProviderTableMeta._ID + "=?",
                             new String[] { String.valueOf(file.getFileId()) });
                 } catch (RemoteException e) {
@@ -173,7 +218,7 @@ public class FileDataStorageManager {
                         ProviderTableMeta.CONTENT_URI_FILE, cv);
             } else {
                 try {
-                    result_uri = getContentProvider().insert(
+                    result_uri = getContentProviderClient().insert(
                             ProviderTableMeta.CONTENT_URI_FILE, cv);
                 } catch (RemoteException e) {
                     Log_OC.e(TAG,
@@ -188,15 +233,15 @@ public class FileDataStorageManager {
             }            
         }
 
-        if (file.isDirectory()) {
+        if (file.isFolder()) {
             calculateFolderSize(file.getFileId());
             if (file.needsUpdatingWhileSaving()) {
-                for (OCFile f : getDirectoryContent(file))
+                for (OCFile f : getFolderContent(file))
                     saveFile(f);
             }
         }
         
-        if (changesSizeOfAncestors || file.isDirectory()) {
+        if (changesSizeOfAncestors || file.isFolder()) {
             updateSizesToTheRoot(file.getParentId());
         }
         
@@ -223,7 +268,7 @@ public class FileDataStorageManager {
             if (file.getParentId() != FileDataStorageManager.ROOT_PARENT_ID)
                 cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
             cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
-            if (!file.isDirectory())
+            if (!file.isFolder())
                 cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
             cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
             cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
@@ -235,7 +280,7 @@ public class FileDataStorageManager {
                 OCFile oldFile = getFileByPath(file.getRemotePath());
                 file.setFileId(oldFile.getFileId());
                
-                if (file.isDirectory()) {
+                if (file.isFolder()) {
                     cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, oldFile.getFileLength());
                     file.setFileLength(oldFile.getFileLength());
                 }
@@ -251,7 +296,7 @@ public class FileDataStorageManager {
                 if (file.getStoragePath() == null && oldFile.getStoragePath() != null)
                     file.setStoragePath(oldFile.getStoragePath());
                 
-                if (!file.isDirectory())
+                if (!file.isFolder())
                     cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
                 else {
                     cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, oldFile.getFileLength());
@@ -276,7 +321,7 @@ public class FileDataStorageManager {
                 results = getContentResolver().applyBatch(ProviderMeta.AUTHORITY_FILES, operations);
 
             } else {
-                results = getContentProvider().applyBatch(operations);
+                results = getContentProviderClient().applyBatch(operations);
             }
 
         } catch (OperationApplicationException e) {
@@ -299,46 +344,164 @@ public class FileDataStorageManager {
         }
 
         for (OCFile aFile : files) {
-            if (aFile.isDirectory() && aFile.needsUpdatingWhileSaving())
-                saveFiles(getDirectoryContent(aFile));
+            if (aFile.isFolder() && aFile.needsUpdatingWhileSaving())
+                saveFiles(getFolderContent(aFile));
         }
 
     }
 
-    public void setAccount(Account account) {
-        mAccount = account;
-    }
 
-    public Account getAccount() {
-        return mAccount;
+    /**
+     * Calculate and save the folderSize on DB
+     * @param id
+     */
+    public void calculateFolderSize(long id) {
+        long folderSize = 0;
+        
+        Vector<OCFile> files = getFolderContent(id);
+        
+        for (OCFile f: files)
+        {
+            folderSize = folderSize + f.getFileLength();
+        }
+        
+        updateSize(id, folderSize);
     }
-
-    public void setContentResolver(ContentResolver cr) {
-        mContentResolver = cr;
+    
+    
+    public void removeFile(OCFile file, boolean removeLocalCopy) {
+        Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId());
+        if (getContentProviderClient() != null) {
+            try {
+                getContentProviderClient().delete(file_uri,
+                        ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
+                        new String[]{mAccount.name});
+            } catch (RemoteException e) {
+                e.printStackTrace();
+            }
+        } else {
+            getContentResolver().delete(file_uri,
+                    ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
+                    new String[]{mAccount.name});
+        }
+        if (file.isDown() && removeLocalCopy) {
+            new File(file.getStoragePath()).delete();
+        }
+        if (file.isFolder() && removeLocalCopy) {
+            File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
+            if (f.exists() && f.isDirectory() && (f.list() == null || f.list().length == 0)) {
+                f.delete();
+            }
+        }
+        
+        if (file.getFileLength() > 0) {
+            updateSizesToTheRoot(file.getParentId());
+        }
     }
 
-    public ContentResolver getContentResolver() {
-        return mContentResolver;
+    public void removeFolder(OCFile folder, boolean removeDBData, boolean removeLocalContent) {
+        // TODO consider possible failures
+        if (folder != null && folder.isFolder() && folder.getFileId() != -1) {
+            Vector<OCFile> children = getFolderContent(folder);
+            if (children.size() > 0) {
+                OCFile child = null;
+                for (int i=0; i<children.size(); i++) {
+                    child = children.get(i);
+                    if (child.isFolder()) {
+                        removeFolder(child, removeDBData, removeLocalContent);
+                    } else {
+                        if (removeDBData) {
+                            removeFile(child, removeLocalContent);
+                        } else if (removeLocalContent) {
+                            if (child.isDown()) {
+                                new File(child.getStoragePath()).delete();
+                            }
+                        }
+                    }
+                }
+            }
+            if (removeDBData) {
+                removeFile(folder, true);
+            }
+            
+            if (folder.getFileLength() > 0) {
+                updateSizesToTheRoot(folder.getParentId());
+            }
+        }
     }
 
-    public void setContentProvider(ContentProviderClient cp) {
-        mContentProvider = cp;
-    }
 
-    public ContentProviderClient getContentProvider() {
-        return mContentProvider;
-    }
-    
-    public Vector<OCFile> getDirectoryContent(OCFile f) {
-        if (f != null && f.isDirectory() && f.getFileId() != -1) {
-            return getDirectoryContent(f.getFileId());
+    /**
+     * Updates database for a folder that was moved to a different location.
+     * 
+     * TODO explore better (faster) implementations
+     * TODO throw exceptions up !
+     */
+    public void moveFolder(OCFile folder, String newPath) {
+        // TODO check newPath
+
+        if (folder != null && folder.isFolder() && folder.fileExists() && !OCFile.ROOT_PATH.equals(folder.getFileName())) {
+            /// 1. get all the descendants of 'dir' in a single QUERY (including 'dir')
+            Cursor c = null;
+            if (getContentProviderClient() != null) {
+                try {
+                    c = getContentProviderClient().query(ProviderTableMeta.CONTENT_URI, 
+                            null,
+                            ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ? ",
+                            new String[] { mAccount.name, folder.getRemotePath() + "%"  }, ProviderTableMeta.FILE_PATH + " ASC ");
+                } catch (RemoteException e) {
+                    Log_OC.e(TAG, e.getMessage());
+                }
+            } else {
+                c = getContentResolver().query(ProviderTableMeta.CONTENT_URI, 
+                        null,
+                        ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ? ",
+                        new String[] { mAccount.name, folder.getRemotePath() + "%"  }, ProviderTableMeta.FILE_PATH + " ASC ");
+            }
+
+            /// 2. prepare a batch of update operations to change all the descendants
+            ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(c.getCount());
+            int lengthOfOldPath = folder.getRemotePath().length();
+            String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name);
+            int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath;
+            if (c.moveToFirst()) {
+                do {
+                    ContentValues cv = new ContentValues(); // don't take the constructor out of the loop and clear the object
+                    OCFile child = createFileInstance(c);
+                    cv.put(ProviderTableMeta.FILE_PATH, newPath + child.getRemotePath().substring(lengthOfOldPath));
+                    if (child.getStoragePath() != null && child.getStoragePath().startsWith(defaultSavePath)) {
+                        cv.put(ProviderTableMeta.FILE_STORAGE_PATH, defaultSavePath + newPath + child.getStoragePath().substring(lengthOfOldStoragePath));
+                    }
+                    operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
+                            withValues(cv).
+                            withSelection(  ProviderTableMeta._ID + "=?", 
+                                    new String[] { String.valueOf(child.getFileId()) })
+                                    .build());
+                } while (c.moveToNext());
+            }
+            c.close();
+
+            /// 3. apply updates in batch
+            try {
+                if (getContentResolver() != null) {
+                    getContentResolver().applyBatch(ProviderMeta.AUTHORITY_FILES, operations);
+
+                } else {
+                    getContentProviderClient().applyBatch(operations);
+                }
+
+            } catch (OperationApplicationException e) {
+                Log_OC.e(TAG, "Fail to update descendants of " + folder.getFileId() + " in database", e);
+
+            } catch (RemoteException e) {
+                Log_OC.e(TAG, "Fail to update desendants of " + folder.getFileId() + " in database", e);
+            }
 
-        } else {
-            return new Vector<OCFile>();
         }
     }
 
-    private Vector<OCFile> getDirectoryContent(long parentId) {
+    
+    private Vector<OCFile> getFolderContent(long parentId) {
 
         Vector<OCFile> ret = new Vector<OCFile>();
 
@@ -347,9 +510,9 @@ public class FileDataStorageManager {
                 String.valueOf(parentId));
         Cursor c = null;
 
-        if (getContentProvider() != null) {
+        if (getContentProviderClient() != null) {
             try {
-                c = getContentProvider().query(req_uri, null, 
+                c = getContentProviderClient().query(req_uri, null, 
                         ProviderTableMeta.FILE_PARENT + "=?" ,
                         new String[] { String.valueOf(parentId)}, null);
             } catch (RemoteException e) {
@@ -377,6 +540,13 @@ public class FileDataStorageManager {
     }
     
     
+    private OCFile createRootDir() {
+        OCFile file = new OCFile(OCFile.ROOT_PATH);
+        file.setMimetype("DIR");
+        file.setParentId(FileDataStorageManager.ROOT_PARENT_ID);
+        saveFile(file);
+        return file;
+    }
 
     private boolean fileExists(String cmp_key, String value) {
         Cursor c;
@@ -390,7 +560,7 @@ public class FileDataStorageManager {
                                     new String[] { value, mAccount.name }, null);
         } else {
             try {
-                c = getContentProvider().query(
+                c = getContentProviderClient().query(
                         ProviderTableMeta.CONTENT_URI,
                         null,
                         cmp_key + "=? AND "
@@ -420,7 +590,7 @@ public class FileDataStorageManager {
                                     new String[] { value, mAccount.name }, null);
         } else {
             try {
-                c = getContentProvider().query(
+                c = getContentProviderClient().query(
                         ProviderTableMeta.CONTENT_URI,
                         null,
                         key + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER
@@ -444,7 +614,7 @@ public class FileDataStorageManager {
                     .getColumnIndex(ProviderTableMeta.FILE_PARENT)));
             file.setMimetype(c.getString(c
                     .getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)));
-            if (!file.isDirectory()) {
+            if (!file.isFolder()) {
                 file.setStoragePath(c.getString(c
                         .getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
                 if (file.getStoragePath() == null) {
@@ -476,170 +646,6 @@ public class FileDataStorageManager {
         return file;
     }
 
-    public void removeFile(OCFile file, boolean removeLocalCopy) {
-        Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId());
-        if (getContentProvider() != null) {
-            try {
-                getContentProvider().delete(file_uri,
-                        ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
-                        new String[]{mAccount.name});
-            } catch (RemoteException e) {
-                e.printStackTrace();
-            }
-        } else {
-            getContentResolver().delete(file_uri,
-                    ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
-                    new String[]{mAccount.name});
-        }
-        if (file.isDown() && removeLocalCopy) {
-            new File(file.getStoragePath()).delete();
-        }
-        if (file.isDirectory() && removeLocalCopy) {
-            File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
-            if (f.exists() && f.isDirectory() && (f.list() == null || f.list().length == 0)) {
-                f.delete();
-            }
-        }
-        
-        if (file.getFileLength() > 0) {
-            updateSizesToTheRoot(file.getParentId());
-        }
-    }
-
-    public void removeDirectory(OCFile dir, boolean removeDBData, boolean removeLocalContent) {
-        // TODO consider possible failures
-        if (dir != null && dir.isDirectory() && dir.getFileId() != -1) {
-            Vector<OCFile> children = getDirectoryContent(dir);
-            if (children.size() > 0) {
-                OCFile child = null;
-                for (int i=0; i<children.size(); i++) {
-                    child = children.get(i);
-                    if (child.isDirectory()) {
-                        removeDirectory(child, removeDBData, removeLocalContent);
-                    } else {
-                        if (removeDBData) {
-                            removeFile(child, removeLocalContent);
-                        } else if (removeLocalContent) {
-                            if (child.isDown()) {
-                                new File(child.getStoragePath()).delete();
-                            }
-                        }
-                    }
-                }
-            }
-            if (removeDBData) {
-                removeFile(dir, true);
-            }
-            
-            if (dir.getFileLength() > 0) {
-                updateSizesToTheRoot(dir.getParentId());
-            }
-        }
-    }
-
-
-    /**
-     * Updates database for a folder that was moved to a different location.
-     * 
-     * TODO explore better (faster) implementations
-     * TODO throw exceptions up !
-     */
-    public void moveDirectory(OCFile dir, String newPath) {
-        // TODO check newPath
-
-        if (dir != null && dir.isDirectory() && dir.fileExists() && !dir.getFileName().equals(OCFile.PATH_SEPARATOR)) {
-            /// 1. get all the descendants of 'dir' in a single QUERY (including 'dir')
-            Cursor c = null;
-            if (getContentProvider() != null) {
-                try {
-                    c = getContentProvider().query(ProviderTableMeta.CONTENT_URI, 
-                            null,
-                            ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ? ",
-                            new String[] { mAccount.name, dir.getRemotePath() + "%"  }, ProviderTableMeta.FILE_PATH + " ASC ");
-                } catch (RemoteException e) {
-                    Log_OC.e(TAG, e.getMessage());
-                }
-            } else {
-                c = getContentResolver().query(ProviderTableMeta.CONTENT_URI, 
-                        null,
-                        ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ? ",
-                        new String[] { mAccount.name, dir.getRemotePath() + "%"  }, ProviderTableMeta.FILE_PATH + " ASC ");
-            }
-
-            /// 2. prepare a batch of update operations to change all the descendants
-            ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(c.getCount());
-            int lengthOfOldPath = dir.getRemotePath().length();
-            String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name);
-            int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath;
-            if (c.moveToFirst()) {
-                do {
-                    ContentValues cv = new ContentValues(); // don't take the constructor out of the loop and clear the object
-                    OCFile child = createFileInstance(c);
-                    cv.put(ProviderTableMeta.FILE_PATH, newPath + child.getRemotePath().substring(lengthOfOldPath));
-                    if (child.getStoragePath() != null && child.getStoragePath().startsWith(defaultSavePath)) {
-                        cv.put(ProviderTableMeta.FILE_STORAGE_PATH, defaultSavePath + newPath + child.getStoragePath().substring(lengthOfOldStoragePath));
-                    }
-                    operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
-                            withValues(cv).
-                            withSelection(  ProviderTableMeta._ID + "=?", 
-                                    new String[] { String.valueOf(child.getFileId()) })
-                                    .build());
-                } while (c.moveToNext());
-            }
-            c.close();
-
-            /// 3. apply updates in batch
-            try {
-                if (getContentResolver() != null) {
-                    getContentResolver().applyBatch(ProviderMeta.AUTHORITY_FILES, operations);
-
-                } else {
-                    getContentProvider().applyBatch(operations);
-                }
-
-            } catch (OperationApplicationException e) {
-                Log_OC.e(TAG, "Fail to update descendants of " + dir.getFileId() + " in database", e);
-
-            } catch (RemoteException e) {
-                Log_OC.e(TAG, "Fail to update desendants of " + dir.getFileId() + " in database", e);
-            }
-
-        }
-    }
-
-    public Vector<OCFile> getDirectoryImages(OCFile directory) {
-        Vector<OCFile> ret = new Vector<OCFile>(); 
-        if (directory != null) {
-            // TODO better implementation, filtering in the access to database (if possible) instead of here 
-            Vector<OCFile> tmp = getDirectoryContent(directory);
-            OCFile current = null; 
-            for (int i=0; i<tmp.size(); i++) {
-                current = tmp.get(i);
-                if (current.isImage()) {
-                    ret.add(current);
-                }
-            }
-        }
-        return ret;
-    }
-
-    /**
-     * Calculate and save the folderSize on DB
-     * @param id
-     */
-    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
      */
@@ -652,7 +658,7 @@ public class FileDataStorageManager {
                      new String[] { String.valueOf(id) });
         } else {
             try {
-                result = getContentProvider().update(ProviderTableMeta.CONTENT_URI, cv, ProviderTableMeta._ID + "=?", 
+                result = getContentProviderClient().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());

+ 11 - 10
src/com/owncloud/android/datamodel/OCFile.java

@@ -41,6 +41,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     };
 
     public static final String PATH_SEPARATOR = "/";
+    public static final String ROOT_PATH = PATH_SEPARATOR;
 
     private static final String TAG = OCFile.class.getSimpleName();
     
@@ -146,11 +147,11 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     }
 
     /**
-     * Use this to find out if this file is a Directory
+     * Use this to find out if this file is a folder.
      * 
-     * @return true if it is a directory
+     * @return true if it is a folder
      */
-    public boolean isDirectory() {
+    public boolean isFolder() {
         return mMimeType != null && mMimeType.equals("DIR");
     }
 
@@ -257,7 +258,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
      */
     public String getFileName() {
         File f = new File(getRemotePath());
-        return f.getName().length() == 0 ? PATH_SEPARATOR : f.getName();
+        return f.getName().length() == 0 ? ROOT_PATH : f.getName();
     }
     
     /**
@@ -267,11 +268,11 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
      */
     public void setFileName(String name) {
         Log_OC.d(TAG, "OCFile name changin from " + mRemotePath);
-        if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) && !mRemotePath.equals(PATH_SEPARATOR)) {
+        if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) && !mRemotePath.equals(ROOT_PATH)) {
             String parent = (new File(getRemotePath())).getParent();
             parent = (parent.endsWith(PATH_SEPARATOR)) ? parent : parent + PATH_SEPARATOR;
             mRemotePath =  parent + name;
-            if (isDirectory()) {
+            if (isFolder()) {
                 mRemotePath += PATH_SEPARATOR;
             }
             Log_OC.d(TAG, "OCFile name changed to " + mRemotePath);
@@ -296,7 +297,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
      *             not a directory
      */
     public void addFile(OCFile file) throws IllegalStateException {
-        if (isDirectory()) {
+        if (isFolder()) {
             file.mParentId = mId;
             mNeedsUpdating = true;
             return;
@@ -419,11 +420,11 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     @Override
     public int compareTo(OCFile another) {
-        if (isDirectory() && another.isDirectory()) {
+        if (isFolder() && another.isFolder()) {
             return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase());
-        } else if (isDirectory()) {
+        } else if (isFolder()) {
             return -1;
-        } else if (another.isDirectory()) {
+        } else if (another.isFolder()) {
             return 1;
         }
         return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase());

+ 1 - 1
src/com/owncloud/android/files/services/FileDownloader.java

@@ -231,7 +231,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
             if (account == null || file == null) return false;
             String targetKey = buildRemoteName(account, file);
             synchronized (mPendingDownloads) {
-                if (file.isDirectory()) {
+                if (file.isFolder()) {
                     // this can be slow if there are many downloads :(
                     Iterator<String> it = mPendingDownloads.keySet().iterator();
                     boolean found = false;

+ 1 - 1
src/com/owncloud/android/files/services/FileUploader.java

@@ -376,7 +376,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
                 return false;
             String targetKey = buildRemoteName(account, file);
             synchronized (mPendingUploads) {
-                if (file.isDirectory()) {
+                if (file.isFolder()) {
                     // this can be slow if there are many uploads :(
                     Iterator<String> it = mPendingUploads.keySet().iterator();
                     boolean found = false;

+ 2 - 2
src/com/owncloud/android/operations/RemoveFileOperation.java

@@ -81,8 +81,8 @@ public class RemoveFileOperation extends RemoteOperation {
             delete = new DeleteMethod(client.getBaseUri() + WebdavUtils.encodePath(mFileToRemove.getRemotePath()));
             int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);
             if (delete.succeeded() || status == HttpStatus.SC_NOT_FOUND) {
-                if (mFileToRemove.isDirectory()) {
-                    mDataStorageManager.removeDirectory(mFileToRemove, true, mDeleteLocalCopy);
+                if (mFileToRemove.isFolder()) {
+                    mDataStorageManager.removeFolder(mFileToRemove, true, mDeleteLocalCopy);
                 } else {
                     mDataStorageManager.removeFile(mFileToRemove, mDeleteLocalCopy);
                 }

+ 3 - 3
src/com/owncloud/android/operations/RenameFileOperation.java

@@ -94,7 +94,7 @@ public class RenameFileOperation extends RemoteOperation {
             String parent = (new File(mFile.getRemotePath())).getParent();
             parent = (parent.endsWith(OCFile.PATH_SEPARATOR)) ? parent : parent + OCFile.PATH_SEPARATOR; 
             mNewRemotePath =  parent + mNewName;
-            if (mFile.isDirectory()) {
+            if (mFile.isFolder()) {
                 mNewRemotePath += OCFile.PATH_SEPARATOR;
             }
             
@@ -113,7 +113,7 @@ public class RenameFileOperation extends RemoteOperation {
             int status = client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT);
             if (move.succeeded()) {
 
-                if (mFile.isDirectory()) {
+                if (mFile.isFolder()) {
                     saveLocalDirectory();
                     
                 } else {
@@ -152,7 +152,7 @@ public class RenameFileOperation extends RemoteOperation {
 
     
     private void saveLocalDirectory() {
-        mStorageManager.moveDirectory(mFile, mNewRemotePath);
+        mStorageManager.moveFolder(mFile, mNewRemotePath);
         String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
         File localDir = new File(localPath);
         if (localDir.exists()) {

+ 6 - 6
src/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -189,7 +189,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
                 if (status == HttpStatus.SC_NOT_FOUND) {
                     if (mStorageManager.fileExists(mLocalFolder.getFileId())) {
                         String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
-                        mStorageManager.removeDirectory(mLocalFolder, true, (mLocalFolder.isDown() && mLocalFolder.getStoragePath().startsWith(currentSavePath)));
+                        mStorageManager.removeFolder(mLocalFolder, true, (mLocalFolder.isDown() && mLocalFolder.getStoragePath().startsWith(currentSavePath)));
                     }
                 }
                 result = new RemoteOperationResult(false, status, query.getResponseHeaders());
@@ -251,7 +251,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
                 mStorageManager.saveFile(remoteFolder);
             }
             
-            mChildren = mStorageManager.getDirectoryContent(mLocalFolder);
+            mChildren = mStorageManager.getFolderContent(mLocalFolder);
             
         } else {
             // read info of folder contents
@@ -325,14 +325,14 @@ public class SynchronizeFolderOperation extends RemoteOperation {
      *  Removes obsolete children in the folder after saving all the new data.
      */
     private void removeObsoleteFiles() {
-        mChildren = mStorageManager.getDirectoryContent(mLocalFolder);
+        mChildren = mStorageManager.getFolderContent(mLocalFolder);
         OCFile file;
         for (int i=0; i < mChildren.size(); ) {
             file = mChildren.get(i);
             if (file.getLastSyncDateForProperties() != mCurrentSyncTime) {
-                if (file.isDirectory()) {
+                if (file.isFolder()) {
                     Log_OC.d(TAG, "removing folder: " + file);
-                    mStorageManager.removeDirectory(file, true, true);
+                    mStorageManager.removeFolder(file, true, true);
                 } else {
                     Log_OC.d(TAG, "removing file: " + file);
                     mStorageManager.removeFile(file, true);
@@ -468,7 +468,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
      * @param file      File to associate a possible 'lost' local file.
      */
     private void searchForLocalFileInDefaultPath(OCFile file) {
-        if (file.getStoragePath() == null && !file.isDirectory()) {
+        if (file.getStoragePath() == null && !file.isFolder()) {
             File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
             if (f.exists()) {
                 file.setStoragePath(f.getAbsolutePath());

+ 2 - 2
src/com/owncloud/android/syncadapter/FileSyncAdapter.java

@@ -149,7 +149,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             updateOCVersion();
             mCurrentSyncTime = System.currentTimeMillis();
             if (!mCancellation) {
-                synchronizeFolder(getStorageManager().getFileByPath(OCFile.PATH_SEPARATOR), true);
+                synchronizeFolder(getStorageManager().getFileByPath(OCFile.ROOT_PATH), true);
                 
             } else {
                 Log_OC.d(TAG, "Leaving synchronization before synchronizing the root folder because cancelation request");
@@ -315,7 +315,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         int i;
         for (i=0; i < files.size() && !mCancellation; i++) {
             OCFile newFile = files.get(i);
-            if (newFile.isDirectory()) {
+            if (newFile.isFolder()) {
                 synchronizeFolder(newFile, false);
             }
         }

+ 12 - 12
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -228,7 +228,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
             }
             if (file == null) {
                 // fall back to root folder
-                file = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);  // never returns null
+                file = mStorageManager.getFileByPath(OCFile.ROOT_PATH);  // never returns null
             }
             setFile(file);
             setNavigationListWithFolder(file);
@@ -237,8 +237,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                 initFragmentsWithFile();
                 
             } else {
-                updateFragmentsVisibility(!file.isDirectory());
-                updateNavigationElementsInActionBar(file.isDirectory() ? null : file);
+                updateFragmentsVisibility(!file.isFolder());
+                updateNavigationElementsInActionBar(file.isFolder() ? null : file);
             }
             
             
@@ -251,8 +251,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     private void setNavigationListWithFolder(OCFile file) {
         mDirectories.clear();
         OCFile fileIt = file;
-        while(fileIt != null && fileIt.getFileName() != OCFile.PATH_SEPARATOR) {
-            if (fileIt.isDirectory()) {
+        while(fileIt != null && fileIt.getFileName() != OCFile.ROOT_PATH) {
+            if (fileIt.isFolder()) {
                 mDirectories.add(fileIt.getFileName());
             }
             fileIt = mStorageManager.getFileById(fileIt.getParentId());
@@ -303,7 +303,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
 
     private Fragment chooseInitialSecondFragment(OCFile file) {
         Fragment secondFragment = null;
-        if (file != null && !file.isDirectory()) {
+        if (file != null && !file.isFolder()) {
             if (file.isDown() && PreviewMediaFragment.canBePreviewed(file) 
                     && file.getLastSyncDateForProperties() > 0  // temporal fix
                     ) {
@@ -820,10 +820,10 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     /**
      * Pushes a directory to the drop down list
      * @param directory to push
-     * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
+     * @throws IllegalArgumentException If the {@link OCFile#isFolder()} returns false.
      */
     public void pushDirname(OCFile directory) {
-        if(!directory.isDirectory()){
+        if(!directory.isFolder()){
             throw new IllegalArgumentException("Only directories may be pushed!");
         }
         mDirectories.insert(directory.getFileName(), 0);
@@ -895,7 +895,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                     browseToRoot();
                     
                 } else {
-                    if (currentFile == null && !getFile().isDirectory()) {
+                    if (currentFile == null && !getFile().isFolder()) {
                         // currently selected file was removed in the server, and now we know it
                         cleanSecondFragment();
                         currentFile = currentDir;
@@ -995,7 +995,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
             while (mDirectories.getCount() > 1) {
                 popDirname();
             }
-            OCFile root = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
+            OCFile root = mStorageManager.getFileByPath(OCFile.ROOT_PATH);
             listOfFiles.listDirectory(root);
             setFile(listOfFiles.getCurrentFile());
             startSyncFolderOperation(root);
@@ -1005,7 +1005,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     
     
     public void browseTo(OCFile folder) {
-        if (folder == null || !folder.isDirectory()) {
+        if (folder == null || !folder.isFolder()) {
             throw new IllegalArgumentException("Trying to browse to invalid folder " + folder);
         }
         OCFileListFragment listOfFiles = getListOfFilesFragment(); 
@@ -1433,7 +1433,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     private OCFile getCurrentDir() {
         OCFile file = getFile();
         if (file != null) {
-            if (file.isDirectory()) {
+            if (file.isFolder()) {
                 return file;
             } else if (mStorageManager != null) {
                 return mStorageManager.getFileById(file.getParentId());

+ 2 - 2
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -135,7 +135,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
             TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
             ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
             
-            if (!file.isDirectory()) {
+            if (!file.isFolder()) {
                 fileSizeV.setVisibility(View.VISIBLE);
                 fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
                 lastModV.setVisibility(View.VISIBLE);
@@ -202,7 +202,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
             mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
         }
         if (mStorageManager != null) {
-            mFiles = mStorageManager.getDirectoryContent(mFile);
+            mFiles = mStorageManager.getFolderContent(mFile);
         } else {
             mFiles = null;
         }

+ 1 - 1
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -415,7 +415,7 @@ public class FileDetailFragment extends FileFragment implements
     private void renameFile() {
         OCFile file = getFile();
         String fileName = file.getFileName();
-        int extensionStart = file.isDirectory() ? -1 : fileName.lastIndexOf(".");
+        int extensionStart = file.isFolder() ? -1 : fileName.lastIndexOf(".");
         int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length();
         EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
         dialog.show(getFragmentManager(), "nameeditdialog");

+ 8 - 8
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -142,7 +142,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
                 parentDir = storageManager.getFileByPath(parentPath);
                 moveCount++;
             } else {
-                parentDir = storageManager.getFileByPath(OCFile.PATH_SEPARATOR);    // never returns null; keep the path in root folder
+                parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH);    // never returns null; keep the path in root folder
             }
             while (parentDir == null) {
                 parentPath = new File(parentPath).getParent();
@@ -166,7 +166,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
     public void onItemClick(AdapterView<?> l, View v, int position, long id) {
         OCFile file = (OCFile) mAdapter.getItem(position);
         if (file != null) {
-            if (file.isDirectory()) { 
+            if (file.isFolder()) { 
                 // update state and view of this fragment
                 listDirectory(file);
                 // then, notify parent activity to let it update its state and view, and other fragments
@@ -213,7 +213,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         List<Integer> toDisable = new ArrayList<Integer>();  
         
         MenuItem item = null;
-        if (targetFile.isDirectory()) {
+        if (targetFile.isFolder()) {
             // contextual menu for folders
             toHide.add(R.id.action_open_file_with);
             toHide.add(R.id.action_download_file);
@@ -285,7 +285,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         switch (item.getItemId()) {
             case R.id.action_rename_file: {
                 String fileName = mTargetFile.getFileName();
-                int extensionStart = mTargetFile.isDirectory() ? -1 : fileName.lastIndexOf(".");
+                int extensionStart = mTargetFile.isFolder() ? -1 : fileName.lastIndexOf(".");
                 int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length();
                 EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
                 dialog.show(getFragmentManager(), EditNameDialog.TAG);
@@ -295,7 +295,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
                 int messageStringId = R.string.confirmation_remove_alert;
                 int posBtnStringId = R.string.confirmation_remove_remote;
                 int neuBtnStringId = -1;
-                if (mTargetFile.isDirectory()) {
+                if (mTargetFile.isFolder()) {
                     messageStringId = R.string.confirmation_remove_folder_alert;
                     posBtnStringId = R.string.confirmation_remove_remote_and_local;
                     neuBtnStringId = R.string.confirmation_remove_folder_local;
@@ -389,7 +389,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         
         
             // If that's not a directory -> List its parent
-            if(!directory.isDirectory()){
+            if(!directory.isFolder()){
                 Log_OC.w(TAG, "You see, that is not a directory -> " + directory.toString());
                 directory = storageManager.getFileById(directory.getParentId());
             }
@@ -484,9 +484,9 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
     @Override
     public void onNeutral(String callerTag) {
         File f = null;
-        if (mTargetFile.isDirectory()) {
+        if (mTargetFile.isFolder()) {
             // TODO run in a secondary thread?
-            mContainerActivity.getStorageManager().removeDirectory(mTargetFile, false, true);
+            mContainerActivity.getStorageManager().removeFolder(mTargetFile, false, true);
             
         } else if (mTargetFile.isDown() && (f = new File(mTargetFile.getStoragePath())).exists()) {
             f.delete();

+ 1 - 1
src/com/owncloud/android/ui/preview/PreviewImageActivity.java

@@ -107,7 +107,7 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
         OCFile parentFolder = mStorageManager.getFileById(getFile().getParentId());
         if (parentFolder == null) {
             // should not be necessary
-            parentFolder = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
+            parentFolder = mStorageManager.getFileByPath(OCFile.ROOT_PATH);
         }
         mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), parentFolder, getAccount(), mStorageManager);
         mViewPager = (ViewPager) findViewById(R.id.fragmentPager);

+ 1 - 1
src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java

@@ -71,7 +71,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
 
         mAccount = account;
         mStorageManager = storageManager;
-        mImageFiles = mStorageManager.getDirectoryImages(parentFolder); 
+        mImageFiles = mStorageManager.getFolderImages(parentFolder); 
         mObsoleteFragments = new HashSet<Object>();
         mObsoletePositions = new HashSet<Integer>();
         mDownloadErrors = new HashSet<Integer>();