mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 06:05:42 +03:00
Share the file with a user or group when selected on the list of suggestions
This commit is contained in:
parent
5e0f46cc2e
commit
9df957d548
4 changed files with 58 additions and 29 deletions
|
@ -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
|
* @return 'True' if the server supports the Share API
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,7 +29,6 @@ package com.owncloud.android.operations;
|
||||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
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.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||||
import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation;
|
import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation;
|
||||||
|
@ -44,22 +43,24 @@ public class CreateShareWithShareeOperation extends SyncOperation {
|
||||||
protected FileDataStorageManager mStorageManager;
|
protected FileDataStorageManager mStorageManager;
|
||||||
|
|
||||||
private String mPath;
|
private String mPath;
|
||||||
private String mTargetName;
|
private String mShareeName;
|
||||||
private boolean mWithGroup;
|
private ShareType mShareType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor.
|
||||||
* @param path Full path of the file/folder being shared. Mandatory argument
|
*
|
||||||
|
* @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(
|
public CreateShareWithShareeOperation(String path, String shareeName, ShareType shareType) {
|
||||||
String path,
|
if (!ShareType.USER.equals(shareType) && !ShareType.GROUP.equals(shareType)) {
|
||||||
String targetName,
|
throw new IllegalArgumentException("Illegal share type " + shareType);
|
||||||
boolean withGroup
|
}
|
||||||
) {
|
|
||||||
|
|
||||||
mPath = path;
|
mPath = path;
|
||||||
mTargetName = targetName;
|
mShareeName = shareeName;
|
||||||
mWithGroup = withGroup;
|
mShareType = shareType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,14 +73,15 @@ public class CreateShareWithShareeOperation extends SyncOperation {
|
||||||
if (!result.isSuccess() || result.getData().size() <= 0) {
|
if (!result.isSuccess() || result.getData().size() <= 0) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RemoteOperation operation = new CreateRemoteShareOperation(
|
CreateRemoteShareOperation operation = new CreateRemoteShareOperation(
|
||||||
mPath,
|
mPath,
|
||||||
(mWithGroup ? ShareType.GROUP : ShareType.USER),
|
mShareType,
|
||||||
mTargetName,
|
mShareeName,
|
||||||
false,
|
false,
|
||||||
"",
|
"",
|
||||||
READ_ONLY
|
READ_ONLY
|
||||||
);
|
);
|
||||||
|
operation.setGetShareDetails(true);
|
||||||
RemoteOperationResult result = operation.execute(client);
|
RemoteOperationResult result = operation.execute(client);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class OperationsService extends Service {
|
||||||
public static final String EXTRA_COOKIE = "COOKIE";
|
public static final String EXTRA_COOKIE = "COOKIE";
|
||||||
|
|
||||||
public static final String ACTION_CREATE_SHARE_VIA_LINK = "CREATE_SHARE_VIA_LINK";
|
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_UNSHARE = "UNSHARE";
|
||||||
public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO";
|
public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO";
|
||||||
public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN = "OAUTH2_GET_ACCESS_TOKEN";
|
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(
|
operation = new CreateShareWithShareeOperation(
|
||||||
remotePath,
|
remotePath,
|
||||||
shareeName,
|
shareeName,
|
||||||
ShareType.GROUP.equals(shareType)
|
shareType
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.operations.GetSharesForFileOperation;
|
import com.owncloud.android.operations.GetSharesForFileOperation;
|
||||||
|
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||||
import com.owncloud.android.operations.UnshareOperation;
|
import com.owncloud.android.operations.UnshareOperation;
|
||||||
import com.owncloud.android.ui.fragment.SearchFragment;
|
import com.owncloud.android.ui.fragment.SearchFragment;
|
||||||
import com.owncloud.android.ui.fragment.ShareFileFragment;
|
import com.owncloud.android.ui.fragment.ShareFileFragment;
|
||||||
|
@ -107,7 +108,7 @@ public class ShareActivity extends FileActivity
|
||||||
// Verify the action and get the query
|
// Verify the action and get the query
|
||||||
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
||||||
String query = intent.getStringExtra(SearchManager.QUERY);
|
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())) {
|
} else if (UsersAndGroupsSearchProvider.ACTION_SHARE_WITH.equals(intent.getAction())) {
|
||||||
Uri data = intent.getData();
|
Uri data = intent.getData();
|
||||||
|
@ -121,19 +122,17 @@ public class ShareActivity extends FileActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doMySearch(String query) {
|
private void doShareWith(String shareeName, boolean isGroup) {
|
||||||
// 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
|
|
||||||
if (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 {
|
} 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
|
@Override
|
||||||
|
@ -164,6 +163,7 @@ public class ShareActivity extends FileActivity
|
||||||
if (mSearchFragment != null){
|
if (mSearchFragment != null){
|
||||||
getSupportFragmentManager().popBackStackImmediate();
|
getSupportFragmentManager().popBackStackImmediate();
|
||||||
mSearchFragment = null;
|
mSearchFragment = null;
|
||||||
|
mShareFileFragment.refreshUsersOrGroupsList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue