use of com.owncloud.android.operations.RefreshFolderOperation 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.operations.RefreshFolderOperation in project android by nextcloud.
the class ContactsBackupFragment method refreshBackupFolder.
private void refreshBackupFolder(final String backupFolderPath, final ContactsPreferenceActivity contactsPreferenceActivity) {
AsyncTask<String, Integer, Boolean> task = new AsyncTask<String, Integer, Boolean>() {
@Override
protected Boolean doInBackground(String... path) {
FileDataStorageManager storageManager = new FileDataStorageManager(account, contactsPreferenceActivity.getContentResolver());
OCFile folder = storageManager.getFileByPath(path[0]);
if (folder != null) {
RefreshFolderOperation operation = new RefreshFolderOperation(folder, System.currentTimeMillis(), false, false, false, storageManager, account, getContext());
RemoteOperationResult result = operation.execute(account, getContext());
return result.isSuccess();
} else {
return false;
}
}
@Override
protected void onPostExecute(Boolean result) {
if (result) {
OCFile backupFolder = contactsPreferenceActivity.getStorageManager().getFileByPath(backupFolderPath);
List<OCFile> backupFiles = contactsPreferenceActivity.getStorageManager().getFolderContent(backupFolder, false);
if (backupFiles == null || backupFiles.size() == 0) {
contactsDatePickerBtn.setVisibility(View.GONE);
} else {
contactsDatePickerBtn.setVisibility(View.VISIBLE);
}
}
}
};
task.execute(backupFolderPath);
}
use of com.owncloud.android.operations.RefreshFolderOperation in project android by nextcloud.
the class ActivitiesListActivity method onActivityClicked.
@Override
public void onActivityClicked(RichObject richObject) {
String path = FileUtils.PATH_SEPARATOR + richObject.getPath();
runOnUiThread(new Runnable() {
@Override
public void run() {
swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
swipeListRefreshLayout.setVisibility(View.GONE);
setLoadingMessage();
}
});
updateTask = new AsyncTask<String, Object, OCFile>() {
@Override
protected OCFile doInBackground(String... path) {
OCFile ocFile = null;
// always update file as it could be an old state saved in database
ReadRemoteFileOperation operation = new ReadRemoteFileOperation(path[0]);
RemoteOperationResult resultRemoteFileOp = operation.execute(ownCloudClient);
if (resultRemoteFileOp.isSuccess()) {
OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) resultRemoteFileOp.getData().get(0));
ocFile = getStorageManager().saveFileWithParent(temp, getBaseContext());
if (ocFile.isFolder()) {
// perform folder synchronization
RemoteOperation synchFolderOp = new RefreshFolderOperation(ocFile, System.currentTimeMillis(), false, getFileOperationsHelper().isSharedSupported(), true, getStorageManager(), getAccount(), getApplicationContext());
synchFolderOp.execute(ownCloudClient);
}
}
return ocFile;
}
@Override
protected void onPostExecute(OCFile ocFile) {
if (!isCancelled()) {
if (ocFile == null) {
Toast.makeText(getBaseContext(), R.string.file_not_found, Toast.LENGTH_LONG).show();
swipeEmptyListRefreshLayout.setVisibility(View.GONE);
swipeListRefreshLayout.setVisibility(View.VISIBLE);
dismissLoadingDialog();
} else {
Intent showDetailsIntent;
if (PreviewImageFragment.canBePreviewed(ocFile)) {
showDetailsIntent = new Intent(getBaseContext(), PreviewImageActivity.class);
} else {
showDetailsIntent = new Intent(getBaseContext(), FileDisplayActivity.class);
}
showDetailsIntent.putExtra(EXTRA_FILE, ocFile);
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
startActivity(showDetailsIntent);
}
}
}
};
updateTask.execute(path);
}
use of com.owncloud.android.operations.RefreshFolderOperation in project android by nextcloud.
the class FileDataStorageManagerIT method testFolderContent.
@Test
public void testFolderContent() throws IOException {
assertEquals(0, sut.getAllFiles().size());
assertTrue(new CreateFolderRemoteOperation("/1/1/", true).execute(client).isSuccess());
assertTrue(new CreateFolderRemoteOperation("/1/2/", true).execute(client).isSuccess());
assertTrue(new UploadFileRemoteOperation(getDummyFile("/chunkedFile.txt").getAbsolutePath(), "/1/1/chunkedFile.txt", "text/plain", String.valueOf(System.currentTimeMillis() / 1000)).execute(client).isSuccess());
assertTrue(new UploadFileRemoteOperation(getDummyFile("/chunkedFile.txt").getAbsolutePath(), "/1/1/chunkedFile2.txt", "text/plain", String.valueOf(System.currentTimeMillis() / 1000)).execute(client).isSuccess());
File imageFile = getFile("imageFile.png");
assertTrue(new UploadFileRemoteOperation(imageFile.getAbsolutePath(), "/1/1/imageFile.png", "image/png", String.valueOf(System.currentTimeMillis() / 1000)).execute(client).isSuccess());
// sync
assertNull(sut.getFileByDecryptedRemotePath("/1/1/"));
assertTrue(new RefreshFolderOperation(sut.getFileByDecryptedRemotePath("/"), System.currentTimeMillis() / 1000, false, false, sut, user, targetContext).execute(client).isSuccess());
assertTrue(new RefreshFolderOperation(sut.getFileByDecryptedRemotePath("/1/"), System.currentTimeMillis() / 1000, false, false, sut, user, targetContext).execute(client).isSuccess());
assertTrue(new RefreshFolderOperation(sut.getFileByDecryptedRemotePath("/1/1/"), System.currentTimeMillis() / 1000, false, false, sut, user, targetContext).execute(client).isSuccess());
assertEquals(3, sut.getFolderContent(sut.getFileByDecryptedRemotePath("/1/1/"), false).size());
}
use of com.owncloud.android.operations.RefreshFolderOperation in project android by nextcloud.
the class FileDataStorageManagerIT method testGallerySearch.
/**
* This test creates an image and a video, does a gallery search (now returned image and video is not yet in file
* hierarchy), then root folder is refreshed and it is verified that the same image file is used in database
*/
@Test
public void testGallerySearch() throws IOException {
sut = new FileDataStorageManager(user, targetContext.getContentResolver().acquireContentProviderClient(ProviderMeta.ProviderTableMeta.CONTENT_URI));
String imagePath = "/imageFile.png";
VirtualFolderType virtualType = VirtualFolderType.GALLERY;
assertEquals(0, sut.getFolderContent(sut.getFileByDecryptedRemotePath("/"), false).size());
assertEquals(1, sut.getAllFiles().size());
File imageFile = getFile("imageFile.png");
assertTrue(new UploadFileRemoteOperation(imageFile.getAbsolutePath(), imagePath, "image/png", String.valueOf((System.currentTimeMillis() - 10000) / 1000)).execute(client).isSuccess());
// Check that file does not yet exist in local database
assertNull(sut.getFileByDecryptedRemotePath(imagePath));
String videoPath = "/videoFile.mp4";
File videoFile = getFile("videoFile.mp4");
assertTrue(new UploadFileRemoteOperation(videoFile.getAbsolutePath(), videoPath, "video/mpeg", String.valueOf((System.currentTimeMillis() + 10000) / 1000)).execute(client).isSuccess());
// Check that file does not yet exist in local database
assertNull(sut.getFileByDecryptedRemotePath(videoPath));
// search
SearchRemoteOperation searchRemoteOperation = new SearchRemoteOperation("", GALLERY_SEARCH, false, capability);
RemoteOperationResult<List<RemoteFile>> searchResult = searchRemoteOperation.execute(client);
TestCase.assertTrue(searchResult.isSuccess());
TestCase.assertEquals(2, searchResult.getResultData().size());
// newest file must be video path (as sorted by recently modified)
OCFile ocFile = FileStorageUtils.fillOCFile(searchResult.getResultData().get(0));
sut.saveFile(ocFile);
assertEquals(videoPath, ocFile.getRemotePath());
List<ContentValues> contentValues = new ArrayList<>();
ContentValues cv = new ContentValues();
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, virtualType.toString());
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());
contentValues.add(cv);
// second is image file, as older
OCFile ocFile2 = FileStorageUtils.fillOCFile(searchResult.getResultData().get(1));
sut.saveFile(ocFile2);
assertEquals(imagePath, ocFile2.getRemotePath());
ContentValues cv2 = new ContentValues();
cv2.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, virtualType.toString());
cv2.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile2.getFileId());
contentValues.add(cv2);
sut.saveVirtuals(contentValues);
assertEquals(0, sut.getFolderContent(sut.getFileByDecryptedRemotePath("/"), false).size());
assertEquals(2, sut.getVirtualFolderContent(virtualType, false).size());
assertEquals(3, sut.getAllFiles().size());
// update root
assertTrue(new RefreshFolderOperation(sut.getFileByDecryptedRemotePath("/"), System.currentTimeMillis() / 1000, false, false, sut, user, targetContext).execute(client).isSuccess());
assertEquals(2, sut.getFolderContent(sut.getFileByDecryptedRemotePath("/"), false).size());
assertEquals(2, sut.getVirtualFolderContent(virtualType, false).size());
assertEquals(3, sut.getAllFiles().size());
assertEquals(sut.getVirtualFolderContent(virtualType, false).get(0), sut.getFolderContent(sut.getFileByDecryptedRemotePath("/"), false).get(0));
}
Aggregations