From: David A. Velasco Date: Mon, 14 Oct 2013 12:55:50 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/refresh_folder_contents_when_browsed_into' into... X-Git-Tag: oc-android-1.5.5~155^2~15 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/47b7a164de81880078ed350b826198eb2edf3785?hp=98d95b576ead4119ec16719a72d83ca6db82b77a Merge remote-tracking branch 'origin/refresh_folder_contents_when_browsed_into' into refresh_folder_contents_when_browsed_into --- diff --git a/src/com/owncloud/android/Uploader.java b/src/com/owncloud/android/Uploader.java index 0ff09079..fe1527a0 100644 --- a/src/com/owncloud/android/Uploader.java +++ b/src/com/owncloud/android/Uploader.java @@ -55,7 +55,6 @@ import android.widget.SimpleAdapter; import android.widget.Toast; import com.owncloud.android.authentication.AccountAuthenticator; -import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileUploader; @@ -77,7 +76,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro private ArrayList mStreamsToUpload; private boolean mCreateDir; private String mUploadPath; - private DataStorageManager mStorageManager; + private FileDataStorageManager mStorageManager; private OCFile mFile; private final static int DIALOG_NO_ACCOUNT = 0; @@ -230,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"); @@ -295,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/DataStorageManager.java b/src/com/owncloud/android/datamodel/DataStorageManager.java deleted file mode 100644 index 133ab8de..00000000 --- a/src/com/owncloud/android/datamodel/DataStorageManager.java +++ /dev/null @@ -1,52 +0,0 @@ -/* ownCloud Android client application - * Copyright (C) 2012 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package com.owncloud.android.datamodel; - -import java.util.List; -import java.util.Vector; - -public interface DataStorageManager { - - public static final int ROOT_PARENT_ID = 0; - - public OCFile getFileByPath(String path); - - public OCFile getFileById(long id); - - public boolean fileExists(String path); - - public boolean fileExists(long id); - - public boolean saveFile(OCFile file); - - public void saveFiles(List files); - - public Vector getDirectoryContent(OCFile f); - - public void removeFile(OCFile file, boolean removeLocalCopy); - - public void removeDirectory(OCFile dir, boolean removeDBData, boolean removeLocalContent); - - public void moveDirectory(OCFile dir, String newPath); - - public Vector getDirectoryImages(OCFile mParentFolder); - - public void calculateFolderSize(long id); - -} diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 1c9ff7a5..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; @@ -42,27 +41,55 @@ import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; -public class FileDataStorageManager implements DataStorageManager { +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; } - @Override + + 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); OCFile file = null; @@ -70,22 +97,13 @@ public class FileDataStorageManager implements DataStorageManager { 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(DataStorageManager.ROOT_PARENT_ID); - saveFile(file); - return file; - } - - @Override public OCFile getFileById(long id) { Cursor c = getCursorForValue(ProviderTableMeta._ID, String.valueOf(id)); OCFile file = null; @@ -106,17 +124,42 @@ public class FileDataStorageManager implements DataStorageManager { return file; } - @Override public boolean fileExists(long id) { return fileExists(ProviderTableMeta._ID, String.valueOf(id)); } - @Override public boolean fileExists(String path) { return fileExists(ProviderTableMeta.FILE_PATH, path); } - @Override + + 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) { Iterator filesIt = files.iterator(); @@ -223,10 +265,10 @@ public class FileDataStorageManager implements DataStorageManager { cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength()); cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype()); cv.put(ProviderTableMeta.FILE_NAME, file.getFileName()); - if (file.getParentId() != DataStorageManager.ROOT_PARENT_ID) + 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()); @@ -238,7 +280,7 @@ public class FileDataStorageManager implements DataStorageManager { 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()); } @@ -254,7 +296,7 @@ public class FileDataStorageManager implements DataStorageManager { 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()); @@ -279,7 +321,7 @@ public class FileDataStorageManager implements DataStorageManager { results = getContentResolver().applyBatch(ProviderMeta.AUTHORITY_FILES, operations); } else { - results = getContentProvider().applyBatch(operations); + results = getContentProviderClient().applyBatch(operations); } } catch (OperationApplicationException e) { @@ -302,47 +344,164 @@ public class FileDataStorageManager implements DataStorageManager { } 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 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; - } - - @Override - 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(); @@ -351,9 +510,9 @@ public class FileDataStorageManager implements DataStorageManager { 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) { @@ -381,6 +540,13 @@ public class FileDataStorageManager implements DataStorageManager { } + 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; @@ -394,7 +560,7 @@ public class FileDataStorageManager implements DataStorageManager { new String[] { value, mAccount.name }, null); } else { try { - c = getContentProvider().query( + c = getContentProviderClient().query( ProviderTableMeta.CONTENT_URI, null, cmp_key + "=? AND " @@ -424,7 +590,7 @@ public class FileDataStorageManager implements DataStorageManager { new String[] { value, mAccount.name }, null); } else { try { - c = getContentProvider().query( + c = getContentProviderClient().query( ProviderTableMeta.CONTENT_URI, null, key + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER @@ -448,7 +614,7 @@ public class FileDataStorageManager implements DataStorageManager { .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) { @@ -480,175 +646,6 @@ public class FileDataStorageManager implements DataStorageManager { return file; } - @Override - 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()); - } - } - - @Override - 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 ! - */ - @Override - 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); - } - - } - } - - @Override - 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 */ @@ -661,7 +658,7 @@ public class FileDataStorageManager implements DataStorageManager { 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()); @@ -678,7 +675,7 @@ public class FileDataStorageManager implements DataStorageManager { OCFile file; - while (parentId != DataStorageManager.ROOT_PARENT_ID) { + while (parentId != FileDataStorageManager.ROOT_PARENT_ID) { // Update the size of the parent calculateFolderSize(parentId); 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/CreateFolderOperation.java b/src/com/owncloud/android/operations/CreateFolderOperation.java index 5745ec21..c86d2fc3 100644 --- a/src/com/owncloud/android/operations/CreateFolderOperation.java +++ b/src/com/owncloud/android/operations/CreateFolderOperation.java @@ -23,7 +23,7 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.jackrabbit.webdav.client.methods.MkColMethod; import com.owncloud.android.Log_OC; -import com.owncloud.android.datamodel.DataStorageManager; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import eu.alefzero.webdav.WebdavClient; @@ -43,7 +43,7 @@ public class CreateFolderOperation extends RemoteOperation { protected String mRemotePath; protected boolean mCreateFullPath; - protected DataStorageManager mStorageManager; + protected FileDataStorageManager mStorageManager; /** * Constructor @@ -52,7 +52,7 @@ public class CreateFolderOperation extends RemoteOperation { * @param createFullPath 'True' means that all the ancestor folders should be created if don't exist yet. * @param storageManager Reference to the local database corresponding to the account where the file is contained. */ - public CreateFolderOperation(String remotePath, boolean createFullPath, DataStorageManager storageManager) { + public CreateFolderOperation(String remotePath, boolean createFullPath, FileDataStorageManager storageManager) { mRemotePath = remotePath; mCreateFullPath = createFullPath; mStorageManager = storageManager; diff --git a/src/com/owncloud/android/operations/RemoveFileOperation.java b/src/com/owncloud/android/operations/RemoveFileOperation.java index 9dabfafd..7c8422ee 100644 --- a/src/com/owncloud/android/operations/RemoveFileOperation.java +++ b/src/com/owncloud/android/operations/RemoveFileOperation.java @@ -21,7 +21,7 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.jackrabbit.webdav.client.methods.DeleteMethod; import com.owncloud.android.Log_OC; -import com.owncloud.android.datamodel.DataStorageManager; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import eu.alefzero.webdav.WebdavClient; @@ -41,7 +41,7 @@ public class RemoveFileOperation extends RemoteOperation { OCFile mFileToRemove; boolean mDeleteLocalCopy; - DataStorageManager mDataStorageManager; + FileDataStorageManager mDataStorageManager; /** @@ -51,7 +51,7 @@ public class RemoveFileOperation extends RemoteOperation { * @param deleteLocalCopy When 'true', and a local copy of the file exists, it is also removed. * @param storageManager Reference to the local database corresponding to the account where the file is contained. */ - public RemoveFileOperation(OCFile fileToRemove, boolean deleteLocalCopy, DataStorageManager storageManager) { + public RemoveFileOperation(OCFile fileToRemove, boolean deleteLocalCopy, FileDataStorageManager storageManager) { mFileToRemove = fileToRemove; mDeleteLocalCopy = deleteLocalCopy; mDataStorageManager = storageManager; @@ -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 fddb8499..f9bb4242 100644 --- a/src/com/owncloud/android/operations/RenameFileOperation.java +++ b/src/com/owncloud/android/operations/RenameFileOperation.java @@ -26,7 +26,7 @@ import org.apache.jackrabbit.webdav.client.methods.DavMethodBase; import android.accounts.Account; import com.owncloud.android.Log_OC; -import com.owncloud.android.datamodel.DataStorageManager; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.utils.FileStorageUtils; @@ -51,7 +51,7 @@ public class RenameFileOperation extends RemoteOperation { private Account mAccount; private String mNewName; private String mNewRemotePath; - private DataStorageManager mStorageManager; + private FileDataStorageManager mStorageManager; /** @@ -62,7 +62,7 @@ public class RenameFileOperation extends RemoteOperation { * @param newName New name to set as the name of file. * @param storageManager Reference to the local database corresponding to the account where the file is contained. */ - public RenameFileOperation(OCFile file, Account account, String newName, DataStorageManager storageManager) { + public RenameFileOperation(OCFile file, Account account, String newName, FileDataStorageManager storageManager) { mFile = file; mAccount = account; mNewName = newName; @@ -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/SynchronizeFileOperation.java b/src/com/owncloud/android/operations/SynchronizeFileOperation.java index 2f80186a..ea115f1f 100644 --- a/src/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -27,7 +27,7 @@ import android.content.Context; import android.content.Intent; import com.owncloud.android.Log_OC; -import com.owncloud.android.datamodel.DataStorageManager; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileUploader; @@ -45,7 +45,7 @@ public class SynchronizeFileOperation extends RemoteOperation { private OCFile mLocalFile; private OCFile mServerFile; - private DataStorageManager mStorageManager; + private FileDataStorageManager mStorageManager; private Account mAccount; private boolean mSyncFileContents; private boolean mLocalChangeAlreadyKnown; @@ -56,7 +56,7 @@ public class SynchronizeFileOperation extends RemoteOperation { public SynchronizeFileOperation( OCFile localFile, OCFile serverFile, // make this null to let the operation checks the server; added to reuse info from SynchronizeFolderOperation - DataStorageManager storageManager, + FileDataStorageManager storageManager, Account account, boolean syncFileContents, boolean localChangeAlreadyKnown, diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index f8b69f4a..73adc318 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -37,7 +37,7 @@ import android.content.Context; import android.content.Intent; import com.owncloud.android.Log_OC; -import com.owncloud.android.datamodel.DataStorageManager; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.syncadapter.FileSyncService; @@ -74,7 +74,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { private boolean mUpdateFolderProperties; /** Access to the local database */ - private DataStorageManager mStorageManager; + private FileDataStorageManager mStorageManager; /** Account where the file to synchronize belongs */ private Account mAccount; @@ -114,7 +114,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { long currentSyncTime, boolean updateFolderProperties, boolean syncFullAccount, - DataStorageManager dataStorageManager, + FileDataStorageManager dataStorageManager, Account account, Context context ) { mLocalFolder = folder; @@ -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/AbstractOwnCloudSyncAdapter.java b/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java index 26bfff7e..43c0f2f2 100644 --- a/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java @@ -30,7 +30,7 @@ import org.apache.http.client.ClientProtocolException; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException; -import com.owncloud.android.datamodel.DataStorageManager; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.network.OwnCloudClientUtils; import android.accounts.Account; @@ -58,7 +58,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends private Account account; private ContentProviderClient contentProvider; //private Date lastUpdated; - private DataStorageManager mStoreManager; + private FileDataStorageManager mStoreManager; private WebdavClient mClient = null; @@ -91,11 +91,11 @@ public abstract class AbstractOwnCloudSyncAdapter extends this.contentProvider = contentProvider; } - public void setStorageManager(DataStorageManager storage_manager) { + public void setStorageManager(FileDataStorageManager storage_manager) { mStoreManager = storage_manager; } - public DataStorageManager getStorageManager() { + public FileDataStorageManager getStorageManager() { return mStoreManager; } 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/ConflictsResolveActivity.java b/src/com/owncloud/android/ui/activity/ConflictsResolveActivity.java index 61ac8f5f..f0895bfb 100644 --- a/src/com/owncloud/android/ui/activity/ConflictsResolveActivity.java +++ b/src/com/owncloud/android/ui/activity/ConflictsResolveActivity.java @@ -19,7 +19,6 @@ package com.owncloud.android.ui.activity; import com.owncloud.android.Log_OC; -import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileUploader; @@ -81,7 +80,7 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict finish(); } else { /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account - DataStorageManager storageManager = new FileDataStorageManager(getAccount(), getContentResolver()); + FileDataStorageManager storageManager = new FileDataStorageManager(getAccount(), getContentResolver()); file = storageManager.getFileByPath(file.getRemotePath()); // file = null if not in the current Account if (file != null) { setFile(file); diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 19533360..1363fe2c 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -60,7 +60,6 @@ import com.actionbarsherlock.view.Window; import com.owncloud.android.Log_OC; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountAuthenticator; -import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; @@ -103,7 +102,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa private ArrayAdapter mDirectories; /** Access point to the cached database for the current ownCloud {@link Account} */ - private DataStorageManager mStorageManager = null; + private FileDataStorageManager mStorageManager = null; private SyncBroadcastReceiver mSyncBroadcastReceiver; private UploadFinishReceiver mUploadFinishReceiver; @@ -229,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); @@ -238,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); } @@ -252,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()); @@ -304,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 ) { @@ -821,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); @@ -896,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; @@ -985,7 +984,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa * {@inheritDoc} */ @Override - public DataStorageManager getStorageManager() { + public FileDataStorageManager getStorageManager() { return mStorageManager; } @@ -996,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); @@ -1006,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(); @@ -1434,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 3e8eecd5..5e6d01b2 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -31,7 +31,7 @@ import android.widget.TextView; import com.owncloud.android.DisplayUtils; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; -import com.owncloud.android.datamodel.DataStorageManager; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; @@ -51,7 +51,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { private Context mContext; private OCFile mFile = null; private Vector mFiles = null; - private DataStorageManager mStorageManager; + private FileDataStorageManager mStorageManager; private Account mAccount; private TransferServiceGetter mTransferServiceGetter; //total size of a directory (recursive) @@ -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); @@ -195,14 +195,14 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { * @param directory New file to adapt. Can be NULL, meaning "no content to adapt". * @param updatedStorageManager Optional updated storage manager; used to replace mStorageManager if is different (and not NULL) */ - public void swapDirectory(OCFile directory, DataStorageManager updatedStorageManager) { + public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager) { mFile = directory; if (updatedStorageManager != null && updatedStorageManager != mStorageManager) { mStorageManager = updatedStorageManager; 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 10b132b5..c48a5c14 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -24,7 +24,6 @@ import java.util.List; import com.owncloud.android.Log_OC; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; -import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.FileHandler; @@ -32,11 +31,9 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.operations.OnRemoteOperationListener; import com.owncloud.android.operations.RemoteOperation; -import com.owncloud.android.operations.RemoteOperationResult; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; -import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.TransferServiceGetter; import com.owncloud.android.ui.adapter.FileListListAdapter; @@ -136,7 +133,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName int moveCount = 0; if(mFile != null){ - DataStorageManager storageManager = mContainerActivity.getStorageManager(); + FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); String parentPath = null; if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) { @@ -145,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(); @@ -169,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 @@ -216,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); @@ -288,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); @@ -298,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; @@ -377,7 +374,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName * @param directory File to be listed */ public void listDirectory(OCFile directory) { - DataStorageManager storageManager = mContainerActivity.getStorageManager(); + FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); if (storageManager != null) { // Check input parameters for null @@ -392,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()); } @@ -432,7 +429,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName /** * Getter for the current DataStorageManager in the container activity */ - public DataStorageManager getStorageManager(); + public FileDataStorageManager getStorageManager(); /** @@ -487,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 ef1e977c..863c926c 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java @@ -38,7 +38,6 @@ import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.Window; import com.owncloud.android.authentication.AccountUtils; -import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; @@ -69,7 +68,7 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT"; - private DataStorageManager mStorageManager; + private FileDataStorageManager mStorageManager; private ViewPager mViewPager; private PreviewImagePagerAdapter mPreviewImagePagerAdapter; @@ -108,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 3db62e96..6ef06189 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java +++ b/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java @@ -28,7 +28,7 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.view.ViewGroup; -import com.owncloud.android.datamodel.DataStorageManager; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.ui.fragment.FileFragment; @@ -45,7 +45,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { private Set mObsoleteFragments; private Set mObsoletePositions; private Set mDownloadErrors; - private DataStorageManager mStorageManager; + private FileDataStorageManager mStorageManager; private Map mCachedFragments; @@ -56,7 +56,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { * @param parentFolder Folder where images will be searched for. * @param storageManager Bridge to database. */ - public PreviewImagePagerAdapter(FragmentManager fragmentManager, OCFile parentFolder, Account account, DataStorageManager storageManager) { + public PreviewImagePagerAdapter(FragmentManager fragmentManager, OCFile parentFolder, Account account, FileDataStorageManager storageManager) { super(fragmentManager); if (fragmentManager == null) { @@ -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(); diff --git a/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java b/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java index 0cab2e2b..47441ffb 100644 --- a/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java +++ b/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java @@ -32,7 +32,6 @@ import android.widget.VideoView; import com.owncloud.android.Log_OC; import com.owncloud.android.R; -import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException; @@ -60,7 +59,7 @@ public class PreviewVideoActivity extends FileActivity implements OnCompletionLi private static final String TAG = PreviewVideoActivity.class.getSimpleName(); - private DataStorageManager mStorageManager; + private FileDataStorageManager mStorageManager; private int mSavedPlaybackPosition; // in the unit time handled by MediaPlayer.getCurrentPosition() private boolean mAutoplay; // when 'true', the playback starts immediately with the activity