Search in sources :

Example 36 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class DocumentsStorageProvider method copyDocument.

@Override
public String copyDocument(String sourceDocumentId, String targetParentDocumentId) throws FileNotFoundException {
    Log.d(TAG, "copyDocument(), id=" + sourceDocumentId);
    Document document = toDocument(sourceDocumentId);
    FileDataStorageManager storageManager = document.getStorageManager();
    Document targetFolder = toDocument(targetParentDocumentId);
    RemoteOperationResult result = new CopyFileOperation(document.getRemotePath(), targetFolder.getRemotePath(), document.getStorageManager()).execute(document.getClient());
    if (!result.isSuccess()) {
        Log_OC.e(TAG, result.toString());
        throw new FileNotFoundException("Failed to copy document with documentId " + sourceDocumentId + " to " + targetParentDocumentId);
    }
    Context context = getNonNullContext();
    User user = document.getUser();
    RemoteOperationResult updateParent = new RefreshFolderOperation(targetFolder.getFile(), System.currentTimeMillis(), false, false, true, storageManager, user, context).execute(targetFolder.getClient());
    if (!updateParent.isSuccess()) {
        Log_OC.e(TAG, updateParent.toString());
        throw new FileNotFoundException("Failed to copy document with documentId " + sourceDocumentId + " to " + targetParentDocumentId);
    }
    String newPath = targetFolder.getRemotePath() + document.getFile().getFileName();
    if (document.getFile().isFolder()) {
        newPath = newPath + PATH_SEPARATOR;
    }
    Document newFile = new Document(storageManager, newPath);
    context.getContentResolver().notifyChange(toNotifyUri(targetFolder), null, false);
    return newFile.getDocumentId();
}
Also used : Context(android.content.Context) User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) FileNotFoundException(java.io.FileNotFoundException) CopyFileOperation(com.owncloud.android.operations.CopyFileOperation)

Example 37 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class DocumentsStorageProvider method querySearchDocuments.

@Override
public Cursor querySearchDocuments(String rootId, String query, String[] projection) {
    Log.d(TAG, "querySearchDocuments(), rootId=" + rootId);
    FileCursor result = new FileCursor(projection);
    FileDataStorageManager storageManager = getStorageManager(rootId);
    if (storageManager == null) {
        return result;
    }
    for (Document d : findFiles(new Document(storageManager, ROOT_PATH), query)) {
        result.addFile(d);
    }
    return result;
}
Also used : FileCursor(org.nextcloud.providers.cursors.FileCursor) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 38 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class DocumentsStorageProvider method recursiveRevokePermission.

private void recursiveRevokePermission(Document document) {
    FileDataStorageManager storageManager = document.getStorageManager();
    OCFile file = document.getFile();
    if (file.isFolder()) {
        for (OCFile child : storageManager.getFolderContent(file, false)) {
            recursiveRevokePermission(new Document(storageManager, child));
        }
    }
    revokeDocumentPermission(document.getDocumentId());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 39 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class DocumentsStorageProvider method initiateStorageMap.

private void initiateStorageMap() {
    rootIdToStorageManager.clear();
    ContentResolver contentResolver = getContext().getContentResolver();
    for (User user : accountManager.getAllUsers()) {
        final FileDataStorageManager storageManager = new FileDataStorageManager(user, contentResolver);
        rootIdToStorageManager.put(rootIdForUser(user), storageManager);
    }
}
Also used : User(com.nextcloud.client.account.User) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) ContentResolver(android.content.ContentResolver)

Example 40 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class DocumentsStorageProvider method findFiles.

private List<Document> findFiles(Document root, String query) {
    FileDataStorageManager storageManager = root.getStorageManager();
    List<Document> result = new ArrayList<>();
    for (OCFile f : storageManager.getFolderContent(root.getFile(), false)) {
        if (f.isFolder()) {
            result.addAll(findFiles(new Document(storageManager, f), query));
        } else if (f.getFileName().contains(query)) {
            result.add(new Document(storageManager, f));
        }
    }
    return result;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) ArrayList(java.util.ArrayList)

Aggregations

FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)91 OCFile (com.owncloud.android.datamodel.OCFile)43 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)21 Account (android.accounts.Account)19 User (com.nextcloud.client.account.User)16 Intent (android.content.Intent)12 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)12 Context (android.content.Context)9 File (java.io.File)9 ArrayList (java.util.ArrayList)9 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)8 Test (org.junit.Test)8 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)7 OCUpload (com.owncloud.android.db.OCUpload)6 AccountManager (android.accounts.AccountManager)5 OperationCancelledException (com.owncloud.android.lib.common.operations.OperationCancelledException)5 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)5 DialogFragment (androidx.fragment.app.DialogFragment)4 IOException (java.io.IOException)4 AccountsException (android.accounts.AccountsException)3