diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index e27f84e41d..753dff1d5a 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -193,6 +193,33 @@ public class FileOperationsHelper { } + /** + * Helper method to share a file with a know sharee. Starts a request to do it in {@link OperationsService} + * + * @param file The file to share. + * @param shareeName Name (user name or group name) of the target sharee. + * @param shareType The share type determines the sharee type. + */ + public void shareFileWithSharee(OCFile file, String shareeName, ShareType shareType) { + if (file != null) { + // TODO check capability? + mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext(). + getString(R.string.wait_a_moment)); + + Intent service = new Intent(mFileActivity, OperationsService.class); + service.setAction(OperationsService.ACTION_CREATE_SHARE_WITH_SHAREE); + service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); + service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); + service.putExtra(OperationsService.EXTRA_SHARE_WITH, shareeName); + service.putExtra(OperationsService.EXTRA_SHARE_TYPE, shareType); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service); + + } else { + Log_OC.wtf(TAG, "Trying to share a NULL OCFile"); + } + } + + /** * @return 'True' if the server supports the Share API */ diff --git a/src/com/owncloud/android/operations/CreateShareWithShareeOperation.java b/src/com/owncloud/android/operations/CreateShareWithShareeOperation.java index d7beea0afd..cb81ce46d7 100644 --- a/src/com/owncloud/android/operations/CreateShareWithShareeOperation.java +++ b/src/com/owncloud/android/operations/CreateShareWithShareeOperation.java @@ -29,7 +29,6 @@ package com.owncloud.android.operations; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation; @@ -44,22 +43,24 @@ public class CreateShareWithShareeOperation extends SyncOperation { protected FileDataStorageManager mStorageManager; private String mPath; - private String mTargetName; - private boolean mWithGroup; + private String mShareeName; + private ShareType mShareType; /** - * Constructor - * @param path Full path of the file/folder being shared. Mandatory argument + * Constructor. + * + * @param path Full path of the file/folder being shared. + * @param shareeName User or group name of the target sharee. + * @param shareType Type of share determines type of sharee; {@link ShareType#USER} and {@link ShareType#GROUP} + * are the only valid values for the moment. */ - public CreateShareWithShareeOperation( - String path, - String targetName, - boolean withGroup - ) { - + public CreateShareWithShareeOperation(String path, String shareeName, ShareType shareType) { + if (!ShareType.USER.equals(shareType) && !ShareType.GROUP.equals(shareType)) { + throw new IllegalArgumentException("Illegal share type " + shareType); + } mPath = path; - mTargetName = targetName; - mWithGroup = withGroup; + mShareeName = shareeName; + mShareType = shareType; } @Override @@ -72,14 +73,15 @@ public class CreateShareWithShareeOperation extends SyncOperation { if (!result.isSuccess() || result.getData().size() <= 0) { */ - RemoteOperation operation = new CreateRemoteShareOperation( + CreateRemoteShareOperation operation = new CreateRemoteShareOperation( mPath, - (mWithGroup ? ShareType.GROUP : ShareType.USER), - mTargetName, + mShareType, + mShareeName, false, "", READ_ONLY ); + operation.setGetShareDetails(true); RemoteOperationResult result = operation.execute(client); diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index d14b6e2f4d..eff8e0324a 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -95,7 +95,7 @@ public class OperationsService extends Service { public static final String EXTRA_COOKIE = "COOKIE"; public static final String ACTION_CREATE_SHARE_VIA_LINK = "CREATE_SHARE_VIA_LINK"; - private static final String ACTION_CREATE_SHARE_WITH_SHAREE = "CREATE_SHARE_WITH_SHAREE"; + public static final String ACTION_CREATE_SHARE_WITH_SHAREE = "CREATE_SHARE_WITH_SHAREE"; public static final String ACTION_UNSHARE = "UNSHARE"; public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO"; public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN = "OAUTH2_GET_ACCESS_TOKEN"; @@ -571,7 +571,7 @@ public class OperationsService extends Service { operation = new CreateShareWithShareeOperation( remotePath, shareeName, - ShareType.GROUP.equals(shareType) + shareType ); } diff --git a/src/com/owncloud/android/ui/activity/ShareActivity.java b/src/com/owncloud/android/ui/activity/ShareActivity.java index 03d3b83311..0062ed4caf 100644 --- a/src/com/owncloud/android/ui/activity/ShareActivity.java +++ b/src/com/owncloud/android/ui/activity/ShareActivity.java @@ -35,6 +35,7 @@ import com.owncloud.android.providers.UsersAndGroupsSearchProvider; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.operations.GetSharesForFileOperation; +import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.operations.UnshareOperation; import com.owncloud.android.ui.fragment.SearchFragment; import com.owncloud.android.ui.fragment.ShareFileFragment; @@ -107,7 +108,7 @@ public class ShareActivity extends FileActivity // Verify the action and get the query if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); - doMySearch(query); + Log_OC.w(TAG, "Ignored Intent requesting to query for " + query); } else if (UsersAndGroupsSearchProvider.ACTION_SHARE_WITH.equals(intent.getAction())) { Uri data = intent.getData(); @@ -121,19 +122,17 @@ public class ShareActivity extends FileActivity } } - private void doMySearch(String query) { - // TODO implement , or prevent that search may be sent without choosing from the suggestions list - Toast.makeText(this, "You want to search for [" + query + "]", Toast.LENGTH_SHORT).show(); - } - - private void doShareWith(String username, boolean isGroup) { - // TODO implement + private void doShareWith(String shareeName, boolean isGroup) { if (isGroup) { - Toast.makeText(this, "You want to SHARE with GROUP [" + username + "]", Toast.LENGTH_SHORT).show(); - + Toast.makeText(this, "You want to SHARE with GROUP [" + shareeName + "]", Toast.LENGTH_SHORT).show(); } else { - Toast.makeText(this, "You want to SHARE with USER [" + username + "]", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, "You want to SHARE with USER [" + shareeName + "]", Toast.LENGTH_SHORT).show(); } + getFileOperationsHelper().shareFileWithSharee( + getFile(), + shareeName, + (isGroup ? ShareType.GROUP : ShareType.USER ) + ); } @Override @@ -164,6 +163,7 @@ public class ShareActivity extends FileActivity if (mSearchFragment != null){ getSupportFragmentManager().popBackStackImmediate(); mSearchFragment = null; + mShareFileFragment.refreshUsersOrGroupsList(); } }