/**
+ * 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
*/
public boolean isSharedSupported() {
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;
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
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);
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";
operation = new CreateShareWithShareeOperation(
remotePath,
shareeName,
- ShareType.GROUP.equals(shareType)
+ shareType
);
}
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;
// 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();
}
}
- 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
if (mSearchFragment != null){
getSupportFragmentManager().popBackStackImmediate();
mSearchFragment = null;
+ mShareFileFragment.refreshUsersOrGroupsList();
}
}