X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/49c1f9e3180099dff1ba1d8880a95314e47480a4..43da474a54718e5cfcd8be06c0aaa5b81b80699e:/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index 6b2aa86a..9bcf9dee 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -39,6 +39,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.webkit.MimeTypeMap; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; @@ -151,6 +152,7 @@ public class FileDetailFragment extends SherlockFragment implements i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath()); i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getURLDecodedRemotePath()); i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength()); + v.setEnabled(false); getActivity().startService(i); } @@ -236,20 +238,48 @@ public class FileDetailFragment extends SherlockFragment implements } catch (Throwable t) { preview.setVisibility(View.INVISIBLE); - Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength()); + Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength(), t); } downloadButton.setText(R.string.filedetails_open); downloadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mFile.getMimetype()); - i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + String storagePath = mFile.getStoragePath(); try { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setDataAndType(Uri.parse("file://"+ storagePath), mFile.getMimetype()); + i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); - } catch (ActivityNotFoundException e) { - Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show(); + } catch (Throwable t) { + Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.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 != mFile.getMimetype()) { + i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mimeType); + 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 " + mFile.getFileName(), Toast.LENGTH_SHORT).show(); + } + } + } } }); @@ -316,24 +346,24 @@ public class FileDetailFragment extends SherlockFragment implements } /** - * In ownCloud 3.0.3 and 4.0.0 there is a bug that SabreDAV does not return + * In ownCloud 3.X.X and 4.X.X there is a bug that SabreDAV does not return * the time that the file was created. There is a chance that this will * be fixed in future versions. Use this method to check if this version of * ownCloud has this fix. - * @return True, if ownCloud the ownCloud version is > 3.0.4 and 4.0.1 + * @return True, if ownCloud the ownCloud version is supporting creationg time */ private boolean ocVersionSupportsTimeCreated(){ - if(mIntent != null){ + /* if(mIntent != null){ Account ocAccount = mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT); if(ocAccount != null){ AccountManager accManager = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE); OwnCloudVersion ocVersion = new OwnCloudVersion(accManager .getUserData(ocAccount, AccountAuthenticator.KEY_OC_VERSION)); - if(ocVersion.compareTo(new OwnCloudVersion(0x030004)) >= 0 || ocVersion.compareTo(new OwnCloudVersion(0x040001)) >= 0){ + if(ocVersion.compareTo(new OwnCloudVersion(0x030000)) < 0) { return true; } } - } + }*/ return false; } @@ -344,8 +374,14 @@ public class FileDetailFragment extends SherlockFragment implements private class DownloadFinishReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - ((OCFile)mIntent.getParcelableExtra(EXTRA_FILE)).setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); - updateFileDetails(mIntent); + getView().findViewById(R.id.fdDownloadBtn).setEnabled(true); + if (intent.getAction().equals(FileDownloader.BAD_DOWNLOAD_MESSAGE)) { + Toast.makeText(context, R.string.downloader_download_failed , Toast.LENGTH_SHORT).show(); + + } else if (intent.getAction().equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) { + ((OCFile)mIntent.getParcelableExtra(EXTRA_FILE)).setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); + updateFileDetails(mIntent); + } } }