Search in sources :

Example 1 with FolderPickerActivity

use of com.owncloud.android.ui.activity.FolderPickerActivity in project android by nextcloud.

the class ExtendedListFragment method performSearch.

public void performSearch(final String query, boolean isBackPressed) {
    handler.removeCallbacksAndMessages(null);
    RecyclerView.Adapter adapter = getRecyclerView().getAdapter();
    Activity activity = getActivity();
    if (activity != null) {
        if (activity instanceof FileDisplayActivity) {
            if (isBackPressed && TextUtils.isEmpty(query)) {
                FileDisplayActivity fileDisplayActivity = (FileDisplayActivity) activity;
                fileDisplayActivity.resetSearchView();
                fileDisplayActivity.updateListOfFilesFragment(true);
            } else {
                handler.post(() -> {
                    if (adapter instanceof OCFileListAdapter) {
                        if (accountManager.getUser().getServer().getVersion().isNewerOrEqual(OwnCloudVersion.nextcloud_20)) {
                            ((FileDisplayActivity) activity).performUnifiedSearch(query);
                        } else {
                            EventBus.getDefault().post(new SearchEvent(query, SearchRemoteOperation.SearchType.FILE_SEARCH));
                        }
                    } else if (adapter instanceof LocalFileListAdapter) {
                        LocalFileListAdapter localFileListAdapter = (LocalFileListAdapter) adapter;
                        localFileListAdapter.filter(query);
                    }
                });
                if (searchView != null) {
                    searchView.clearFocus();
                }
            }
        } else if (activity instanceof UploadFilesActivity) {
            LocalFileListAdapter localFileListAdapter = (LocalFileListAdapter) adapter;
            localFileListAdapter.filter(query);
            ((UploadFilesActivity) activity).showToolbarSpinner();
        } else if (activity instanceof FolderPickerActivity) {
            ((FolderPickerActivity) activity).refreshListOfFilesFragment(true);
        }
    }
}
Also used : FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) UploadFilesActivity(com.owncloud.android.ui.activity.UploadFilesActivity) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) Activity(android.app.Activity) RecyclerView(androidx.recyclerview.widget.RecyclerView) EmptyRecyclerView(com.owncloud.android.ui.EmptyRecyclerView) SearchEvent(com.owncloud.android.ui.events.SearchEvent) LocalFileListAdapter(com.owncloud.android.ui.adapter.LocalFileListAdapter) UploadFilesActivity(com.owncloud.android.ui.activity.UploadFilesActivity) OCFileListAdapter(com.owncloud.android.ui.adapter.OCFileListAdapter)

Example 2 with FolderPickerActivity

use of com.owncloud.android.ui.activity.FolderPickerActivity 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 FolderPickerActivity

use of com.owncloud.android.ui.activity.FolderPickerActivity in project android by nextcloud.

the class ExtendedListFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) {
    final MenuItem item = menu.findItem(R.id.action_search);
    searchView = (SearchView) MenuItemCompat.getActionView(item);
    closeButton = searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
    searchView.setOnQueryTextListener(this);
    searchView.setOnCloseListener(this);
    ThemeToolbarUtils.themeSearchView(searchView, requireContext());
    SearchView.SearchAutoComplete theTextArea = searchView.findViewById(R.id.search_src_text);
    theTextArea.setHighlightColor(ThemeColorUtils.primaryAccentColor(getContext()));
    final Handler handler = new Handler();
    DisplayMetrics displaymetrics = new DisplayMetrics();
    Activity activity;
    if ((activity = getActivity()) != null) {
        activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int width = displaymetrics.widthPixels;
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            searchView.setMaxWidth((int) (width * 0.4));
        } else {
            if (activity instanceof FolderPickerActivity) {
                searchView.setMaxWidth((int) (width * 0.8));
            } else {
                searchView.setMaxWidth(width);
            }
        }
    }
    searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> handler.post(() -> {
        if (getActivity() != null && !(getActivity() instanceof FolderPickerActivity) && !(getActivity() instanceof UploadFilesActivity)) {
            if (getActivity() instanceof FileDisplayActivity) {
                Fragment fragment = ((FileDisplayActivity) getActivity()).getLeftFragment();
                if (fragment instanceof OCFileListFragment) {
                    ((OCFileListFragment) fragment).setFabVisible(!hasFocus);
                }
            }
            if (TextUtils.isEmpty(searchView.getQuery())) {
                closeButton.setVisibility(View.INVISIBLE);
            }
        }
    }));
    // On close -> empty field, show keyboard and
    closeButton.setOnClickListener(view -> {
        searchView.setQuery("", true);
        searchView.requestFocus();
        searchView.onActionViewExpanded();
        InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (inputMethodManager != null) {
            inputMethodManager.showSoftInput(searchView, InputMethodManager.SHOW_IMPLICIT);
        }
    });
    final View mSearchEditFrame = searchView.findViewById(androidx.appcompat.R.id.search_edit_frame);
    ViewTreeObserver vto = mSearchEditFrame.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        int oldVisibility = -1;

        @Override
        public void onGlobalLayout() {
            int currentVisibility = mSearchEditFrame.getVisibility();
            if (currentVisibility != oldVisibility) {
                if (currentVisibility == View.VISIBLE) {
                    setEmptyListMessage(SearchType.REGULAR_FILTER);
                } else {
                    if (MainApp.isOnlyOnDevice()) {
                        setMessageForEmptyList(R.string.file_list_empty_headline, R.string.file_list_empty_on_device, R.drawable.ic_list_empty_folder, true);
                    } else {
                        setEmptyListMessage(SearchType.NO_SEARCH);
                    }
                }
                oldVisibility = currentVisibility;
            }
        }
    });
    LinearLayout searchBar = searchView.findViewById(R.id.search_bar);
    searchBar.setLayoutTransition(new LayoutTransition());
}
Also used : Handler(android.os.Handler) UploadFilesActivity(com.owncloud.android.ui.activity.UploadFilesActivity) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) Activity(android.app.Activity) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) LayoutTransition(android.animation.LayoutTransition) DisplayMetrics(android.util.DisplayMetrics) Fragment(androidx.fragment.app.Fragment) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) EmptyRecyclerView(com.owncloud.android.ui.EmptyRecyclerView) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) SearchView(androidx.appcompat.widget.SearchView) UploadFilesActivity(com.owncloud.android.ui.activity.UploadFilesActivity) ViewTreeObserver(android.view.ViewTreeObserver) LinearLayout(android.widget.LinearLayout)

Aggregations

FileDisplayActivity (com.owncloud.android.ui.activity.FileDisplayActivity)3 FolderPickerActivity (com.owncloud.android.ui.activity.FolderPickerActivity)3 Activity (android.app.Activity)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 EmptyRecyclerView (com.owncloud.android.ui.EmptyRecyclerView)2 UploadFilesActivity (com.owncloud.android.ui.activity.UploadFilesActivity)2 LayoutTransition (android.animation.LayoutTransition)1 Intent (android.content.Intent)1 Handler (android.os.Handler)1 DisplayMetrics (android.util.DisplayMetrics)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 SearchView (androidx.appcompat.widget.SearchView)1