X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/9b5506f81e61906c094f210b19d66dbbb99d505f..f72289f7bfb2aef41f575cbfe225c94e4d5fabe2:/src/com/owncloud/android/files/FileOperationsHelper.java diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index c0b00e55..cf0f50f0 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -22,7 +22,11 @@ package com.owncloud.android.files; import android.accounts.Account; +import android.content.ActivityNotFoundException; +import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.net.Uri; import android.support.v4.app.DialogFragment; import android.webkit.MimeTypeMap; @@ -43,6 +47,8 @@ import com.owncloud.android.ui.dialog.ShareLinkToDialog; import org.apache.http.protocol.HTTP; +import java.util.List; + /** * */ @@ -86,21 +92,46 @@ public class FileOperationsHelper { ); } } - - Intent chooserIntent; + + Intent openFileWithIntent; if (intentForGuessedMimeType != null) { - chooserIntent = Intent.createChooser(intentForGuessedMimeType, mFileActivity.getString(R.string.actionbar_open_with)); + openFileWithIntent = intentForGuessedMimeType; } else { - chooserIntent = Intent.createChooser(intentForSavedMimeType, mFileActivity.getString(R.string.actionbar_open_with)); + openFileWithIntent = intentForSavedMimeType; } - mFileActivity.startActivity(chooserIntent); + List launchables = mFileActivity.getPackageManager(). + queryIntentActivities(openFileWithIntent, PackageManager.GET_INTENT_FILTERS); + + if(launchables != null && launchables.size() > 0) { + try { + mFileActivity.startActivity( + Intent.createChooser( + openFileWithIntent, mFileActivity.getString(R.string.actionbar_open_with) + ) + ); + } catch (ActivityNotFoundException anfe) { + showNoAppForFileTypeToast(mFileActivity.getApplicationContext()); + } + } else { + showNoAppForFileTypeToast(mFileActivity.getApplicationContext()); + } } else { Log_OC.wtf(TAG, "Trying to open a NULL OCFile"); } } + /** + * Displays a toast stating that no application could be found to open the file. + * + * @param context the context to be able to show a toast. + */ + private void showNoAppForFileTypeToast(Context context) { + Toast.makeText(context, + R.string.file_list_no_app_for_file_type, Toast.LENGTH_SHORT) + .show(); + } public void shareFileWithLink(OCFile file) { @@ -230,30 +261,6 @@ public class FileOperationsHelper { } } - - /** - * Request the synchronization of a file or the DOWNLOAD OF A FOLDER, including its contents. - * - * For files, it's the same as syncFile(OCFile file); for folders, this method does not trigger uploads for - * file locally modified. - * - * Kept 'til synchronization of full folders is considered good enough. - * - * @param file The file or folder to synchronize - */ - public void downloadFile(OCFile file) { - if (!file.isFolder()){ - syncFile(file); - - } else { - Intent intent = new Intent(mFileActivity, OperationsService.class); - intent.setAction(OperationsService.ACTION_DOWNLOAD_FOLDER); - intent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); - intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); - mFileActivity.startService(intent); - } - } - public void toggleFavorite(OCFile file, boolean isFavorite) { file.setFavorite(isFavorite); mFileActivity.getStorageManager().saveFile(file); @@ -327,15 +334,6 @@ public class FileOperationsHelper { FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder(); if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) { downloaderBinder.cancel(account, file); - - // TODO - review why is this here, and solve in a better way - // Remove etag for parent, if file is a favorite - if (file.isFavorite()) { - OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId()); - parent.setEtag(""); - mFileActivity.getStorageManager().saveFile(parent); - } - } FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder(); if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {