use of com.owncloud.android.lib.resources.files.ReadFileRemoteOperation in project android by nextcloud.
the class RefreshFolderOperation method checkForChanges.
private RemoteOperationResult checkForChanges(OwnCloudClient client) {
mRemoteFolderChanged = true;
RemoteOperationResult result;
String remotePath = mLocalFolder.getRemotePath();
Log_OC.d(TAG, "Checking changes in " + user.getAccountName() + remotePath);
// remote request
result = new ReadFileRemoteOperation(remotePath).execute(client);
if (result.isSuccess()) {
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
if (!mIgnoreETag) {
// check if remote and local folder are different
String remoteFolderETag = remoteFolder.getEtag();
if (remoteFolderETag != null) {
mRemoteFolderChanged = !(remoteFolderETag.equalsIgnoreCase(mLocalFolder.getEtag()));
} else {
Log_OC.e(TAG, "Checked " + user.getAccountName() + remotePath + ": No ETag received from server");
}
}
result = new RemoteOperationResult(ResultCode.OK);
Log_OC.i(TAG, "Checked " + user.getAccountName() + remotePath + " : " + (mRemoteFolderChanged ? "changed" : "not changed"));
} else {
// check failed
if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
removeLocalFolder();
}
if (result.isException()) {
Log_OC.e(TAG, "Checked " + user.getAccountName() + remotePath + " : " + result.getLogMessage(), result.getException());
} else {
Log_OC.e(TAG, "Checked " + user.getAccountName() + remotePath + " : " + result.getLogMessage());
}
}
return result;
}
use of com.owncloud.android.lib.resources.files.ReadFileRemoteOperation 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.ReadFileRemoteOperation in project android by nextcloud.
the class OCFileListAdapter method parseShares.
private void parseShares(List<Object> objects) {
List<OCShare> shares = new ArrayList<>();
for (Object shareObject : objects) {
// check type before cast as of long running data fetch it is possible that old result is filled
if (shareObject instanceof OCShare) {
OCShare ocShare = (OCShare) shareObject;
shares.add(ocShare);
// get ocFile from Server to have an up-to-date copy
RemoteOperationResult result = new ReadFileRemoteOperation(ocShare.getPath()).execute(user.toPlatformAccount(), activity);
if (result.isSuccess()) {
OCFile file = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
FileStorageUtils.searchForLocalFileInDefaultPath(file, user.getAccountName());
file = mStorageManager.saveFileWithParent(file, activity);
ShareType newShareType = ocShare.getShareType();
if (newShareType == ShareType.PUBLIC_LINK) {
file.setSharedViaLink(true);
} else if (newShareType == ShareType.USER || newShareType == ShareType.GROUP || newShareType == ShareType.EMAIL || newShareType == ShareType.FEDERATED || newShareType == ShareType.ROOM || newShareType == ShareType.CIRCLE) {
file.setSharedWithSharee(true);
}
mStorageManager.saveFile(file);
if (!mFiles.contains(file)) {
mFiles.add(file);
}
} else {
Log_OC.e(TAG, "Error in getting prop for file: " + ocShare.getPath());
}
}
}
mStorageManager.saveShares(shares);
}
use of com.owncloud.android.lib.resources.files.ReadFileRemoteOperation in project android by nextcloud.
the class SynchronizeFolderOperation method checkForChanges.
private RemoteOperationResult checkForChanges(OwnCloudClient client) throws OperationCancelledException {
Log_OC.d(TAG, "Checking changes in " + user.getAccountName() + mRemotePath);
mRemoteFolderChanged = true;
if (mCancellationRequested.get()) {
throw new OperationCancelledException();
}
// remote request
ReadFileRemoteOperation operation = new ReadFileRemoteOperation(mRemotePath);
RemoteOperationResult result = operation.execute(client);
if (result.isSuccess()) {
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
// check if remote and local folder are different
mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag()));
result = new RemoteOperationResult(ResultCode.OK);
Log_OC.i(TAG, "Checked " + user.getAccountName() + mRemotePath + " : " + (mRemoteFolderChanged ? "changed" : "not changed"));
} else {
// check failed
if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
removeLocalFolder();
}
if (result.isException()) {
Log_OC.e(TAG, "Checked " + user.getAccountName() + mRemotePath + " : " + result.getLogMessage(), result.getException());
} else {
Log_OC.e(TAG, "Checked " + user.getAccountName() + mRemotePath + " : " + result.getLogMessage());
}
}
return result;
}
use of com.owncloud.android.lib.resources.files.ReadFileRemoteOperation in project android by nextcloud.
the class ShareActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ShareActivityBinding binding = ShareActivityBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
OCFile file = getFile();
Optional<User> optionalUser = getUser();
if (!optionalUser.isPresent()) {
finish();
return;
}
// Icon
if (file.isFolder()) {
binding.shareFileIcon.setImageDrawable(MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted(), file.getMountType(), this));
} else {
binding.shareFileIcon.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(), optionalUser.get(), this));
if (MimeTypeUtil.isImage(file)) {
String remoteId = String.valueOf(file.getRemoteId());
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(remoteId);
if (thumbnail != null) {
binding.shareFileIcon.setImageBitmap(thumbnail);
}
}
}
// Name
binding.shareFileName.setText(getResources().getString(R.string.share_file, file.getFileName()));
binding.shareHeaderDivider.getBackground().setColorFilter(ThemeColorUtils.primaryAccentColor(this), PorterDuff.Mode.SRC_ATOP);
// Size
binding.shareFileSize.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
Activity activity = this;
new Thread(() -> {
RemoteOperationResult result = new ReadFileRemoteOperation(getFile().getRemotePath()).execute(optionalUser.get().toPlatformAccount(), activity);
if (result.isSuccess()) {
RemoteFile remoteFile = (RemoteFile) result.getData().get(0);
long length = remoteFile.getLength();
getFile().setFileLength(length);
runOnUiThread(() -> binding.shareFileSize.setText(DisplayUtils.bytesToHumanReadable(length)));
}
}).start();
if (savedInstanceState == null) {
// Add Share fragment on first creation
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment fragment = FileDetailSharingFragment.newInstance(getFile(), optionalUser.get());
ft.replace(R.id.share_fragment_container, fragment, TAG_SHARE_FRAGMENT);
ft.commit();
}
}
Aggregations