import android.provider.MediaStore;
import com.owncloud.android.MainApp;
-import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.FileUtils;
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;
}
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)
cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
if (!file.isFolder())
boolean sameRemotePath = fileExists(file.getRemotePath());
if (sameRemotePath || fileExists(file.getFileId())) { // for renamed files; no more delete and create
- OCFile oldFile = null;
+ OCFile oldFile;
if (sameRemotePath) {
oldFile = getFileByPath(file.getRemotePath());
file.setFileId(oldFile.getFileId());
}
}
-// if (file.isFolder()) {
-// updateFolderSize(file.getFileId());
-// } else {
-// updateFolderSize(file.getParentId());
-// }
-
return overriden;
}
for (OCFile file : filesToRemove) {
if (file.getParentId() == folder.getFileId()) {
whereArgs = new String[]{mAccount.name, file.getRemotePath()};
- //Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, "" + file.getFileId());
if (file.isFolder()) {
operations.add(ContentProviderOperation.newDelete(
ContentUris.withAppendedId(
}
}
- //updateFolderSize(folder.getFileId());
-
}
-// /**
-// *
-// * @param id
-// */
-// private void updateFolderSize(long id) {
-// if (id > FileDataStorageManager.ROOT_PARENT_ID) {
-// Log_OC.d(TAG, "Updating size of " + id);
-// if (getContentResolver() != null) {
-// getContentResolver().update(ProviderTableMeta.CONTENT_URI_DIR,
-// new ContentValues(),
- // won't be used, but cannot be null; crashes in KLP
-// ProviderTableMeta._ID + "=?",
-// new String[] { String.valueOf(id) });
-// } else {
-// try {
-// getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_DIR,
-// new ContentValues(),
- // won't be used, but cannot be null; crashes in KLP
-// ProviderTableMeta._ID + "=?",
-// new String[] { String.valueOf(id) });
-//
-// } catch (RemoteException e) {
-// Log_OC.e(
-// TAG, "Exception in update of folder size through compatibility patch " + e.getMessage());
-// }
-// }
-// } else {
-// Log_OC.e(TAG, "not updating size for folder " + id);
-// }
-// }
-
-
public boolean removeFile(OCFile file, boolean removeDBData, boolean removeLocalCopy) {
boolean success = true;
if (file != null) {
return file;
}
- /**
- * Returns if the file/folder is shared by link or not
- *
- * @param path Path of the file/folder
- * @return
- */
- public boolean isShareByLink(String path) {
- Cursor c = getCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path);
- OCFile file = null;
- if (c.moveToFirst()) {
- file = createFileInstance(c);
- }
- c.close();
- return file.isShareByLink();
- }
-
- /**
- * Returns the public link of the file/folder
- *
- * @param path Path of the file/folder
- * @return
- */
- public String getPublicLink(String path) {
- Cursor c = getCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path);
- OCFile file = null;
- if (c.moveToFirst()) {
- file = createFileInstance(c);
- }
- c.close();
- return file.getPublicLink();
- }
-
-
// Methods for Shares
public boolean saveShare(OCShare share) {
boolean overriden = false;
}
}
return preparedOperations;
-
- /*
- if (operations.size() > 0) {
- try {
- if (getContentResolver() != null) {
- getContentResolver().applyBatch(MainApp.getAuthority(), operations);
-
- } else {
- getContentProviderClient().applyBatch(operations);
- }
-
- } catch (OperationApplicationException e) {
- Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
-
- } catch (RemoteException e) {
- Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
- }
- }
- */
-
- /*
- if (getContentResolver() != null) {
-
- getContentResolver().delete(ProviderTableMeta.CONTENT_URI_SHARE,
- where,
- whereArgs);
- } else {
- try {
- getContentProviderClient().delete( ProviderTableMeta.CONTENT_URI_SHARE,
- where,
- whereArgs);
-
- } catch (RemoteException e) {
- Log_OC.e(TAG, "Exception deleting shares in a folder " + e.getMessage());
- }
- }
- */
- //}
}
public void triggerMediaScan(String path) {
}
/**
- * Adds a file to this directory. If this file is not a directory, an
- * exception gets thrown.
- *
- * @param file to add
- * @throws IllegalStateException if you try to add a something and this is
- * not a directory
- */
- public void addFile(OCFile file) throws IllegalStateException {
- if (isFolder()) {
- file.mParentId = mId;
- mNeedsUpdating = true;
- return;
- }
- throw new IllegalStateException(
- "This is not a directory where you can add stuff to!");
- }
-
- /**
* Used internally. Reset all file properties
*/
private void resetData() {
package com.owncloud.android.files.services;
import java.io.File;
-import java.io.IOException;
import java.util.AbstractList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
-import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.authentication.AuthenticatorActivity;
import android.accounts.Account;
import android.accounts.AccountManager;
-import android.accounts.AccountsException;
import android.accounts.OnAccountsUpdateListener;
import android.app.NotificationManager;
import android.app.PendingIntent;
String downloadKey = putResult.first;
requestedDownloads.add(downloadKey);
- // Store file on db with state 'downloading'
- /*
- TODO - check if helps with UI responsiveness,
- letting only folders use FileDownloaderBinder to check
- FileDataStorageManager storageManager =
- new FileDataStorageManager(account, getContentResolver());
- file.setDownloading(true);
- storageManager.saveFile(file);
- */
-
sendBroadcastNewDownload(newDownload, putResult.second);
} catch (IllegalArgumentException e) {
}
/**
- * Update the OC File after a unsuccessful download
- */
- private void updateUnsuccessfulDownloadedFile() {
- OCFile file = mStorageManager.getFileById(mCurrentDownload.getFile().getFileId());
- file.setDownloading(false);
- mStorageManager.saveFile(file);
- }
-
-
- /**
* Creates a status notification to show the download progress
*
* @param download Download operation starting.
package com.owncloud.android.files.services;
import java.io.File;
-import java.io.IOException;
import java.util.AbstractList;
import java.util.HashMap;
import java.util.Iterator;
import android.accounts.Account;
import android.accounts.AccountManager;
-import android.accounts.AccountsException;
import android.accounts.OnAccountsUpdateListener;
import android.app.NotificationManager;
import android.app.PendingIntent;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
-import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.OwnCloudClient;
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
- RemoteOperationResult result = null;
- File newFile = null;
- boolean moved = true;
+ RemoteOperationResult result;
+ File newFile;
+ boolean moved;
/// download will be performed to a temporal file, then moved to the final location
File tmpFile = new File(getTmpPath());
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import android.accounts.Account;
private boolean mWasRenamed = false;
private String mOriginalFileName = null;
private String mOriginalStoragePath = null;
- PutMethod mPutMethod = null;
private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
private AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
private Context mContext;
package com.owncloud.android.providers;
import java.io.File;
-import java.security.Provider;
import java.util.ArrayList;
import java.util.HashMap;
String remoteId = "";
if (c != null && c.moveToFirst()) {
remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
- //ThumbnailsCacheManager.removeFileFromCache(remoteId);
}
Log_OC.d(TAG, "Removing FILE " + remoteId);
}
}
- /*
- private int updateFolderSize(SQLiteDatabase db, String folderId) {
- int count = 0;
- String [] whereArgs = new String[] { folderId };
-
- // read current size saved for the folder
- long folderSize = 0;
- long folderParentId = -1;
- Uri selectFolderUri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, folderId);
- String[] folderProjection = new String[] { ProviderTableMeta.FILE_CONTENT_LENGTH, ProviderTableMeta.FILE_PARENT};
- String folderWhere = ProviderTableMeta._ID + "=?";
- Cursor folderCursor = query(db, selectFolderUri, folderProjection, folderWhere, whereArgs, null);
- if (folderCursor != null && folderCursor.moveToFirst()) {
- folderSize = folderCursor.getLong(folderCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH));;
- folderParentId = folderCursor.getLong(folderCursor.getColumnIndex(ProviderTableMeta.FILE_PARENT));;
- }
- folderCursor.close();
-
- // read and sum sizes of children
- long childrenSize = 0;
- Uri selectChildrenUri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, folderId);
- String[] childrenProjection = new String[] { ProviderTableMeta.FILE_CONTENT_LENGTH, ProviderTableMeta.FILE_PARENT};
- String childrenWhere = ProviderTableMeta.FILE_PARENT + "=?";
- Cursor childrenCursor = query(db, selectChildrenUri, childrenProjection, childrenWhere, whereArgs, null);
- if (childrenCursor != null && childrenCursor.moveToFirst()) {
- while (!childrenCursor.isAfterLast()) {
- childrenSize += childrenCursor.getLong(childrenCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH));
- childrenCursor.moveToNext();
- }
- }
- childrenCursor.close();
-
- // update if needed
- if (folderSize != childrenSize) {
- Log_OC.d("FileContentProvider", "Updating " + folderSize + " to " + childrenSize);
- ContentValues cv = new ContentValues();
- cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, childrenSize);
- count = db.update(ProviderTableMeta.FILE_TABLE_NAME, cv, folderWhere, whereArgs);
-
- // propagate update until root
- if (folderParentId > FileDataStorageManager.ROOT_PARENT_ID) {
- Log_OC.d("FileContentProvider", "Propagating update to " + folderParentId);
- updateFolderSize(db, String.valueOf(folderParentId));
- } else {
- Log_OC.d("FileContentProvider", "NOT propagating to " + folderParentId);
- }
- } else {
- Log_OC.d("FileContentProvider", "NOT updating, sizes are " + folderSize + " and " + childrenSize);
- }
- return count;
- }
-*/
-
@Override
public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
*/
@Override
public IBinder onBind(Intent intent) {
- //Log_OC.wtf(TAG, "onBind" );
return mOperationsBinder;
}
}
}
if (count == 0) {
- //mOperationResults.put(operation.hashCode(), result);
Pair<RemoteOperation, RemoteOperationResult> undispatched =
new Pair<RemoteOperation, RemoteOperationResult>(operation, result);
mUndispatchedFinishedOperations.put(((Runnable) operation).hashCode(), undispatched);
return view;\r
}\r
\r
- /**\r
- * Local Folder size in human readable format\r
- * \r
- * @param path\r
- * String\r
- * @return Size in human readable format\r
- */\r
- private String getFolderSizeHuman(String path) {\r
-\r
- File dir = new File(path);\r
-\r
- if (dir.exists()) {\r
- long bytes = FileStorageUtils.getFolderSize(dir);\r
- return DisplayUtils.bytesToHumanReadable(bytes);\r
- }\r
-\r
- return "0 B";\r
- }\r
-\r
- /**\r
- * Local Folder size\r
- * @param dir File\r
- * @return Size in bytes\r
- */\r
- private long getFolderSize(File dir) {\r
- if (dir.exists()) {\r
- long result = 0;\r
- File[] fileList = dir.listFiles();\r
- for(int i = 0; i < fileList.length; i++) {\r
- if(fileList[i].isDirectory()) {\r
- result += getFolderSize(fileList[i]);\r
- } else {\r
- result += fileList[i].length();\r
- }\r
- }\r
- return result;\r
- }\r
- return 0;\r
- } \r
-\r
@Override\r
public int getViewTypeCount() {\r
return 1;\r
public static final Integer SORT_SIZE = 2;
- //private static final String LOG_TAG = "FileStorageUtils";
-
public static final String getSavePath(String accountName) {
File sdCard = Environment.getExternalStorageDirectory();
return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/" + Uri.encode(accountName, "@");