use of com.owncloud.android.ui.activity.FileDisplayActivity in project android by nextcloud.
the class OCFileListFragment method listDirectory.
/**
* Lists the given directory on the view. When the input parameter is null,
* it will either refresh the last known directory. list the root
* if there never was a directory.
*
* @param directory File to be listed
*/
public void listDirectory(OCFile directory, OCFile file, boolean onlyOnDevice, boolean fromSearch) {
if (!searchFragment) {
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
if (storageManager != null) {
// Check input parameters for null
if (directory == null) {
if (mFile != null) {
directory = mFile;
} else {
directory = storageManager.getFileByPath(ROOT_PATH);
if (directory == null) {
// no files, wait for sync
return;
}
}
}
// If that's not a directory -> List its parent
if (!directory.isFolder()) {
Log_OC.w(TAG, "You see, that is not a directory -> " + directory);
directory = storageManager.getFileById(directory.getParentId());
}
if (searchView != null && !searchView.isIconified() && !fromSearch) {
searchView.post(() -> {
searchView.setQuery("", false);
searchView.onActionViewCollapsed();
Activity activity;
if ((activity = getActivity()) != null && activity instanceof FileDisplayActivity) {
FileDisplayActivity fileDisplayActivity = (FileDisplayActivity) activity;
fileDisplayActivity.hideSearchView(fileDisplayActivity.getCurrentDir());
if (getCurrentFile() != null) {
fileDisplayActivity.setDrawerIndicatorEnabled(fileDisplayActivity.isRoot(getCurrentFile()));
}
}
});
}
mAdapter.swapDirectory(accountManager.getUser(), directory, storageManager, onlyOnDevice, mLimitToMimeType);
OCFile previousDirectory = mFile;
mFile = directory;
updateLayout();
if (file != null) {
mAdapter.setHighlightedItem(file);
int position = mAdapter.getItemPosition(file);
if (position != -1) {
getRecyclerView().scrollToPosition(position);
}
} else if (previousDirectory == null || !previousDirectory.equals(directory)) {
getRecyclerView().scrollToPosition(0);
}
}
}
}
use of com.owncloud.android.ui.activity.FileDisplayActivity 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.FileDisplayActivity in project android by nextcloud.
the class PreviewMediaFragment method bindMediaService.
private void bindMediaService() {
Log_OC.d(TAG, "Binding to MediaService...");
if (mMediaServiceConnection == null) {
mMediaServiceConnection = new MediaServiceConnection();
}
getActivity().bindService(new Intent(getActivity(), MediaService.class), mMediaServiceConnection, Context.BIND_AUTO_CREATE);
// follow the flow in MediaServiceConnection#onServiceConnected(...)
((FileDisplayActivity) getActivity()).setMediaServiceConnection();
}
use of com.owncloud.android.ui.activity.FileDisplayActivity in project android by owncloud.
the class OCFileListFragment method onItemClick.
@Override
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
OCFile file = (OCFile) mFileListAdapter.getItem(position);
if (file != null) {
if (file.isFolder()) {
listDirectoryWithAnimationDown(file);
// then, notify parent activity to let it update its state and view
mContainerActivity.onBrowsedDownTo(file);
// save index and top position
saveIndexAndTopPosition(position);
} else {
// / Click on a file
if (PreviewImageFragment.canBePreviewed(file)) {
// preview image - it handles the sync, if needed
((FileDisplayActivity) mContainerActivity).startImagePreview(file);
} else if (PreviewTextFragment.canBePreviewed(file)) {
((FileDisplayActivity) mContainerActivity).startTextPreview(file);
mContainerActivity.getFileOperationsHelper().syncFile(file);
} else if (PreviewAudioFragment.canBePreviewed(file)) {
// media preview
((FileDisplayActivity) mContainerActivity).startAudioPreview(file, 0);
mContainerActivity.getFileOperationsHelper().syncFile(file);
} else if (PreviewVideoFragment.canBePreviewed(file) && !fileIsDownloading(file)) {
// Available offline exception, don't initialize streaming
if (!file.isDown() && file.isAvailableOffline()) {
// sync file content, then open with external apps
((FileDisplayActivity) mContainerActivity).startSyncThenOpen(file);
} else {
// media preview
((FileDisplayActivity) mContainerActivity).startVideoPreview(file, 0);
}
// new available file version
if (file.isDown()) {
mContainerActivity.getFileOperationsHelper().syncFile(file);
}
} else {
// sync file content, then open with external apps
((FileDisplayActivity) mContainerActivity).startSyncThenOpen(file);
}
}
} else {
Timber.d("Null object in ListAdapter!!");
}
}
use of com.owncloud.android.ui.activity.FileDisplayActivity in project android by owncloud.
the class PreviewVideoFragment method showAlertDialog.
/**
* Show an alert dialog with the error produced while playing the video and initialize a
* specific behaviour when necessary
*
* @param previewVideoError player error with the needed info
*/
private void showAlertDialog(final PreviewVideoError previewVideoError) {
new AlertDialog.Builder(requireActivity()).setMessage(previewVideoError.getErrorMessage()).setPositiveButton(android.R.string.VideoView_error_button, (dialog, whichButton) -> {
if (previewVideoError.isFileSyncNeeded() && mContainerActivity != null) {
// Initialize the file download
mContainerActivity.getFileOperationsHelper().syncFile(getFile());
}
// or involving other parts
if (previewVideoError.isParentFolderSyncNeeded()) {
// Start to sync the parent file folder
OCFile folder = new OCFile(getFile().getParentRemotePath());
((FileDisplayActivity) requireActivity()).startSyncFolderOperation(folder, false);
}
}).setCancelable(false).show();
}
Aggregations