Search in sources :

Example 76 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class BackupFragment method openDate.

public void openDate(@Nullable Date savedDate) {
    final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();
    if (contactsPreferenceActivity == null) {
        Toast.makeText(getContext(), getString(R.string.error_choosing_date), Toast.LENGTH_LONG).show();
        return;
    }
    String contactsBackupFolderString = getResources().getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR;
    String calendarBackupFolderString = getResources().getString(R.string.calendar_backup_folder) + OCFile.PATH_SEPARATOR;
    FileDataStorageManager storageManager = contactsPreferenceActivity.getStorageManager();
    OCFile contactsBackupFolder = storageManager.getFileByDecryptedRemotePath(contactsBackupFolderString);
    OCFile calendarBackupFolder = storageManager.getFileByDecryptedRemotePath(calendarBackupFolderString);
    List<OCFile> backupFiles = storageManager.getFolderContent(contactsBackupFolder, false);
    backupFiles.addAll(storageManager.getFolderContent(calendarBackupFolder, false));
    Collections.sort(backupFiles, (o1, o2) -> {
        return Long.compare(o1.getModificationTimestamp(), o2.getModificationTimestamp());
    });
    Calendar cal = Calendar.getInstance();
    int year;
    int month;
    int day;
    if (savedDate == null) {
        year = cal.get(Calendar.YEAR);
        month = cal.get(Calendar.MONTH) + 1;
        day = cal.get(Calendar.DAY_OF_MONTH);
    } else {
        year = savedDate.getYear();
        month = savedDate.getMonth();
        day = savedDate.getDay();
    }
    if (backupFiles.size() > 0 && backupFiles.get(backupFiles.size() - 1) != null) {
        datePickerDialog = new DatePickerDialog(contactsPreferenceActivity, this, year, month, day);
        datePickerDialog.getDatePicker().setMaxDate(backupFiles.get(backupFiles.size() - 1).getModificationTimestamp());
        datePickerDialog.getDatePicker().setMinDate(backupFiles.get(0).getModificationTimestamp());
        datePickerDialog.setOnDismissListener(dialog -> selectedDate = null);
        datePickerDialog.setTitle("");
        datePickerDialog.show();
        datePickerDialog.getButton(DatePickerDialog.BUTTON_NEGATIVE).setTextColor(themeColorUtils.primaryColor(getContext(), true));
        datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTextColor(themeColorUtils.primaryColor(getContext(), true));
        // set background to transparent
        datePickerDialog.getButton(DatePickerDialog.BUTTON_NEGATIVE).setBackgroundColor(0x00000000);
        datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setBackgroundColor(0x00000000);
    } else {
        DisplayUtils.showSnackMessage(getView().findViewById(R.id.contacts_linear_layout), R.string.contacts_preferences_something_strange_happened);
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) ContactsPreferenceActivity(com.owncloud.android.ui.activity.ContactsPreferenceActivity) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 77 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class FileOperationsHelper method openFile.

public void openFile(OCFile file) {
    if (file != null) {
        final Intent openFileWithIntent = createOpenFileIntent(file);
        List<ResolveInfo> launchables = fileActivity.getPackageManager().queryIntentActivities(openFileWithIntent, PackageManager.GET_RESOLVED_FILTER);
        if (launchables.isEmpty()) {
            Optional<User> optionalUser = fileActivity.getUser();
            if (optionalUser.isPresent() && EditorUtils.isEditorAvailable(fileActivity.getContentResolver(), optionalUser.get(), file.getMimeType())) {
                openFileWithTextEditor(file, fileActivity);
            } else {
                Account account = fileActivity.getAccount();
                OCCapability capability = fileActivity.getStorageManager().getCapability(account.name);
                if (capability.getRichDocumentsMimeTypeList().contains(file.getMimeType()) && capability.getRichDocumentsDirectEditing().isTrue()) {
                    openFileAsRichDocument(file, fileActivity);
                    return;
                } else {
                    DisplayUtils.showSnackMessage(fileActivity, R.string.file_list_no_app_for_file_type);
                    return;
                }
            }
        }
        fileActivity.showLoadingDialog(fileActivity.getResources().getString(R.string.sync_in_progress));
        new Thread(new Runnable() {

            @Override
            public void run() {
                User user = currentAccount.getUser();
                FileDataStorageManager storageManager = new FileDataStorageManager(user, fileActivity.getContentResolver());
                // a fresh object is needed; many things could have occurred to the file
                // since it was registered to observe again, assuming that local files
                // are linked to a remote file AT MOST, SOMETHING TO BE DONE;
                SynchronizeFileOperation sfo = new SynchronizeFileOperation(file, null, user, true, fileActivity, storageManager);
                RemoteOperationResult result = sfo.execute(fileActivity);
                fileActivity.dismissLoadingDialog();
                if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
                    // ISSUE 5: if the user is not running the app (this is a service!),
                    // this can be very intrusive; a notification should be preferred
                    Intent intent = ConflictsResolveActivity.createIntent(file, user, -1, Intent.FLAG_ACTIVITY_NEW_TASK, fileActivity);
                    fileActivity.startActivity(intent);
                } else {
                    if (!launchables.isEmpty()) {
                        try {
                            if (!result.isSuccess()) {
                                DisplayUtils.showSnackMessage(fileActivity, R.string.file_not_synced);
                                try {
                                    Thread.sleep(3000);
                                } catch (InterruptedException e) {
                                    Log.e(TAG, "Failed to sleep");
                                }
                            }
                            openFileWithIntent.setFlags(openFileWithIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                            fileActivity.startActivity(openFileWithIntent);
                        } catch (ActivityNotFoundException exception) {
                            DisplayUtils.showSnackMessage(fileActivity, R.string.file_list_no_app_for_file_type);
                        }
                    } else {
                        DisplayUtils.showSnackMessage(fileActivity, R.string.file_list_no_app_for_file_type);
                    }
                }
            }
        }).start();
    } else {
        Log_OC.e(TAG, "Trying to open a NULL OCFile");
    }
}
Also used : Account(android.accounts.Account) User(com.nextcloud.client.account.User) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) ActivityNotFoundException(android.content.ActivityNotFoundException) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) SynchronizeFileOperation(com.owncloud.android.operations.SynchronizeFileOperation)

