+ }
+ case R.id.open_file_item: {
+ String storagePath = mTargetFile.getStoragePath();
+ String encodedStoragePath = WebdavUtils.encodePath(storagePath);
+ try {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mTargetFile.getMimetype());
+ i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ startActivity(i);
+
+ } catch (Throwable t) {
+ Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mTargetFile.getMimetype());
+ boolean toastIt = true;
+ String mimeType = "";
+ try {
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
+ if (mimeType == null || !mimeType.equals(mTargetFile.getMimetype())) {
+ if (mimeType != null) {
+ i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
+ } else {
+ // desperate try
+ i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), "*/*");
+ }
+ i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ startActivity(i);
+ toastIt = false;
+ }
+
+ } catch (IndexOutOfBoundsException e) {
+ Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
+
+ } catch (ActivityNotFoundException e) {
+ Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
+
+ } catch (Throwable th) {
+ Log.e(TAG, "Unexpected problem when opening: " + storagePath, th);
+
+ } finally {
+ if (toastIt) {
+ Toast.makeText(getActivity(), "There is no application to handle file " + mTargetFile.getFileName(), Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ }
+ return true;
+ }
+ case R.id.download_file_item: {
+ Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
+ Intent i = new Intent(getActivity(), FileDownloader.class);
+ i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
+ i.putExtra(FileDownloader.EXTRA_FILE, mTargetFile);
+ getActivity().startService(i);
+ listDirectory();
+ return true;
+ }
+ case R.id.cancel_download_item: {
+ FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
+ Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
+ if (downloaderBinder != null && downloaderBinder.isDownloading(account, mTargetFile)) {
+ downloaderBinder.cancel(account, mTargetFile);
+ listDirectory();
+ }
+ return true;
+ }
+ case R.id.cancel_upload_item: {
+ FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
+ Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
+ if (uploaderBinder != null && uploaderBinder.isUploading(account, mTargetFile)) {
+ uploaderBinder.cancel(account, mTargetFile);
+ listDirectory();
+ }
+ return true;
+ }