use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class CreateFolderOperation method saveFolderInDB.
/**
* Save new directory in local database
*
* @return Instance of {@link OCFile} just created
*/
private OCFile saveFolderInDB() {
OCFile newDir = null;
if (mCreateFullPath && getStorageManager().getFileByPath(FileStorageUtils.getParentPath(mRemotePath)) == null) {
// When parent
// of remote path
// is not created
String[] subFolders = mRemotePath.split("/");
String composedRemotePath = "/";
// Create all the ancestors
for (String subFolder : subFolders) {
if (!subFolder.isEmpty()) {
composedRemotePath = composedRemotePath + subFolder + "/";
mRemotePath = composedRemotePath;
newDir = saveFolderInDB();
}
}
} else {
// Create directory on DB
newDir = new OCFile(mRemotePath);
newDir.setMimetype("DIR");
long parentId = getStorageManager().getFileByPath(FileStorageUtils.getParentPath(mRemotePath)).getFileId();
newDir.setParentId(parentId);
newDir.setModificationTimestamp(System.currentTimeMillis());
getStorageManager().saveFile(newDir);
Log_OC.d(TAG, "Create directory " + mRemotePath + " in Database");
}
return newDir;
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class MoveFileOperation method resumeObservation.
private void resumeObservation(String targetPath) {
OCFile updatedFile = new OCFile(targetPath);
updatedFile.setMimetype(mFile.getMimetype());
updatedFile.setFileId(mFile.getFileId());
updatedFile.setStoragePath(FileStorageUtils.getDefaultSavePathFor(getStorageManager().getAccount().name, updatedFile));
FileObserverService.observeFile(MainApp.getAppContext(), updatedFile, getStorageManager().getAccount(), true);
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class FileContentProvider method updateDownloadedFiles.
/**
* Rename the local ownCloud folder of one account to match the a rename of the account itself. Updates the
* table of files in database so that the paths to the local files keep being the same.
*
* @param db Database where table of files is included.
* @param newAccountName New name for the target OC account.
* @param oldAccountName Old name of the target OC account.
*/
private void updateDownloadedFiles(SQLiteDatabase db, String newAccountName, String oldAccountName) {
String whereClause = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL";
Cursor c = db.query(ProviderTableMeta.FILE_TABLE_NAME, null, whereClause, new String[] { newAccountName }, null, null, null);
try {
if (c.moveToFirst()) {
// create storage path
String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName);
String newAccountPath = FileStorageUtils.getSavePath(newAccountName);
// move files
File oldAccountFolder = new File(oldAccountPath);
File newAccountFolder = new File(newAccountPath);
oldAccountFolder.renameTo(newAccountFolder);
// update database
do {
// Update database
String oldPath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
OCFile file = new OCFile(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH)));
String newPath = FileStorageUtils.getDefaultSavePathFor(newAccountName, file);
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, newPath);
db.update(ProviderTableMeta.FILE_TABLE_NAME, cv, ProviderTableMeta.FILE_STORAGE_PATH + "=?", new String[] { oldPath });
Log_OC.v("SQL", "Updated path of downloaded file: old file name == " + oldPath + ", new file name == " + newPath);
} while (c.moveToNext());
}
} finally {
c.close();
}
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class RootCursor method addRoot.
public void addRoot(Account account, Context context) {
final FileDataStorageManager manager = new FileDataStorageManager(account, context.getContentResolver());
final OCFile mainDir = manager.getFileByPath("/");
newRow().add(Root.COLUMN_ROOT_ID, account.name).add(Root.COLUMN_DOCUMENT_ID, mainDir.getFileId()).add(Root.COLUMN_SUMMARY, account.name).add(Root.COLUMN_TITLE, context.getString(R.string.app_name)).add(Root.COLUMN_ICON, R.mipmap.icon).add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_SEARCH);
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class UpdateShareViaLinkOperation method updateData.
private void updateData(OCShare share) {
// Update DB with the response
share.setPath(mPath);
if (mPath.endsWith(FileUtils.PATH_SEPARATOR)) {
share.setIsFolder(true);
} else {
share.setIsFolder(false);
}
// TODO info about having a password? ask to Gonzalo
getStorageManager().saveShare(share);
// Update OCFile with data from share: ShareByLink and publicLink
// TODO check & remove if not needed
OCFile file = getStorageManager().getFileByPath(mPath);
if (file != null) {
file.setPublicLink(share.getShareLink());
file.setShareViaLink(true);
getStorageManager().saveFile(file);
}
}
Aggregations