Search in sources :

Example 26 with OCFile

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;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile)

Example 27 with OCFile

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);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile)

Example 28 with OCFile

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();
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) ContentValues(android.content.ContentValues) Cursor(android.database.Cursor) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File)

Example 29 with OCFile

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);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 30 with OCFile

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);
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile)

Aggregations

OCFile (com.owncloud.android.datamodel.OCFile)84 File (java.io.File)14 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)9 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)8 Intent (android.content.Intent)7 Account (android.accounts.Account)6 OCFileListFragment (com.owncloud.android.ui.fragment.OCFileListFragment)6 FileFragment (com.owncloud.android.ui.fragment.FileFragment)5 Vector (java.util.Vector)5 Bundle (android.os.Bundle)4 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)4 RemoteFile (com.owncloud.android.lib.resources.files.RemoteFile)4 SuppressLint (android.annotation.SuppressLint)3 Bitmap (android.graphics.Bitmap)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 ThumbnailsCacheManager (com.owncloud.android.datamodel.ThumbnailsCacheManager)3 TransferProgressController (com.owncloud.android.ui.controller.TransferProgressController)3 SharedPreferences (android.content.SharedPreferences)2