Search in sources :

Example 1 with VirtualFolderType

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

the class PreviewImageActivity method initViewPager.

private void initViewPager() {
    // virtual folder
    if (getIntent().getSerializableExtra(EXTRA_VIRTUAL_TYPE) != null) {
        VirtualFolderType type = (VirtualFolderType) getIntent().getSerializableExtra(EXTRA_VIRTUAL_TYPE);
        mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), type, getAccount(), getStorageManager());
    } else {
        // get parent from path
        OCFile parentFolder = getStorageManager().getFileById(getFile().getParentId());
        if (parentFolder == null) {
            // should not be necessary
            parentFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
        }
        mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), parentFolder, getAccount(), getStorageManager(), MainApp.isOnlyOnDevice(), this);
    }
    mViewPager = findViewById(R.id.fragmentPager);
    int position = mHasSavedPosition ? mSavedPosition : mPreviewImagePagerAdapter.getFilePosition(getFile());
    position = (position >= 0) ? position : 0;
    mViewPager.setAdapter(mPreviewImagePagerAdapter);
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setCurrentItem(position);
    if (position == 0 && !getFile().isDown()) {
        // this is necessary because mViewPager.setCurrentItem(0) just after setting the
        // adapter does not result in a call to #onPageSelected(0)
        mRequestWaitingForBinder = true;
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType) SuppressLint(android.annotation.SuppressLint)

Example 2 with VirtualFolderType

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

the class OCFileListFragment method onItemClicked.

