From: masensio Date: Tue, 18 Feb 2014 09:32:28 +0000 (+0100) Subject: Merge branch 'develop' into send_file_pr311_with_develop X-Git-Tag: oc-android-1.5.5~22^2~22 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/c6d4f4980b1099764f8dc169abe881f7191fca6b?hp=c28ab3aec8df30f97339f1ff3f07491d4e33beb9 Merge branch 'develop' into send_file_pr311_with_develop --- diff --git a/res/values/strings.xml b/res/values/strings.xml index bd672b27..af816994 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -252,4 +252,6 @@ An error occurred while trying to share this file or folder Unable to unshare this file or folder. It does not exist. An error occurred while trying to unshare this file or folder + + Send diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 4b37a3ba..a0927b2f 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -139,7 +139,7 @@ public class FileOperationsHelper { } return false; } - + public void unshareFileWithLink(OCFile file, FileActivity callerActivity) { @@ -160,4 +160,23 @@ public class FileOperationsHelper { } } + + public void sendDownloadedFile(OCFile file, FileActivity callerActivity) { + if (file != null) { + Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); + // set MimeType + sendIntent.setType(file.getMimetype()); + sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getStoragePath())); + sendIntent.putExtra(Intent.ACTION_SEND, true); // Send Action + + // Show dialog, without the own app + String[] packagesToExclude = new String[] { callerActivity.getPackageName() }; + DialogFragment chooserDialog = ActivityChooserDialog.newInstance(sendIntent, packagesToExclude, file); + chooserDialog.show(callerActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG); + + } else { + Log_OC.wtf(TAG, "Trying to send a NULL OCFile"); + } + } + } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index e6963522..4bbac63d 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -86,7 +86,6 @@ import com.owncloud.android.ui.fragment.FileDetailFragment; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.ui.fragment.OCFileListFragment; import com.owncloud.android.ui.preview.PreviewImageActivity; -import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; import com.owncloud.android.ui.preview.PreviewVideoActivity; import com.owncloud.android.utils.DisplayUtils; @@ -120,7 +119,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW"; private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS"; - private static final String KEY_REFRESH_SHARES_IN_PROGRESS = "SHARES_IN_PROGRESS"; + //private static final String KEY_REFRESH_SHARES_IN_PROGRESS = "SHARES_IN_PROGRESS"; + private static final String KEY_WAITING_TO_SEND = "WAITING_TO_SEND"; public static final int DIALOG_SHORT_WAIT = 0; private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 1; @@ -142,6 +142,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa private boolean mSyncInProgress = false; //private boolean mRefreshSharesInProgress = false; + private OCFile mWaitingToSend; + @Override protected void onCreate(Bundle savedInstanceState) { Log_OC.d(TAG, "onCreate() start"); @@ -172,11 +174,13 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW); mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS); //mRefreshSharesInProgress = savedInstanceState.getBoolean(KEY_REFRESH_SHARES_IN_PROGRESS); + mWaitingToSend = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND); } else { mWaitingToPreview = null; mSyncInProgress = false; //mRefreshSharesInProgress = false; + mWaitingToSend = null; } /// USER INTERFACE @@ -667,6 +671,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview); outState.putBoolean(FileDisplayActivity.KEY_SYNC_IN_PROGRESS, mSyncInProgress); //outState.putBoolean(FileDisplayActivity.KEY_REFRESH_SHARES_IN_PROGRESS, mRefreshSharesInProgress); + outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND, mWaitingToSend); Log_OC.d(TAG, "onSaveInstanceState() end"); } @@ -1023,6 +1028,13 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa refreshSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false)); } + if (mWaitingToSend != null) { + mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath()); // Update the file to send + if (mWaitingToSend.isDown()) { + sendDownloadedFile(); + } + } + removeStickyBroadcast(intent); } @@ -1602,4 +1614,34 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } */ + /** + * Requests the download of the received {@link OCFile} , updates the UI + * to monitor the download progress and prepares the activity to send the file + * when the download finishes. + * + * @param file {@link OCFile} to download and preview. + */ + @Override + public void startDownloadForSending(OCFile file) { + mWaitingToSend = file; + requestForDownload(mWaitingToSend); + updateFragmentsVisibility(true); + } + + private void requestForDownload(OCFile file) { + Account account = getAccount(); + if (!mDownloaderBinder.isDownloading(account, file)) { + Intent i = new Intent(this, FileDownloader.class); + i.putExtra(FileDownloader.EXTRA_ACCOUNT, account); + i.putExtra(FileDownloader.EXTRA_FILE, file); + startService(i); + } + } + + private void sendDownloadedFile(){ + dismissLoadingDialog(); + getFileOperationsHelper().sendDownloadedFile(mWaitingToSend, this); + mWaitingToSend = null; + } + } diff --git a/src/com/owncloud/android/ui/dialog/ActivityChooserDialog.java b/src/com/owncloud/android/ui/dialog/ActivityChooserDialog.java index dc15f69a..71d67604 100644 --- a/src/com/owncloud/android/ui/dialog/ActivityChooserDialog.java +++ b/src/com/owncloud/android/ui/dialog/ActivityChooserDialog.java @@ -98,23 +98,46 @@ public class ActivityChooserDialog extends SherlockDialogFragment { Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm)); mAdapter = new ActivityAdapter(getSherlockActivity(), pm, activities); - return new AlertDialog.Builder(getSherlockActivity()) - .setTitle(R.string.activity_chooser_title) - .setAdapter(mAdapter, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // Add the information of the chosen activity to the intent to send - ResolveInfo chosen = mAdapter.getItem(which); - ActivityInfo actInfo = chosen.activityInfo; - ComponentName name=new ComponentName(actInfo.applicationInfo.packageName, actInfo.name); - mIntent.setComponent(name); - - // Create a new share resource - FileOperationsHelper foh = new FileOperationsHelper(); - foh.shareFileWithLinkToApp(mFile, mIntent, (FileActivity)getSherlockActivity()); - } - }) - .create(); + boolean sendAction = mIntent.getBooleanExtra(Intent.ACTION_SEND, false); + + if (sendAction) { + + return new AlertDialog.Builder(getSherlockActivity()) + .setTitle(R.string.activity_chooser_title) + .setAdapter(mAdapter, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Add the information of the chosen activity to the intent to send + ResolveInfo chosen = mAdapter.getItem(which); + ActivityInfo actInfo = chosen.activityInfo; + ComponentName name=new ComponentName(actInfo.applicationInfo.packageName, actInfo.name); + mIntent.setComponent(name); + + // Send the file + ((FileActivity)getSherlockActivity()).startActivity(mIntent); + + } + }) + .create(); + } else { + return new AlertDialog.Builder(getSherlockActivity()) + .setTitle(R.string.activity_chooser_send_file_title) + .setAdapter(mAdapter, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Add the information of the chosen activity to the intent to send + ResolveInfo chosen = mAdapter.getItem(which); + ActivityInfo actInfo = chosen.activityInfo; + ComponentName name=new ComponentName(actInfo.applicationInfo.packageName, actInfo.name); + mIntent.setComponent(name); + + // Create a new share resource + FileOperationsHelper foh = new FileOperationsHelper(); + foh.shareFileWithLinkToApp(mFile, mIntent, (FileActivity)getSherlockActivity()); + } + }) + .create(); + } } diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index fb5b6a92..4d3b0318 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -376,6 +376,19 @@ public class FileDetailFragment extends FileFragment implements synchronizeFile(); return true; } + case R.id.action_send_file: { + FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); + // Obtain the file + if (!getFile().isDown()) { // Download the file + //activity.showLoadingDialog(); + Log_OC.d(TAG, getFile().getRemotePath() + " : File must be downloaded"); + activity.startDownloadForSending(getFile()); + + } else { + activity.getFileOperationsHelper().sendDownloadedFile(getFile(), activity); + } + return true; + } default: return false; } diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index deb981e5..f4fb2f80 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -44,8 +44,6 @@ import com.owncloud.android.utils.Log_OC; import android.accounts.Account; import android.app.Activity; -import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.view.ContextMenu; @@ -222,7 +220,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName toHide.add(R.id.action_cancel_upload); toHide.add(R.id.action_sync_file); toHide.add(R.id.action_see_details); - toHide.add(R.id.action_share_file); + toHide.add(R.id.action_send_file); if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) || mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) ) { toDisable.add(R.id.action_rename_file); @@ -362,11 +360,17 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName return true; } case R.id.action_send_file: { - Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); - // set MimeType - sharingIntent.setType(mTargetFile.getMimetype()); - sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+mTargetFile.getStoragePath())); - startActivity(Intent.createChooser(sharingIntent, "Share via")); + // Obtain the file + if (!mTargetFile.isDown()) { // Download the file + ((FileDisplayActivity) getSherlockActivity()).showLoadingDialog(); + Log_OC.d(TAG, mTargetFile.getRemotePath() + " : File must be downloaded"); + mContainerActivity.startDownloadForSending(mTargetFile); + + } else { + + FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); + activity.getFileOperationsHelper().sendDownloadedFile(mTargetFile, activity); + } return true; } default: @@ -473,6 +477,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName * @param uploading Flag signaling if the file is now uploading. */ public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading); + + void startDownloadForSending(OCFile file); } diff --git a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java index 5a346867..5560c272 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -311,7 +311,8 @@ public class PreviewImageFragment extends FileFragment implements OnRemoteOper return true; } case R.id.action_send_file: { - shareFile(); + FileActivity act = (FileActivity)getSherlockActivity(); + act.getFileOperationsHelper().sendDownloadedFile(getFile(), act); return true; } @@ -320,15 +321,6 @@ public class PreviewImageFragment extends FileFragment implements OnRemoteOper } } - private void shareFile(){ - Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); - // set MimeType - sharingIntent.setType(getFile().getMimetype()); - sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+getFile().getStoragePath())); - startActivity(Intent.createChooser(sharingIntent, "Share via")); - } - - private void seeDetails() { ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile()); diff --git a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 4c52280e..1f98649e 100644 --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -351,6 +351,9 @@ public class PreviewMediaFragment extends FileFragment implements seeDetails(); return true; } + case R.id.action_send_file: { + sendFile(); + } default: return false; @@ -380,6 +383,12 @@ public class PreviewMediaFragment extends FileFragment implements } + private void sendFile() { + stopPreview(false); + FileActivity activity = (FileActivity)((FileFragment.ContainerActivity)getActivity()); + activity.getFileOperationsHelper().sendDownloadedFile(getFile(), activity); + + } private void seeDetails() { stopPreview(false);