From: David A. Velasco Date: Mon, 3 Feb 2014 08:46:26 +0000 (+0100) Subject: Merge branch 'share_link__new_share' into share_link__new_share_menu X-Git-Tag: oc-android-1.5.5~58^2~15^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/59513cd56ddd82118b96df9a5485406338dfb5ea?ds=inline;hp=-c Merge branch 'share_link__new_share' into share_link__new_share_menu --- 59513cd56ddd82118b96df9a5485406338dfb5ea diff --combined AndroidManifest.xml index 8ff6870b,ca11c81b..465dec84 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@@ -54,6 -54,7 +54,6 @@@ > - @@@ -80,12 -81,9 +80,12 @@@ - + - + + + + + diff --combined res/values/strings.xml index 2669565e,7d941c1a..fba0915c --- a/res/values/strings.xml +++ b/res/values/strings.xml @@@ -187,7 -187,6 +187,7 @@@ Wait a moment "Unexpected problem ; please select the file from a different app" No file was selected + Send link to #8230; Login with oAuth2 Connecting to oAuth2 server… @@@ -245,4 -244,7 +245,7 @@@ do nothing you are not online for instant upload Failure Message: Please check your server configuration,maybe your quota is exceeded. + + Sorry, sharing is not enabled on your server. Please contact your administrator. + Unable to share this file or folder. Please, make sure it exists diff --combined src/com/owncloud/android/ui/activity/FileActivity.java index 471214b2,3a9297ec..4f42597f --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@@ -18,23 -18,15 +18,24 @@@ package com.owncloud.android.ui.activity; +import java.util.ArrayList; +import java.util.List; + +import org.apache.http.protocol.HTTP; + import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AccountManagerCallback; import android.accounts.AccountManagerFuture; import android.accounts.OperationCanceledException; import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; +import android.os.Parcelable; import android.webkit.MimeTypeMap; ++import android.widget.Toast; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.owncloud.android.MainApp; @@@ -351,77 -343,5 +352,88 @@@ public abstract class FileActivity exte Log_OC.wtf(TAG, "Trying to open a NULL OCFile"); } } + + /* + public void shareFileWithLink(OCFile file) { + if (file != null) { + + Intent intentToShareLink = new Intent(Intent.ACTION_SEND); + intentToShareLink.putExtra(Intent.EXTRA_TEXT, "https://fake.url.lolo"); + intentToShareLink.setType(HTTP.PLAIN_TEXT_TYPE); + + Intent chooserIntent = Intent.createChooser(intentToShareLink, getString(R.string.action_share_file)); + startActivity(chooserIntent); + + } else { + Log_OC.wtf(TAG, "Trying to open a NULL OCFile"); + } + } + */ + + public void shareFileWithLink(OCFile file) { - if (file != null) { - - //CreateShareOperation createShare = new CreateShareOperation(file.getRemotePath(), ShareType.PUBLIC_LINK, "", false, "", 1); - //createShare.execute(getAccount(), this, this, mHandler, this); - - String link = "https://fake.url.lolo"; - Intent chooserIntent = null; - List targetedShareIntents = new ArrayList(); - List resInfo = getPackageManager().queryIntentActivities(createShareWithLinkIntent(link), PackageManager.MATCH_DEFAULT_ONLY); - String myPackageName = getPackageName(); - if (!resInfo.isEmpty()) { - for (ResolveInfo info : resInfo) { - if (!info.activityInfo.packageName.equalsIgnoreCase(myPackageName)) { - Intent targetedShare = createTargetedShare(link, info.activityInfo.applicationInfo.packageName, info.activityInfo.name); - targetedShareIntents.add(targetedShare); ++ if (isSharedSupported()) { ++ if (file != null) { ++ ++ // Create the Share ++ //CreateShareOperation createShare = new CreateShareOperation(file.getRemotePath(), ShareType.PUBLIC_LINK, "", false, "", 1); ++ //createShare.execute(getStorageManager(), this, this, mHandler, this); ++ ++ // TODO ++ // Get the link --> when the operation is finished ++ ++ String link = "https://fake.url.lolo"; ++ Intent chooserIntent = null; ++ List targetedShareIntents = new ArrayList(); ++ List resInfo = getPackageManager().queryIntentActivities(createShareWithLinkIntent(link), PackageManager.MATCH_DEFAULT_ONLY); ++ String myPackageName = getPackageName(); ++ if (!resInfo.isEmpty()) { ++ for (ResolveInfo info : resInfo) { ++ if (!info.activityInfo.packageName.equalsIgnoreCase(myPackageName)) { ++ Intent targetedShare = createTargetedShare(link, info.activityInfo.applicationInfo.packageName, info.activityInfo.name); ++ targetedShareIntents.add(targetedShare); ++ } + } + } - } - if (targetedShareIntents.size() > 0) { - Intent firstTargeted = targetedShareIntents.remove(0); - chooserIntent = Intent.createChooser(firstTargeted, getString(R.string.action_share_file)); - chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {})); ++ if (targetedShareIntents.size() > 0) { ++ Intent firstTargeted = targetedShareIntents.remove(0); ++ chooserIntent = Intent.createChooser(firstTargeted, getString(R.string.action_share_file)); ++ chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {})); ++ } else { ++ // to show standard message ++ chooserIntent = Intent.createChooser(null, getString(R.string.action_share_file)); ++ } ++ startActivity(chooserIntent); ++ + } else { - // to show standard message - chooserIntent = Intent.createChooser(null, getString(R.string.action_share_file)); ++ Log_OC.wtf(TAG, "Trying to open a NULL OCFile"); + } - startActivity(chooserIntent); + + } else { - Log_OC.wtf(TAG, "Trying to open a NULL OCFile"); ++ // Show a Message ++ Toast t = Toast.makeText(this, getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG); ++ t.show(); + } + } + + private Intent createTargetedShare(String link, String packageName, String className) { + //Intent targetedShare = createShareWithLinkIntent(link); + Intent targetedShare=new Intent(Intent.ACTION_MAIN); + + targetedShare.addCategory(Intent.CATEGORY_LAUNCHER); + targetedShare.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | + Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + Log_OC.e("LOLO", "className: " + className + "\npackageName: " + packageName + "\n"); + targetedShare.setClassName(packageName, className); + return targetedShare; + } + + + private Intent createShareWithLinkIntent(String link) { + Intent intentToShareLink = new Intent(Intent.ACTION_SEND); + intentToShareLink.putExtra(Intent.EXTRA_TEXT, link); + intentToShareLink.setType(HTTP.PLAIN_TEXT_TYPE); + return intentToShareLink; + } + } diff --combined src/com/owncloud/android/ui/activity/FileDisplayActivity.java index f684b790,9ae9dfed..237113d8 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@@ -45,6 -45,7 +45,7 @@@ import android.provider.MediaStore import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; + import android.support.v4.content.LocalBroadcastManager; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@@ -69,17 -70,17 +70,16 @@@ import com.owncloud.android.files.servi import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.operations.CreateFolderOperation; - import com.owncloud.android.operations.GetSharesOperation; - import com.owncloud.android.lib.operations.common.OnRemoteOperationListener; import com.owncloud.android.lib.operations.common.RemoteOperation; import com.owncloud.android.lib.operations.common.RemoteOperationResult; -import com.owncloud.android.lib.operations.common.ShareType; import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode; - + import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFolderOperation; + import com.owncloud.android.services.OperationsService; import com.owncloud.android.syncadapter.FileSyncService; import com.owncloud.android.ui.dialog.EditNameDialog; import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener; @@@ -114,6 -115,7 +114,7 @@@ OCFileListFragment.ContainerActivity, F private SyncBroadcastReceiver mSyncBroadcastReceiver; private UploadFinishReceiver mUploadFinishReceiver; private DownloadFinishReceiver mDownloadFinishReceiver; + private OperationsServiceReceiver mOperationsServiceReceiver; private FileDownloaderBinder mDownloaderBinder = null; private FileUploaderBinder mUploaderBinder = null; private ServiceConnection mDownloadConnection = null, mUploadConnection = null; @@@ -703,6 -705,12 +704,12 @@@ downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage()); mDownloadFinishReceiver = new DownloadFinishReceiver(); registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); + + // Listen for messages from the OperationsService + IntentFilter operationsIntentFilter = new IntentFilter(OperationsService.ACTION_OPERATION_ADDED); + operationsIntentFilter.addAction(OperationsService.ACTION_OPERATION_FINISHED); + mOperationsServiceReceiver = new OperationsServiceReceiver(); + LocalBroadcastManager.getInstance(this).registerReceiver(mOperationsServiceReceiver, operationsIntentFilter); Log_OC.d(TAG, "onResume() end"); } @@@ -724,7 -732,10 +731,10 @@@ unregisterReceiver(mDownloadFinishReceiver); mDownloadFinishReceiver = null; } - + if (mOperationsServiceReceiver != null) { + LocalBroadcastManager.getInstance(this).unregisterReceiver(mOperationsServiceReceiver); + mOperationsServiceReceiver = null; + } Log_OC.d(TAG, "onPause() end"); } @@@ -1031,6 -1042,45 +1041,45 @@@ return (accountName != null && getAccount() != null && accountName.equals(getAccount().name)); } } + + + /** + * Class waiting for broadcast events from the {@link OperationsService}. + * + * Updates the list of files when a get for shares is finished; at this moment the refresh of shares is the only + * operation performed in {@link OperationsService}. + * + * In the future will handle the progress or finalization of all the operations performed in {@link OperationsService}, + * probably all the operations associated to the app model. + */ + private class OperationsServiceReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + if (OperationsService.ACTION_OPERATION_ADDED.equals(intent.getAction())) { + + } else if (OperationsService.ACTION_OPERATION_FINISHED.equals(intent.getAction())) { + mRefreshSharesInProgress = false; + + Account account = intent.getParcelableExtra(OperationsService.EXTRA_ACCOUNT); + RemoteOperationResult getSharesResult = (RemoteOperationResult)intent.getSerializableExtra(OperationsService.EXTRA_RESULT); + if (getAccount() != null && account.name.equals(getAccount().name) + && mStorageManager != null + ) { + refeshListOfFilesFragment(); + } + if ((getSharesResult != null) && + RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(getSharesResult.getCode())) { + mLastSslUntrustedServerResult = getSharesResult; + showDialog(DIALOG_SSL_VALIDATOR); + } + + setSupportProgressBarIndeterminateVisibility(mRefreshSharesInProgress || mSyncInProgress); + } + + } + + } /** @@@ -1295,27 -1345,23 +1344,23 @@@ } else if (operation instanceof CreateFolderOperation) { onCreateFolderOperationFinish((CreateFolderOperation)operation, result); - - } else if (operation instanceof GetSharesOperation) { - onGetSharesOperationFinish((GetSharesOperation) operation, result); + + } else if (operation instanceof CreateShareOperation) { + onCreateShareOperation((CreateShareOperation) operation, result); } + } - /** Updates the data about shared files - * - * @param operation Get Shared Files - * @param result Result of the operation - */ - private void onGetSharesOperationFinish(GetSharesOperation operation, RemoteOperationResult result) { - // Refresh the filelist with the information - refeshListOfFilesFragment(); + private void onCreateShareOperation(CreateShareOperation operation, RemoteOperationResult result) { + if (result.getCode() == ResultCode.FILE_NOT_FOUND) { + // Show a Message + Toast t = Toast.makeText(this, getString(R.string.share_link_file_no_exist), Toast.LENGTH_LONG); + t.show(); + } - mRefreshSharesInProgress = false; + refeshListOfFilesFragment(); - if (!mSyncInProgress) { - setSupportProgressBarIndeterminateVisibility(false); - } } /** @@@ -1529,23 -1575,32 +1574,13 @@@ private void startGetShares() { // Get shared files/folders - RemoteOperation getShares = new GetSharesOperation(mStorageManager); - getShares.execute(getAccount(), this, this, mHandler, this); + Intent intent = new Intent(this, OperationsService.class); + intent.putExtra(OperationsService.EXTRA_ACCOUNT, getAccount()); + startService(intent); mRefreshSharesInProgress = true; setSupportProgressBarIndeterminateVisibility(true); } - // public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) { - // int childCount = viewGroup.getChildCount(); - // for (int i = 0; i < childCount; i++) { - // View view = viewGroup.getChildAt(i); - // view.setEnabled(enabled); - // view.setClickable(!enabled); - // if (view instanceof ViewGroup) { - // enableDisableViewGroup((ViewGroup) view, enabled); - // } - // } - // } - - public void shareFileWithLink(OCFile file) { - - if (isSharedSupported()) { - // Create the Share - CreateShareOperation createShare = new CreateShareOperation(file.getRemotePath(), ShareType.PUBLIC_LINK, "", false, "", 1); - createShare.execute(getStorageManager(), this, this, mHandler, this); - - // TODO - // Get the link --> when the operation is finished - - } else { - // Show a Message - Toast t = Toast.makeText(this, getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG); - t.show(); - - } - } - } diff --combined src/com/owncloud/android/ui/fragment/FileDetailFragment.java index eebbef8d,5925e085..0eacfe44 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@@ -55,9 -55,6 +55,6 @@@ import com.owncloud.android.lib.operati import com.owncloud.android.lib.operations.common.RemoteOperation; import com.owncloud.android.lib.operations.common.RemoteOperationResult; import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode; - import com.owncloud.android.lib.operations.common.ShareType; - import com.owncloud.android.lib.operations.remote.CreateShareRemoteOperation; - import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; @@@ -339,7 -336,7 +336,7 @@@ public class FileDetailFragment extend public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_share_file: { - mContainerActivity.shareFileWithLink(getFile()); + mContainerActivity.shareFileWithLink(getFile()); return true; } case R.id.action_open_file_with: {