@Override
public void onItemClicked(OCFile file) {
    if (getAdapter().isMultiSelect()) {
        toggleItemToCheckedList(file);
    } else {
        if (file != null) {
            int position = mAdapter.getItemPosition(file);
            if (file.isFolder()) {
                resetHeaderScrollingState();
                if (file.isEncrypted()) {
                    User user = ((FileActivity) mContainerActivity).getUser().orElseThrow(RuntimeException::new);
                    // check if e2e app is enabled
                    OCCapability ocCapability = mContainerActivity.getStorageManager().getCapability(user.getAccountName());
                    if (ocCapability.getEndToEndEncryption().isFalse() || ocCapability.getEndToEndEncryption().isUnknown()) {
                        Snackbar.make(getRecyclerView(), R.string.end_to_end_encryption_not_enabled, Snackbar.LENGTH_LONG).show();
                        return;
                    }
                    // check if keys are stored
                    ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
                    String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
                    String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);
                    if (publicKey.isEmpty() || privateKey.isEmpty()) {
                        Log_OC.d(TAG, "no public key for " + user.getAccountName());
                        SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
                        dialog.setTargetFragment(this, SetupEncryptionDialogFragment.SETUP_ENCRYPTION_REQUEST_CODE);
                        dialog.show(getFragmentManager(), SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG);
                    } else {
                        // update state and view of this fragment
                        searchFragment = false;
                        mHideFab = false;
                        if (mContainerActivity instanceof FolderPickerActivity && ((FolderPickerActivity) mContainerActivity).isDoNotEnterEncryptedFolder()) {
                            Snackbar.make(getRecyclerView(), R.string.copy_move_to_encrypted_folder_not_supported, Snackbar.LENGTH_LONG).show();
                        } else {
                            listDirectory(file, MainApp.isOnlyOnDevice(), false);
                            // then, notify parent activity to let it update its state and view
                            mContainerActivity.onBrowsedDownTo(file);
                            // save index and top position
                            saveIndexAndTopPosition(position);
                        }
                    }
                } else {
                    // update state and view of this fragment
                    searchFragment = false;
                    setEmptyListLoadingMessage();
                    listDirectory(file, MainApp.isOnlyOnDevice(), false);
                    // then, notify parent activity to let it update its state and view
                    mContainerActivity.onBrowsedDownTo(file);
                    // save index and top position
                    saveIndexAndTopPosition(position);
                }
            } else if (mFileSelectable) {
                Intent intent = new Intent();
                intent.putExtra(FolderPickerActivity.EXTRA_FILES, file);
                getActivity().setResult(Activity.RESULT_OK, intent);
                getActivity().finish();
            } else if (!mOnlyFoldersClickable) {
                // Click on a file
                if (PreviewImageFragment.canBePreviewed(file)) {
                    // preview image - it handles the download, if needed
                    if (searchFragment) {
                        VirtualFolderType type;
                        switch(currentSearchType) {
                            case FAVORITE_SEARCH:
                                type = VirtualFolderType.FAVORITE;
                                break;
                            case GALLERY_SEARCH:
                                type = VirtualFolderType.GALLERY;
                                break;
                            default:
                                type = VirtualFolderType.NONE;
                                break;
                        }
                        ((FileDisplayActivity) mContainerActivity).startImagePreview(file, type, !file.isDown());
                    } else {
                        ((FileDisplayActivity) mContainerActivity).startImagePreview(file, !file.isDown());
                    }
                } else if (file.isDown() && MimeTypeUtil.isVCard(file)) {
                    ((FileDisplayActivity) mContainerActivity).startContactListFragment(file);
                } else if (file.isDown() && MimeTypeUtil.isPDF(file)) {
                    ((FileDisplayActivity) mContainerActivity).startPdfPreview(file);
                } else if (PreviewTextFileFragment.canBePreviewed(file)) {
                    setFabVisible(false);
                    resetHeaderScrollingState();
                    ((FileDisplayActivity) mContainerActivity).startTextPreview(file, false);
                } else if (file.isDown()) {
                    if (PreviewMediaFragment.canBePreviewed(file)) {
                        // media preview
                        setFabVisible(false);
                        resetHeaderScrollingState();
                        ((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true, true, false);
                    } else {
                        mContainerActivity.getFileOperationsHelper().openFile(file);
                    }
                } else {
                    // file not downloaded, check for streaming, remote editing
                    User account = accountManager.getUser();
                    OCCapability capability = mContainerActivity.getStorageManager().getCapability(account.getAccountName());
                    if (PreviewMediaFragment.canBePreviewed(file) && !file.isEncrypted()) {
                        // stream media preview on >= NC14
                        setFabVisible(false);
                        resetHeaderScrollingState();
                        ((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true, true, true);
                    } else if (FileMenuFilter.isEditorAvailable(requireContext().getContentResolver(), accountManager.getUser(), file.getMimeType()) && !file.isEncrypted()) {
                        mContainerActivity.getFileOperationsHelper().openFileWithTextEditor(file, getContext());
                    } else if (capability.getRichDocumentsMimeTypeList().contains(file.getMimeType()) && capability.getRichDocumentsDirectEditing().isTrue() && !file.isEncrypted()) {
                        mContainerActivity.getFileOperationsHelper().openFileAsRichDocument(file, getContext());
                    } else {
                        // automatic download, preview on finish
                        ((FileDisplayActivity) mContainerActivity).startDownloadForPreview(file);
                    }
                }
            }
        } else {
            Log_OC.d(TAG, "Null object in ListAdapter!");
        }
    }
}
Also used : FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) User(com.nextcloud.client.account.User) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent) SetupEncryptionDialogFragment(com.owncloud.android.ui.dialog.SetupEncryptionDialogFragment) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType)

Example 3 with VirtualFolderType

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

the class OCFileListAdapter method parseVirtuals.

private void parseVirtuals(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) {
    VirtualFolderType type;
    boolean onlyImages = false;
    switch(searchType) {
        case FAVORITE_SEARCH:
            type = VirtualFolderType.FAVORITE;
            break;
        case PHOTO_SEARCH:
            type = VirtualFolderType.PHOTOS;
            onlyImages = true;
            break;
        default:
            type = VirtualFolderType.NONE;
            break;
    }
    mStorageManager.deleteVirtuals(type);
    List<ContentValues> contentValues = new ArrayList<>();
    for (int i = 0; i < objects.size(); i++) {
        OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
        searchForLocalFileInDefaultPath(ocFile);
        try {
            ocFile = mStorageManager.saveFileWithParent(ocFile, mContext);
            if (!onlyImages || MimeTypeUtil.isImage(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);
        }
    }
    mStorageManager.saveVirtuals(type, contentValues);
}
Also used : ContentValues(android.content.ContentValues) OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperationFailedException(com.owncloud.android.operations.RemoteOperationFailedException) ArrayList(java.util.ArrayList) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType)