Example 78 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class ErrorsWhileCopyingHandlerActivity method onCreate.

/**
 * {@link}
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // / read extra parameters in intent
    Intent intent = getIntent();
    user = intent.getParcelableExtra(EXTRA_USER);
    mRemotePaths = intent.getStringArrayListExtra(EXTRA_REMOTE_PATHS);
    mLocalPaths = intent.getStringArrayListExtra(EXTRA_LOCAL_PATHS);
    mStorageManager = new FileDataStorageManager(user, getContentResolver());
    mHandler = new Handler();
    if (mCurrentDialog != null) {
        mCurrentDialog.dismiss();
        mCurrentDialog = null;
    }
    // / load generic layout
    setContentView(R.layout.generic_explanation);
    // / customize text message
    TextView textView = findViewById(R.id.message);
    String appName = getString(R.string.app_name);
    String message = String.format(getString(R.string.sync_foreign_files_forgotten_explanation), appName, appName, appName, appName, user.getAccountName());
    textView.setText(message);
    textView.setMovementMethod(new ScrollingMovementMethod());
    // / load the list of local and remote files that failed
    ListView listView = findViewById(R.id.list);
    if (mLocalPaths != null && mLocalPaths.size() > 0) {
        mAdapter = new ErrorsWhileCopyingListAdapter();
        listView.setAdapter(mAdapter);
    } else {
        listView.setVisibility(View.GONE);
        mAdapter = null;
    }
    // / customize buttons
    Button cancelBtn = findViewById(R.id.cancel);
    Button okBtn = findViewById(R.id.ok);
    okBtn.setText(R.string.foreign_files_move);
    cancelBtn.setOnClickListener(this);
    okBtn.setOnClickListener(this);
}
Also used : ListView(android.widget.ListView) Button(android.widget.Button) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Handler(android.os.Handler) Intent(android.content.Intent) TextView(android.widget.TextView) ScrollingMovementMethod(android.text.method.ScrollingMovementMethod)

Example 79 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class UsersAndGroupsSearchProvider method searchForUsersOrGroups.

private Cursor searchForUsersOrGroups(Uri uri) {
    String lastPathSegment = uri.getLastPathSegment();
    if (lastPathSegment == null) {
        throw new IllegalArgumentException("Wrong URI passed!");
    }
    // need to trust on the AccountUtils to get the current account since the query in the client side is not
    // directly started by our code, but from SearchView implementation
    User user = accountManager.getUser();
    String userQuery = lastPathSegment.toLowerCase(Locale.ROOT);
    // request to the OC server about users and groups matching userQuery
    GetShareesRemoteOperation searchRequest = new GetShareesRemoteOperation(userQuery, REQUESTED_PAGE, RESULTS_PER_PAGE);
    RemoteOperationResult result = searchRequest.execute(user.toPlatformAccount(), getContext());
    List<JSONObject> names = new ArrayList<>();
    if (result.isSuccess()) {
        for (Object o : result.getData()) {
            names.add((JSONObject) o);
        }
    } else {
        showErrorMessage(result);
    }
    MatrixCursor response = null;
    // convert the responses from the OC server to the expected format
    if (names.size() > 0) {
        if (getContext() == null) {
            throw new IllegalArgumentException("Context may not be null!");
        }
        response = new MatrixCursor(COLUMNS);
        Uri userBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_USER).build();
        Uri groupBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_GROUP).build();
        Uri roomBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_ROOM).build();
        Uri remoteBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_REMOTE).build();
        Uri emailBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_EMAIL).build();
        Uri circleBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_CIRCLE).build();
        FileDataStorageManager manager = new FileDataStorageManager(user, getContext().getContentResolver());
        boolean federatedShareAllowed = manager.getCapability(user.getAccountName()).getFilesSharingFederationOutgoing().isTrue();
        try {
            Iterator<JSONObject> namesIt = names.iterator();
            JSONObject item;
            String displayName;
            String subline = null;
            Object icon = 0;
            Uri dataUri;
            int count = 0;
            while (namesIt.hasNext()) {
                item = namesIt.next();
                dataUri = null;
                displayName = null;
                String userName = item.getString(GetShareesRemoteOperation.PROPERTY_LABEL);
                String name = item.isNull("name") ? "" : item.getString("name");
                JSONObject value = item.getJSONObject(GetShareesRemoteOperation.NODE_VALUE);
                ShareType type = ShareType.fromValue(value.getInt(GetShareesRemoteOperation.PROPERTY_SHARE_TYPE));
                String shareWith = value.getString(GetShareesRemoteOperation.PROPERTY_SHARE_WITH);
                Status status;
                JSONObject statusObject = item.optJSONObject(PROPERTY_STATUS);
                if (statusObject != null) {
                    status = new Status(StatusType.valueOf(statusObject.getString(PROPERTY_STATUS).toUpperCase(Locale.US)), statusObject.isNull(PROPERTY_MESSAGE) ? "" : statusObject.getString(PROPERTY_MESSAGE), statusObject.isNull(PROPERTY_ICON) ? "" : statusObject.getString(PROPERTY_ICON), statusObject.isNull(PROPERTY_CLEAR_AT) ? -1 : statusObject.getLong(PROPERTY_CLEAR_AT));
                } else {
                    status = new Status(StatusType.OFFLINE, "", "", -1);
                }
                switch(type) {
                    case GROUP:
                        displayName = userName;
                        icon = R.drawable.ic_group;
                        dataUri = Uri.withAppendedPath(groupBaseUri, shareWith);
                        break;
                    case FEDERATED:
                        if (federatedShareAllowed) {
                            icon = R.drawable.ic_user;
                            dataUri = Uri.withAppendedPath(remoteBaseUri, shareWith);
                            if (userName.equals(shareWith)) {
                                displayName = name;
                                subline = getContext().getString(R.string.remote);
                            } else {
                                String[] uriSplitted = shareWith.split("@");
                                displayName = name;
                                subline = getContext().getString(R.string.share_known_remote_on_clarification, uriSplitted[uriSplitted.length - 1]);
                            }
                        }
                        break;
                    case USER:
                        displayName = userName;
                        subline = (status.getMessage() == null || status.getMessage().isEmpty()) ? null : status.getMessage();
                        Uri.Builder builder = Uri.parse("content://com.nextcloud.android.providers.UsersAndGroupsSearchProvider/icon").buildUpon();
                        builder.appendQueryParameter("shareWith", shareWith);
                        builder.appendQueryParameter("displayName", displayName);
                        builder.appendQueryParameter("status", status.getStatus().toString());
                        if (!TextUtils.isEmpty(status.getIcon()) && !"null".equals(status.getIcon())) {
                            builder.appendQueryParameter("icon", status.getIcon());
                        }
                        icon = builder.build();
                        dataUri = Uri.withAppendedPath(userBaseUri, shareWith);
                        break;
                    case EMAIL:
                        icon = R.drawable.ic_email;
                        displayName = name;
                        subline = shareWith;
                        dataUri = Uri.withAppendedPath(emailBaseUri, shareWith);
                        break;
                    case ROOM:
                        icon = R.drawable.ic_talk;
                        displayName = userName;
                        dataUri = Uri.withAppendedPath(roomBaseUri, shareWith);
                        break;
                    case CIRCLE:
                        icon = R.drawable.ic_circles;
                        displayName = userName;
                        dataUri = Uri.withAppendedPath(circleBaseUri, shareWith);
                        break;
                    default:
                        break;
                }
                if (displayName != null && dataUri != null) {
                    response.newRow().add(// BaseColumns._ID
                    count++).add(// SearchManager.SUGGEST_COLUMN_TEXT_1
                    displayName).add(// SearchManager.SUGGEST_COLUMN_TEXT_2
                    subline).add(// SearchManager.SUGGEST_COLUMN_ICON_1
                    icon).add(dataUri);
                }
            }
        } catch (JSONException e) {
            Log_OC.e(TAG, "Exception while parsing data of users/groups", e);
        }
    }
    return response;
}
Also used : Status(com.owncloud.android.lib.resources.users.Status) User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) GetShareesRemoteOperation(com.owncloud.android.lib.resources.shares.GetShareesRemoteOperation) Uri(android.net.Uri) MatrixCursor(android.database.MatrixCursor) JSONObject(org.json.JSONObject) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) JSONObject(org.json.JSONObject) ShareType(com.owncloud.android.lib.resources.shares.ShareType)

Example 80 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class OperationsService method newOperation.

/**
 * Creates a new operation, as described by operationIntent.
 * <p>
 * TODO - move to ServiceHandler (probably)
 *
 * @param operationIntent Intent describing a new operation to queue and execute.
 * @return Pair with the new operation object and the information about its target server.
 */
