Search in sources :

Example 1 with RenameFileDialogFragment

use of com.owncloud.android.ui.dialog.RenameFileDialogFragment in project android by nextcloud.

the class OCFileListFragment method onFileActionChosen.

/**
 * Start the appropriate action(s) on the currently selected files given menu selected by the user.
 *
 * @param item       MenuItem selected by the user
 * @param checkedFiles List of files selected by the user on which the action should be performed
 * @return 'true' if the menu selection started any action, 'false' otherwise.
 */
public boolean onFileActionChosen(MenuItem item, Set<OCFile> checkedFiles) {
    if (checkedFiles.isEmpty()) {
        return false;
    }
    if (checkedFiles.size() == SINGLE_SELECTION) {
        // / action only possible on a single file
        OCFile singleFile = checkedFiles.iterator().next();
        int itemId = item.getItemId();
        if (itemId == R.id.action_send_share_file) {
            mContainerActivity.getFileOperationsHelper().sendShareFile(singleFile);
            return true;
        } else if (itemId == R.id.action_open_file_with) {
            mContainerActivity.getFileOperationsHelper().openFile(singleFile);
            return true;
        } else if (itemId == R.id.action_stream_media) {
            mContainerActivity.getFileOperationsHelper().streamMediaFile(singleFile);
            return true;
        } else if (itemId == R.id.action_edit) {
            // should not be necessary, as menu item is filtered, but better play safe
            if (FileMenuFilter.isEditorAvailable(requireContext().getContentResolver(), accountManager.getUser(), singleFile.getMimeType())) {
                mContainerActivity.getFileOperationsHelper().openFileWithTextEditor(singleFile, getContext());
            } else {
                mContainerActivity.getFileOperationsHelper().openFileAsRichDocument(singleFile, getContext());
            }
            return true;
        } else if (itemId == R.id.action_rename_file) {
            RenameFileDialogFragment dialog = RenameFileDialogFragment.newInstance(singleFile);
            dialog.show(getFragmentManager(), FileDetailFragment.FTAG_RENAME_FILE);
            return true;
        } else if (itemId == R.id.action_see_details) {
            if (mActiveActionMode != null) {
                mActiveActionMode.finish();
            }
            mContainerActivity.showDetails(singleFile);
            mContainerActivity.showSortListGroup(false);
            return true;
        } else if (itemId == R.id.action_set_as_wallpaper) {
            mContainerActivity.getFileOperationsHelper().setPictureAs(singleFile, getView());
            return true;
        } else if (itemId == R.id.action_encrypted) {
            mContainerActivity.getFileOperationsHelper().toggleEncryption(singleFile, true);
            return true;
        } else if (itemId == R.id.action_unset_encrypted) {
            mContainerActivity.getFileOperationsHelper().toggleEncryption(singleFile, false);
            return true;
        }
    }
    // / actions possible on a batch of files
    int itemId = item.getItemId();
    if (itemId == R.id.action_remove_file) {
        RemoveFilesDialogFragment dialog = RemoveFilesDialogFragment.newInstance(new ArrayList<>(checkedFiles), mActiveActionMode);
        dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION);
        return true;
    } else if (itemId == R.id.action_download_file || itemId == R.id.action_sync_file) {
        syncAndCheckFiles(checkedFiles);
        exitSelectionMode();
        return true;
    } else if (itemId == R.id.action_cancel_sync) {
        ((FileDisplayActivity) mContainerActivity).cancelTransference(checkedFiles);
        return true;
    } else if (itemId == R.id.action_favorite) {
        mContainerActivity.getFileOperationsHelper().toggleFavoriteFiles(checkedFiles, true);
        return true;
    } else if (itemId == R.id.action_unset_favorite) {
        mContainerActivity.getFileOperationsHelper().toggleFavoriteFiles(checkedFiles, false);
        return true;
    } else if (itemId == R.id.action_move) {
        Intent action = new Intent(getActivity(), FolderPickerActivity.class);
        action.putParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES, new ArrayList<>(checkedFiles));
        action.putExtra(FolderPickerActivity.EXTRA_CURRENT_FOLDER, mFile);
        action.putExtra(FolderPickerActivity.EXTRA_ACTION, FolderPickerActivity.MOVE);
        getActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__MOVE_FILES);
        return true;
    } else if (itemId == R.id.action_copy) {
        Intent action = new Intent(getActivity(), FolderPickerActivity.class);
        action.putParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES, new ArrayList<>(checkedFiles));
        action.putExtra(FolderPickerActivity.EXTRA_CURRENT_FOLDER, mFile);
        action.putExtra(FolderPickerActivity.EXTRA_ACTION, FolderPickerActivity.COPY);
        getActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__COPY_FILES);
        return true;
    } else if (itemId == R.id.action_select_all_action_menu) {
        selectAllFiles(true);
        return true;
    } else if (itemId == R.id.action_deselect_all_action_menu) {
        selectAllFiles(false);
        return true;
    } else if (itemId == R.id.action_send_file) {
        mContainerActivity.getFileOperationsHelper().sendFiles(checkedFiles);
        return true;
    }
    return false;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) RenameFileDialogFragment(com.owncloud.android.ui.dialog.RenameFileDialogFragment) RemoveFilesDialogFragment(com.owncloud.android.ui.dialog.RemoveFilesDialogFragment) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Example 2 with RenameFileDialogFragment

