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);
}
}
}
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!");
}
}
}
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());
}
Aggregations