Search in sources :

Example 6 with ReadFileRemoteOperation

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;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation)

Example 7 with ReadFileRemoteOperation

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 "";
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) SearchRemoteOperation(com.owncloud.android.lib.resources.files.SearchRemoteOperation) SearchRemoteOperation(com.owncloud.android.lib.resources.files.SearchRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile)

Example 8 with ReadFileRemoteOperation

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);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) ArrayList(java.util.ArrayList) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) ShareType(com.owncloud.android.lib.resources.shares.ShareType)

Example 9 with ReadFileRemoteOperation

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;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OperationCancelledException(com.owncloud.android.lib.common.operations.OperationCancelledException) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation)

Example 10 with ReadFileRemoteOperation

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();
    }
}
Also used : User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ShareActivityBinding(com.owncloud.android.databinding.ShareActivityBinding) Activity(android.app.Activity) FileDetailSharingFragment(com.owncloud.android.ui.fragment.FileDetailSharingFragment) Fragment(androidx.fragment.app.Fragment) OCFile(com.owncloud.android.datamodel.OCFile) Bitmap(android.graphics.Bitmap) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile)

Aggregations

ReadFileRemoteOperation (com.owncloud.android.lib.resources.files.ReadFileRemoteOperation)10 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)9 OCFile (com.owncloud.android.datamodel.OCFile)7 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)3 Activity (android.app.Activity)1 OperationApplicationException (android.content.OperationApplicationException)1 Bitmap (android.graphics.Bitmap)1 RemoteException (android.os.RemoteException)1 Fragment (androidx.fragment.app.Fragment)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 User (com.nextcloud.client.account.User)1 ShareActivityBinding (com.owncloud.android.databinding.ShareActivityBinding)1 ThumbnailsCacheManager (com.owncloud.android.datamodel.ThumbnailsCacheManager)1 OCUpload (com.owncloud.android.db.OCUpload)1 OperationCancelledException (com.owncloud.android.lib.common.operations.OperationCancelledException)1 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 SearchRemoteOperation (com.owncloud.android.lib.resources.files.SearchRemoteOperation)1 OCShare (com.owncloud.android.lib.resources.shares.OCShare)1 ShareType (com.owncloud.android.lib.resources.shares.ShareType)1