use of com.owncloud.android.ui.dialog.RenameFileDialogFragment in project android by owncloud.

the class OCFileListFragment method onFileActionChosen.

/**
 * Start the appropriate action(s) on the currently selected files given menu selected by the user.
 *
 * @param menuId Identifier of the action menu selected by the user
 * @return 'true' if the menu selection started any action, 'false' otherwise.
 */
private boolean onFileActionChosen(int menuId) {
    final ArrayList<OCFile> checkedFiles = mFileListAdapter.getCheckedItems(getListView());
    if (checkedFiles.size() <= 0) {
        return false;
    }
    if (checkedFiles.size() == 1) {
        // / action only possible on a single file
        OCFile singleFile = checkedFiles.get(0);
        switch(menuId) {
            case R.id.action_share_file:
                {
                    mContainerActivity.getFileOperationsHelper().showShareFile(singleFile);
                    mEnableSelectAll = false;
                    return true;
                }
            case R.id.action_open_file_with:
                {
                    mContainerActivity.getFileOperationsHelper().openFile(singleFile);
                    return true;
                }
            case R.id.action_rename_file:
                {
                    RenameFileDialogFragment dialog = RenameFileDialogFragment.newInstance(singleFile);
                    dialog.show(getFragmentManager(), FileDetailFragment.FTAG_RENAME_FILE);
                    return true;
                }
            case R.id.action_see_details:
                {
                    if (mActiveActionMode != null) {
                        mActiveActionMode.finish();
                    }
                    mContainerActivity.showDetails(singleFile);
                    return true;
                }
            case R.id.action_send_file:
                {
                    // Obtain the file
                    if (!singleFile.isDown()) {
                        // Download the file
                        Timber.d("%s : File must be downloaded", singleFile.getRemotePath());
                        ((FileDisplayActivity) mContainerActivity).startDownloadForSending(singleFile);
                    } else {
                        mContainerActivity.getFileOperationsHelper().sendDownloadedFile(singleFile);
                    }
                    return true;
                }
        }
    }
    // / actions possible on a batch of files
    switch(menuId) {
        case R.id.file_action_select_all:
            {
                selectAll();
                return true;
            }
        case R.id.action_select_inverse:
            {
                for (int i = 0; i < mFileListAdapter.getCount(); i++) {
                    if (getListView().isItemChecked(i)) {
                        getListView().setItemChecked(i, false);
                    } else {
                        getListView().setItemChecked(i, true);
                    }
                }
                return true;
            }
        case R.id.action_remove_file:
            {
                RemoveFilesDialogFragment dialog = RemoveFilesDialogFragment.newInstance(checkedFiles);
                dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION);
                return true;
            }
        case R.id.action_download_file:
        case R.id.action_sync_file:
            {
                mContainerActivity.getFileOperationsHelper().syncFiles(checkedFiles);
                return true;
            }
        case R.id.action_cancel_sync:
            {
                ((FileDisplayActivity) mContainerActivity).cancelTransference(checkedFiles);
                return true;
            }
        case R.id.action_set_available_offline:
            {
                mContainerActivity.getFileOperationsHelper().toggleAvailableOffline(checkedFiles, true);
                getListView().invalidateViews();
                return true;
            }
        case R.id.action_unset_available_offline:
            {
                mContainerActivity.getFileOperationsHelper().toggleAvailableOffline(checkedFiles, false);
                getListView().invalidateViews();
                invalidateActionMode();
                if (mFileListOption.isAvailableOffline()) {
                    onRefresh();
                }
                return true;
            }
        case R.id.action_move:
            {
                Intent action = new Intent(getActivity(), FolderPickerActivity.class);
                action.putParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES, checkedFiles);
                requireActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__MOVE_FILES);
                return true;
            }
        case R.id.action_copy:
            Intent action = new Intent(getActivity(), FolderPickerActivity.class);
            action.putParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES, checkedFiles);
            requireActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__COPY_FILES);
            return true;
        default:
            return false;
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) RenameFileDialogFragment(com.owncloud.android.ui.dialog.RenameFileDialogFragment) RemoveFilesDialogFragment(com.owncloud.android.ui.dialog.RemoveFilesDialogFragment) Intent(android.content.Intent)

