Search in sources :

Example 1 with SetupEncryptionDialogFragment

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

the class OCFileListFragment method onItemClicked.

@Override
public void onItemClicked(OCFile file) {
    if (getAdapter().isMultiSelect()) {
        if (getAdapter().isCheckedFile(file)) {
            getAdapter().removeCheckedFile(file);
        } else {
            getAdapter().addCheckedFile(file);
        }
        mActiveActionMode.invalidate();
        mAdapter.notifyItemChanged(getAdapter().getItemPosition(file));
    } else {
        if (file != null) {
            int position = mAdapter.getItemPosition(file);
            if (file.isFolder()) {
                if (file.isEncrypted()) {
                    // check if API >= 19
                    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
                        Snackbar.make(getRecyclerView(), R.string.end_to_end_encryption_not_supported, Snackbar.LENGTH_LONG).show();
                        return;
                    }
                    Account account = ((FileActivity) mContainerActivity).getAccount();
                    // check if e2e app is enabled
                    OCCapability ocCapability = mContainerActivity.getStorageManager().getCapability(account.name);
                    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(account, EncryptionUtils.PUBLIC_KEY);
                    String privateKey = arbitraryDataProvider.getValue(account, EncryptionUtils.PRIVATE_KEY);
                    if (publicKey.isEmpty() || privateKey.isEmpty()) {
                        Log_OC.d(TAG, "no public key for " + account.name);
                        SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(account, 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;
                        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;
                    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 (!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 PHOTO_SEARCH:
                                type = VirtualFolderType.PHOTOS;
                                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 (PreviewTextFragment.canBePreviewed(file)) {
                    ((FileDisplayActivity) mContainerActivity).startTextPreview(file, false);
                } else if (file.isDown()) {
                    if (PreviewMediaFragment.canBePreviewed(file)) {
                        // media preview
                        ((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true, false);
                    } else {
                        mContainerActivity.getFileOperationsHelper().openFile(file);
                    }
                } else {
                    // automatic download, preview on finish
                    ((FileDisplayActivity) mContainerActivity).startDownloadForPreview(file);
                }
            }
        } else {
            Log_OC.d(TAG, "Null object in ListAdapter!!");
        }
    }
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) FileActivity(com.owncloud.android.ui.activity.FileActivity) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) SetupEncryptionDialogFragment(com.owncloud.android.ui.dialog.SetupEncryptionDialogFragment) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType)

Aggregations

Account (android.accounts.Account)1 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)1 VirtualFolderType (com.owncloud.android.datamodel.VirtualFolderType)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)1 FileActivity (com.owncloud.android.ui.activity.FileActivity)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