From: David A. Velasco Date: Mon, 14 Oct 2013 11:00:49 +0000 (+0200) Subject: Some cleanup and methods renamed in FileDataStorageManager X-Git-Tag: oc-android-1.5.5~155^2~16 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/d8de614d78c283d6d09849818c8043006e887256 Some cleanup and methods renamed in FileDataStorageManager --- diff --git a/src/com/owncloud/android/Uploader.java b/src/com/owncloud/android/Uploader.java index 9ce64454..fe1527a0 100644 --- a/src/com/owncloud/android/Uploader.java +++ b/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 tmpfiles = mStorageManager.getDirectoryContent(mFile); + Vector tmpfiles = mStorageManager.getFolderContent(mFile); if (tmpfiles.size() <= 0) return; // filter on dirtype Vector files = new Vector(); 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 files = mStorageManager.getDirectoryContent(mFile); + Vector files = mStorageManager.getFolderContent(mFile); List> data = new LinkedList>(); for (OCFile f : files) { HashMap h = new HashMap(); - if (f.isDirectory()) { + if (f.isFolder()) { h.put("dirname", f.getFileName()); data.add(h); } diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 39ddb927..cd793b63 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/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 getFolderContent(OCFile f) { + if (f != null && f.isFolder() && f.getFileId() != -1) { + return getFolderContent(f.getFileId()); + + } else { + return new Vector(); + } + } + + + public Vector getFolderImages(OCFile folder) { + Vector ret = new Vector(); + if (folder != null) { + // TODO better implementation, filtering in the access to database (if possible) instead of here + Vector tmp = getFolderContent(folder); + OCFile current = null; + for (int i=0; i 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 children = getFolderContent(folder); + if (children.size() > 0) { + OCFile child = null; + for (int i=0; i 0) { + updateSizesToTheRoot(folder.getParentId()); + } + } } - public void setContentProvider(ContentProviderClient cp) { - mContentProvider = cp; - } - public ContentProviderClient getContentProvider() { - return mContentProvider; - } - - public Vector 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 operations = new ArrayList(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(); } } - private Vector getDirectoryContent(long parentId) { + + private Vector getFolderContent(long parentId) { Vector ret = new Vector(); @@ -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 children = getDirectoryContent(dir); - if (children.size() > 0) { - OCFile child = null; - for (int i=0; i 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 operations = new ArrayList(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 getDirectoryImages(OCFile directory) { - Vector ret = new Vector(); - if (directory != null) { - // TODO better implementation, filtering in the access to database (if possible) instead of here - Vector tmp = getDirectoryContent(directory); - OCFile current = null; - for (int i=0; i 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()); diff --git a/src/com/owncloud/android/datamodel/OCFile.java b/src/com/owncloud/android/datamodel/OCFile.java index 87a38a69..9bd84abd 100644 --- a/src/com/owncloud/android/datamodel/OCFile.java +++ b/src/com/owncloud/android/datamodel/OCFile.java @@ -41,6 +41,7 @@ public class OCFile implements Parcelable, Comparable { }; 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 { } /** - * 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 { */ 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 { */ 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 { * 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 { @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()); diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index e07a17b5..a37a86a9 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/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 it = mPendingDownloads.keySet().iterator(); boolean found = false; diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index c606b687..81012ed7 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/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 it = mPendingUploads.keySet().iterator(); boolean found = false; diff --git a/src/com/owncloud/android/operations/RemoveFileOperation.java b/src/com/owncloud/android/operations/RemoveFileOperation.java index 192ca61c..7c8422ee 100644 --- a/src/com/owncloud/android/operations/RemoveFileOperation.java +++ b/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); } diff --git a/src/com/owncloud/android/operations/RenameFileOperation.java b/src/com/owncloud/android/operations/RenameFileOperation.java index 06bb91c2..f9bb4242 100644 --- a/src/com/owncloud/android/operations/RenameFileOperation.java +++ b/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()) { diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index f85e4e7f..73adc318 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/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()); diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index 4b40ff49..6b6264f4 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java +++ b/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); } } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 477515df..1363fe2c 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/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()); diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 40003184..5e6d01b2 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/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; } diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index b5f1186d..1c076da6 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/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"); diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 4f0a5a43..c48a5c14 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/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 toDisable = new ArrayList(); 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(); diff --git a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java index 93078b52..863c926c 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java +++ b/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); diff --git a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java b/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java index ab786909..6ef06189 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java +++ b/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(); mObsoletePositions = new HashSet(); mDownloadErrors = new HashSet();