use of com.owncloud.android.lib.resources.files.model.RemoteFile 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));
}
use of com.owncloud.android.lib.resources.files.model.RemoteFile in project android by nextcloud.
the class AbstractOnServerIT method deleteAllFiles.
public static void deleteAllFiles() {
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
assertTrue(result.getLogMessage(), result.isSuccess());
for (Object object : result.getData()) {
RemoteFile remoteFile = (RemoteFile) object;
if (!remoteFile.getRemotePath().equals("/")) {
if (remoteFile.isEncrypted()) {
assertTrue(new ToggleEncryptionRemoteOperation(remoteFile.getLocalId(), remoteFile.getRemotePath(), false).execute(client).isSuccess());
}
assertTrue(new RemoveFileRemoteOperation(remoteFile.getRemotePath()).execute(client).isSuccess());
}
}
}
use of com.owncloud.android.lib.resources.files.model.RemoteFile in project android by nextcloud.
the class FetchRemoteFileTask method doInBackground.
@Override
protected String doInBackground(Void... voids) {
SearchRemoteOperation searchRemoteOperation = new SearchRemoteOperation(fileId, FILE_ID_SEARCH, false, fileDisplayActivity.getCapabilities());
RemoteOperationResult remoteOperationResult = searchRemoteOperation.execute(user.toPlatformAccount(), fileDisplayActivity);
if (remoteOperationResult.isSuccess() && remoteOperationResult.getData() != null) {
if (remoteOperationResult.getData().isEmpty()) {
return fileDisplayActivity.getString(R.string.remote_file_fetch_failed);
}
String remotePath = ((RemoteFile) remoteOperationResult.getData().get(0)).getRemotePath();
ReadFileRemoteOperation operation = new ReadFileRemoteOperation(remotePath);
RemoteOperationResult result = operation.execute(user.toPlatformAccount(), fileDisplayActivity);
if (!result.isSuccess()) {
Exception exception = result.getException();
String message = "Fetching file " + remotePath + " fails with: " + result.getLogMessage();
if (exception != null) {
return exception.getMessage();
} else {
return message;
}
}
RemoteFile remoteFile = (RemoteFile) result.getData().get(0);
OCFile ocFile = FileStorageUtils.fillOCFile(remoteFile);
FileStorageUtils.searchForLocalFileInDefaultPath(ocFile, user.getAccountName());
ocFile = storageManager.saveFileWithParent(ocFile, fileDisplayActivity);
// also sync folder content
OCFile toSync;
if (ocFile.isFolder()) {
toSync = ocFile;
} else {
toSync = storageManager.getFileById(ocFile.getParentId());
}
long currentSyncTime = System.currentTimeMillis();
RemoteOperation refreshFolderOperation = new RefreshFolderOperation(toSync, currentSyncTime, true, true, storageManager, user, fileDisplayActivity);
refreshFolderOperation.execute(user.toPlatformAccount(), fileDisplayActivity);
fileDisplayActivity.setFile(ocFile);
} else {
return remoteOperationResult.getLogMessage();
}
return "";
}
use of com.owncloud.android.lib.resources.files.model.RemoteFile in project android by nextcloud.
the class GallerySearchTask method findLastTimestamp.
private long findLastTimestamp(ArrayList<RemoteFile> remoteFiles) {
int lastPosition = remoteFiles.size() - 1;
if (lastPosition < 0) {
return -1;
}
RemoteFile lastFile = remoteFiles.get(lastPosition);
return lastFile.getModifiedTimestamp() / 1000;
}
use of com.owncloud.android.lib.resources.files.model.RemoteFile in project android by nextcloud.
the class OCFileListAdapter method parseVirtuals.
private void parseVirtuals(List<Object> objects, SearchType searchType) {
VirtualFolderType type;
boolean onlyMedia = false;
switch(searchType) {
case FAVORITE_SEARCH:
type = VirtualFolderType.FAVORITE;
break;
case GALLERY_SEARCH:
type = VirtualFolderType.GALLERY;
onlyMedia = true;
int lastPosition = objects.size() - 1;
if (lastPosition < 0) {
lastTimestamp = -1;
break;
}
RemoteFile lastFile = (RemoteFile) objects.get(lastPosition);
lastTimestamp = lastFile.getModifiedTimestamp() / 1000;
break;
default:
type = VirtualFolderType.NONE;
break;
}
List<ContentValues> contentValues = new ArrayList<>();
for (Object remoteFile : objects) {
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) remoteFile);
FileStorageUtils.searchForLocalFileInDefaultPath(ocFile, user.getAccountName());
try {
ocFile = mStorageManager.saveFileWithParent(ocFile, activity);
if (SearchType.GALLERY_SEARCH != searchType) {
// also sync folder content
if (ocFile.isFolder()) {
long currentSyncTime = System.currentTimeMillis();
RemoteOperation refreshFolderOperation = new RefreshFolderOperation(ocFile, currentSyncTime, true, false, mStorageManager, user, activity);
refreshFolderOperation.execute(user.toPlatformAccount(), activity);
}
}
if (!onlyMedia || MimeTypeUtil.isImage(ocFile) || MimeTypeUtil.isVideo(ocFile)) {
mFiles.add(ocFile);
}
ContentValues cv = new ContentValues();
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, type.toString());
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());
contentValues.add(cv);
} catch (RemoteOperationFailedException e) {
Log_OC.e(TAG, "Error saving file with parent" + e.getMessage(), e);
}
}
preferences.setPhotoSearchTimestamp(System.currentTimeMillis());
mStorageManager.saveVirtuals(contentValues);
}
Aggregations