Example 4 with VirtualFolderType

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

the class OCFileListAdapter method setData.

public void setData(List<Object> objects, SearchType searchType, FileDataStorageManager storageManager, @Nullable OCFile folder, boolean clear) {
    if (storageManager != null && mStorageManager == null) {
        mStorageManager = storageManager;
        showShareAvatar = mStorageManager.getCapability(user.getAccountName()).getVersion().isShareesOnDavSupported();
    }
    if (mStorageManager == null) {
        mStorageManager = new FileDataStorageManager(user, activity.getContentResolver());
    }
    if (clear) {
        mFiles.clear();
        resetLastTimestamp();
        preferences.setPhotoSearchTimestamp(0);
        VirtualFolderType type;
        switch(searchType) {
            case FAVORITE_SEARCH:
                type = VirtualFolderType.FAVORITE;
                break;
            case GALLERY_SEARCH:
                type = VirtualFolderType.GALLERY;
                break;
            default:
                type = VirtualFolderType.NONE;
                break;
        }
        if (type != VirtualFolderType.GALLERY) {
            mStorageManager.deleteVirtuals(type);
        }
    }
    // early exit
    if (objects.size() > 0 && mStorageManager != null) {
        if (searchType == SearchType.SHARED_FILTER) {
            parseShares(objects);
        } else {
            if (searchType != SearchType.GALLERY_SEARCH) {
                parseVirtuals(objects, searchType);
            }
        }
    }
    if (searchType != SearchType.GALLERY_SEARCH && searchType != SearchType.RECENTLY_MODIFIED_SEARCH) {
        FileSortOrder sortOrder = preferences.getSortOrderByFolder(folder);
        mFiles = sortOrder.sortCloudFiles(mFiles);
    } else {
        mFiles = FileStorageUtils.sortOcFolderDescDateModifiedWithoutFavoritesFirst(mFiles);
    }
    mFilesAll.clear();
    mFilesAll.addAll(mFiles);
    new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
}
Also used : FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Handler(android.os.Handler) FileSortOrder(com.owncloud.android.utils.FileSortOrder) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType)

Example 5 with VirtualFolderType

use of com.owncloud.android.datamodel.VirtualFolderType 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);
}
Also used : ContentValues(android.content.ContentValues) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) ArrayList(java.util.ArrayList) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType) Point(android.graphics.Point) OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperationFailedException(com.owncloud.android.operations.RemoteOperationFailedException) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile)

Aggregations

VirtualFolderType (com.owncloud.android.datamodel.VirtualFolderType)6 OCFile (com.owncloud.android.datamodel.OCFile)4 SuppressLint (android.annotation.SuppressLint)2 ContentValues (android.content.ContentValues)2 RemoteOperationFailedException (com.owncloud.android.operations.RemoteOperationFailedException)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 Point (android.graphics.Point)1 Handler (android.os.Handler)1 User (com.nextcloud.client.account.User)1 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)1 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)1 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 ReadFileRemoteOperation (com.owncloud.android.lib.resources.files.ReadFileRemoteOperation)1 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)1 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)1 RefreshFolderOperation (com.owncloud.android.operations.RefreshFolderOperation)1 FileDisplayActivity (com.owncloud.android.ui.activity.FileDisplayActivity)1 FolderPickerActivity (com.owncloud.android.ui.activity.FolderPickerActivity)1 SetupEncryptionDialogFragment (com.owncloud.android.ui.dialog.SetupEncryptionDialogFragment)1