private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
    RemoteOperation operation = null;
    Target target = null;
    try {
        if (!operationIntent.hasExtra(EXTRA_ACCOUNT) && !operationIntent.hasExtra(EXTRA_SERVER_URL)) {
            Log_OC.e(TAG, "Not enough information provided in intent");
        } else {
            Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT);
            User user = toUser(account);
            String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL);
            target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl));
            String action = operationIntent.getAction();
            String remotePath;
            String password;
            ShareType shareType;
            String newParentPath;
            long shareId;
            FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user, getContentResolver());
            switch(action) {
                case ACTION_CREATE_SHARE_VIA_LINK:
                    remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                    password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
                    if (!TextUtils.isEmpty(remotePath)) {
                        operation = new CreateShareViaLinkOperation(remotePath, password, fileDataStorageManager);
                    }
                    break;
                case ACTION_UPDATE_PUBLIC_SHARE:
                    shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
                    if (shareId > 0) {
                        UpdateShareViaLinkOperation updateLinkOperation = new UpdateShareViaLinkOperation(shareId, fileDataStorageManager);
                        password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
                        updateLinkOperation.setPassword(password);
                        long expirationDate = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0);
                        updateLinkOperation.setExpirationDateInMillis(expirationDate);
                        boolean hideFileDownload = operationIntent.getBooleanExtra(EXTRA_SHARE_HIDE_FILE_DOWNLOAD, false);
                        updateLinkOperation.setHideFileDownload(hideFileDownload);
                        if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) {
                            updateLinkOperation.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL));
                        }
                        operation = updateLinkOperation;
                    }
                    break;
                case ACTION_UPDATE_USER_SHARE:
                    shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
                    if (shareId > 0) {
                        UpdateSharePermissionsOperation updateShare = new UpdateSharePermissionsOperation(shareId, fileDataStorageManager);
                        int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
                        updateShare.setPermissions(permissions);
                        long expirationDateInMillis = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0L);
                        updateShare.setExpirationDateInMillis(expirationDateInMillis);
                        password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
                        updateShare.setPassword(password);
                        operation = updateShare;
                    }
                    break;
                case ACTION_UPDATE_SHARE_NOTE:
                    shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
                    String note = operationIntent.getStringExtra(EXTRA_SHARE_NOTE);
                    if (shareId > 0) {
                        operation = new UpdateNoteForShareOperation(shareId, note, fileDataStorageManager);
                    }
                    break;
                case ACTION_CREATE_SHARE_WITH_SHAREE:
                    remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                    String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
                    shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
                    int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
                    String noteMessage = operationIntent.getStringExtra(EXTRA_SHARE_NOTE);
                    String sharePassword = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
                    long expirationDateInMillis = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0L);
                    boolean hideFileDownload = operationIntent.getBooleanExtra(EXTRA_SHARE_HIDE_FILE_DOWNLOAD, false);
                    if (!TextUtils.isEmpty(remotePath)) {
                        CreateShareWithShareeOperation createShareWithShareeOperation = new CreateShareWithShareeOperation(remotePath, shareeName, shareType, permissions, noteMessage, sharePassword, expirationDateInMillis, hideFileDownload, fileDataStorageManager);
                        if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) {
                            createShareWithShareeOperation.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL));
                        }
                        operation = createShareWithShareeOperation;
                    }
                    break;
                case ACTION_UPDATE_SHARE_INFO:
                    shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
                    if (shareId > 0) {
                        UpdateShareInfoOperation updateShare = new UpdateShareInfoOperation(shareId, fileDataStorageManager);
                        int permissionsToChange = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
                        updateShare.setPermissions(permissionsToChange);
                        long expirationDateInMills = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0L);
                        updateShare.setExpirationDateInMillis(expirationDateInMills);
                        password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
                        updateShare.setPassword(password);
                        boolean fileDownloadHide = operationIntent.getBooleanExtra(EXTRA_SHARE_HIDE_FILE_DOWNLOAD, false);
                        updateShare.setHideFileDownload(fileDownloadHide);
                        if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) {
                            updateShare.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL));
                        }
                        operation = updateShare;
                    }
                    break;
                case ACTION_UNSHARE:
                    remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                    shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
                    if (shareId > 0) {
                        operation = new UnshareOperation(remotePath, shareId, fileDataStorageManager);
                    }
                    break;
                case ACTION_GET_SERVER_INFO:
                    operation = new GetServerInfoOperation(serverUrl, this);
                    break;
                case ACTION_GET_USER_NAME:
                    operation = new GetUserInfoRemoteOperation();
                    break;
                case ACTION_RENAME:
                    remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                    String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
                    operation = new RenameFileOperation(remotePath, newName, fileDataStorageManager);
                    break;
                case ACTION_REMOVE:
                    // Remove file or folder
                    OCFile file = operationIntent.getParcelableExtra(EXTRA_FILE);
                    boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
                    boolean inBackground = operationIntent.getBooleanExtra(EXTRA_IN_BACKGROUND, false);
                    operation = new RemoveFileOperation(file, onlyLocalCopy, account, inBackground, getApplicationContext(), fileDataStorageManager);
                    break;
                case ACTION_CREATE_FOLDER:
                    remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                    operation = new CreateFolderOperation(remotePath, user, getApplicationContext(), fileDataStorageManager);
                    break;
                case ACTION_SYNC_FILE:
                    remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                    boolean syncFileContents = operationIntent.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS, true);
                    operation = new SynchronizeFileOperation(remotePath, user, syncFileContents, getApplicationContext(), fileDataStorageManager);
                    break;
                case ACTION_SYNC_FOLDER:
                    remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                    operation = new SynchronizeFolderOperation(// TODO remove this dependency from construction time
                    this, remotePath, user, // TODO remove this dependency from construction time
                    System.currentTimeMillis(), fileDataStorageManager);
                    break;
                case ACTION_MOVE_FILE:
                    remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                    newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
                    operation = new MoveFileOperation(remotePath, newParentPath, fileDataStorageManager);
                    break;
                case ACTION_COPY_FILE:
                    remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                    newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
                    operation = new CopyFileOperation(remotePath, newParentPath, fileDataStorageManager);
                    break;
                case ACTION_CHECK_CURRENT_CREDENTIALS:
                    operation = new CheckCurrentCredentialsOperation(user, fileDataStorageManager);
                    break;
                case ACTION_RESTORE_VERSION:
                    FileVersion fileVersion = operationIntent.getParcelableExtra(EXTRA_FILE_VERSION);
                    operation = new RestoreFileVersionRemoteOperation(fileVersion.getRemoteId(), fileVersion.getFileName());
                    break;
                default:
                    // do nothing
                    break;
            }
        }
    } catch (IllegalArgumentException e) {
        Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
        operation = null;
    }
    if (operation != null) {
        return new Pair<>(target, operation);
    } else {
        return null;
    }
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) UnshareOperation(com.owncloud.android.operations.UnshareOperation) User(com.nextcloud.client.account.User) UpdateNoteForShareOperation(com.owncloud.android.operations.UpdateNoteForShareOperation) RemoveFileOperation(com.owncloud.android.operations.RemoveFileOperation) RenameFileOperation(com.owncloud.android.operations.RenameFileOperation) CopyFileOperation(com.owncloud.android.operations.CopyFileOperation) OCFile(com.owncloud.android.datamodel.OCFile) SynchronizeFolderOperation(com.owncloud.android.operations.SynchronizeFolderOperation) UpdateShareViaLinkOperation(com.owncloud.android.operations.UpdateShareViaLinkOperation) FileVersion(com.owncloud.android.lib.resources.files.model.FileVersion) RestoreFileVersionRemoteOperation(com.owncloud.android.lib.resources.files.RestoreFileVersionRemoteOperation) Pair(android.util.Pair) GetUserInfoRemoteOperation(com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation) RestoreFileVersionRemoteOperation(com.owncloud.android.lib.resources.files.RestoreFileVersionRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) GetUserInfoRemoteOperation(com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation) CreateShareWithShareeOperation(com.owncloud.android.operations.CreateShareWithShareeOperation) CheckCurrentCredentialsOperation(com.owncloud.android.operations.CheckCurrentCredentialsOperation) CreateShareViaLinkOperation(com.owncloud.android.operations.CreateShareViaLinkOperation) CreateFolderOperation(com.owncloud.android.operations.CreateFolderOperation) UpdateShareInfoOperation(com.owncloud.android.operations.UpdateShareInfoOperation) MoveFileOperation(com.owncloud.android.operations.MoveFileOperation) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) GetServerInfoOperation(com.owncloud.android.operations.GetServerInfoOperation) UpdateSharePermissionsOperation(com.owncloud.android.operations.UpdateSharePermissionsOperation) ShareType(com.owncloud.android.lib.resources.shares.ShareType) SynchronizeFileOperation(com.owncloud.android.operations.SynchronizeFileOperation)

Aggregations

FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)91 OCFile (com.owncloud.android.datamodel.OCFile)43 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)21 Account (android.accounts.Account)19 User (com.nextcloud.client.account.User)16 Intent (android.content.Intent)12 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)12 Context (android.content.Context)9 File (java.io.File)9 ArrayList (java.util.ArrayList)9 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)8 Test (org.junit.Test)8 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)7 OCUpload (com.owncloud.android.db.OCUpload)6 AccountManager (android.accounts.AccountManager)5 OperationCancelledException (com.owncloud.android.lib.common.operations.OperationCancelledException)5 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)5 DialogFragment (androidx.fragment.app.DialogFragment)4 IOException (java.io.IOException)4 AccountsException (android.accounts.AccountsException)3