Example 3 with RenameFileDialogFragment

use of com.owncloud.android.ui.dialog.RenameFileDialogFragment in project android by nextcloud.

the class FileDetailFragment method optionsItemSelected.

private boolean optionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.action_send_file) {
        containerActivity.getFileOperationsHelper().sendShareFile(getFile(), true);
        return true;
    } else if (itemId == R.id.action_open_file_with) {
        containerActivity.getFileOperationsHelper().openFile(getFile());
        return true;
    } else if (itemId == R.id.action_remove_file) {
        RemoveFilesDialogFragment dialog = RemoveFilesDialogFragment.newInstance(getFile());
        dialog.show(getFragmentManager(), FTAG_CONFIRMATION);
        return true;
    } else if (itemId == R.id.action_rename_file) {
        RenameFileDialogFragment dialog = RenameFileDialogFragment.newInstance(getFile());
        dialog.show(getFragmentManager(), FTAG_RENAME_FILE);
        return true;
    } else if (itemId == R.id.action_cancel_sync) {
        ((FileDisplayActivity) containerActivity).cancelTransference(getFile());
        return true;
    } else if (itemId == R.id.action_download_file || itemId == R.id.action_sync_file) {
        containerActivity.getFileOperationsHelper().syncFile(getFile());
        return true;
    } else if (itemId == R.id.action_set_as_wallpaper) {
        containerActivity.getFileOperationsHelper().setPictureAs(getFile(), getView());
        return true;
    } else if (itemId == R.id.action_encrypted) {
        // TODO implement or remove
        return true;
    } else if (itemId == R.id.action_unset_encrypted) {
        // TODO implement or remove
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) RemoveFilesDialogFragment(com.owncloud.android.ui.dialog.RemoveFilesDialogFragment) RenameFileDialogFragment(com.owncloud.android.ui.dialog.RenameFileDialogFragment)

Aggregations

RemoveFilesDialogFragment (com.owncloud.android.ui.dialog.RemoveFilesDialogFragment)3 RenameFileDialogFragment (com.owncloud.android.ui.dialog.RenameFileDialogFragment)3 Intent (android.content.Intent)2 OCFile (com.owncloud.android.datamodel.OCFile)2 FileDisplayActivity (com.owncloud.android.ui.activity.FileDisplayActivity)2 FolderPickerActivity (com.owncloud.android.ui.activity.FolderPickerActivity)2 ArrayList (java.util.ArrayList)1