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();
}
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;
}
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());
}
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);
}
}
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;
}
Aggregations